本文整理汇总了Python中core.event_bus.EventBus.register_handler方法的典型用法代码示例。如果您正苦于以下问题:Python EventBus.register_handler方法的具体用法?Python EventBus.register_handler怎么用?Python EventBus.register_handler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类core.event_bus.EventBus
的用法示例。
在下文中一共展示了EventBus.register_handler方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: register_method
# 需要导入模块: from core.event_bus import EventBus [as 别名]
# 或者: from core.event_bus.EventBus import register_handler [as 别名]
def register_method(message):
address = message.body.get("address", None)
method = message.body.get("method", None)
module = message.body.get("module", None)
if (address != None and method != None and module != None):
EventBus.register_handler(address, "%s.%s"% (module,method))
else:
message.reply("register_method missing address or method or module")
示例2: login_handler
# 需要导入模块: from core.event_bus import EventBus [as 别名]
# 或者: from core.event_bus.EventBus import register_handler [as 别名]
def login_handler(msg):
user = msg.body
id = vertx.config()['user-prefix'] + str(uuid.uuid4())
users.add(user)
EventBus.register_handler(id,
handler=lambda msg: command_handler(user, msg))
EventBus.publish(vertx.config()['users-address'], user)
msg.reply({'id': id, 'users': list(users)})
示例3: start
# 需要导入模块: from core.event_bus import EventBus [as 别名]
# 或者: from core.event_bus.EventBus import register_handler [as 别名]
def start(self):
#self.eventBus.registerHandler(self.address, self);
self.config = VertxLocator.container.getConfig()
self.engine = create_engine(self.db_path, echo=False)
self.Session = sessionmaker(bind=self.engine)
EventBus.register_handler(self.address, handler=self.handle)
self.metadata.create_all(self.engine)
示例4: register
# 需要导入模块: from core.event_bus import EventBus [as 别名]
# 或者: from core.event_bus.EventBus import register_handler [as 别名]
def register(self):
def handler(msg):
if not msg.body.has_key('error'):
headers = { 'Authorization': 'token '+msg.body['access_token'] }
get('https://api.github.com/user', handle_response, headers=headers)
if 'email' in msg.body['scope']: pass
else:
logger.error(msg.body)
EventBus.register_handler('auth.github.login', handler=handler)
示例5: test_deploy
# 需要导入模块: from core.event_bus import EventBus [as 别名]
# 或者: from core.event_bus.EventBus import register_handler [as 别名]
def test_deploy(self):
def handler(message):
if message.body == "started":
tu.test_complete()
EventBus.register_handler("test-handler", False, handler)
conf = {'foo' : 'bar'}
def deploy_handler(err, ok):
tu.azzert(err == None)
vertx.deploy_verticle("core/deploy/child.py", conf, 1, deploy_handler)
示例6: test_deploy
# 需要导入模块: from core.event_bus import EventBus [as 别名]
# 或者: from core.event_bus.EventBus import register_handler [as 别名]
def test_deploy(self):
global handler_id
def handler(message):
if message.body == "started":
tu.test_complete()
handler_id = EventBus.register_handler("test-handler", False, handler)
conf = {'foo' : 'bar'}
vertx.deploy_verticle("core/deploy/child.py", conf)
示例7: get_auth_uid
# 需要导入模块: from core.event_bus import EventBus [as 别名]
# 或者: from core.event_bus.EventBus import register_handler [as 别名]
def get_auth_uid(uid):
if (uid.body == None): message.reply(None)
else:
userID = uid.body
get_user_eb = EventBus.register_handler("get_user_private", handler = get_user)
def user_handler(user):
message.reply(user.body)
EventBus.unregister_handler(get_user_eb)
EventBus.send("get_user_private", {"userID":userID}, user_handler)
示例8: test_undeploy
# 需要导入模块: from core.event_bus import EventBus [as 别名]
# 或者: from core.event_bus.EventBus import register_handler [as 别名]
def test_undeploy(self):
print "in test undeploy"
def handler(message):
return
EventBus.register_handler("test-handler", False, handler)
conf = {'foo' : 'bar'}
def undeploy_handler(err):
tu.azzert(err == None)
tu.test_complete()
def deploy_handler(err, id):
tu.azzert(err == None)
vertx.undeploy_verticle(id, handler=undeploy_handler)
vertx.deploy_verticle("core/deploy/child.py", conf, handler=deploy_handler)
示例9: test_send_empty
# 需要导入模块: from core.event_bus import EventBus [as 别名]
# 或者: from core.event_bus.EventBus import register_handler [as 别名]
def test_send_empty(self):
json = {}
address = "some-address"
def handler(msg):
tu.azzert(msg.body == {})
EventBus.unregister_handler(id)
tu.test_complete()
id = EventBus.register_handler(address, handler=handler)
tu.azzert(id != None)
EventBus.send(address, json)
示例10: test_simple_send
# 需要导入模块: from core.event_bus import EventBus [as 别名]
# 或者: from core.event_bus.EventBus import register_handler [as 别名]
def test_simple_send(self):
json = {'message' : 'hello world!'}
address = "some-address"
def handler(msg):
tu.azzert(msg.body['message'] == json['message'])
EventBus.unregister_handler(id)
tu.test_complete()
id = EventBus.register_handler(address, handler=handler)
tu.azzert(id != None)
EventBus.send(address, json)
示例11: __init__
# 需要导入模块: from core.event_bus import EventBus [as 别名]
# 或者: from core.event_bus.EventBus import register_handler [as 别名]
def __init__(self, cfg, creds):
self.id = cfg['id']
self.cfg = cfg
self.client = self._build_client(cfg, creds)
self.address = "hbdriver:client:" + self.id
self._handlers = []
for addr, h in [(self.address, self.handler),
(self.STATUS_ADDRESS, self.status_handler),
(self.SHUTDOWN_ADDRESS, self.shutdown_handler)]:
hid = EventBus.register_handler(addr, handler=h)
self._handlers.append(hid)
示例12: test_reply_timeout
# 需要导入模块: from core.event_bus import EventBus [as 别名]
# 或者: from core.event_bus.EventBus import register_handler [as 别名]
def test_reply_timeout(self):
json = {'message': 'hello world!'}
address = 'some-address'
reply = {'cheese': 'stilton!'}
def handler(msg):
tu.azzert(msg.body['message'] == json['message'])
id = EventBus.register_handler(address, handler=handler)
tu.azzert(id != None)
def reply_handler(error, msg):
tu.azzert(error != None)
EventBus.unregister_handler(id)
tu.test_complete()
EventBus.send_with_timeout(address, json, 10, reply_handler)
示例13: test_reply
# 需要导入模块: from core.event_bus import EventBus [as 别名]
# 或者: from core.event_bus.EventBus import register_handler [as 别名]
def test_reply(self):
json = {'message' : 'hello world!'}
address = "some-address"
reply = {'cheese' : 'stilton!'}
def handler(msg):
tu.azzert(msg.body['message'] == json['message'])
msg.reply(reply)
id = EventBus.register_handler(address, handler=handler)
tu.azzert(id != None)
def reply_handler(msg):
tu.azzert(msg.body['cheese'] == reply['cheese'])
EventBus.unregister_handler(id)
tu.test_complete()
EventBus.send(address, json, reply_handler)
示例14: echo
# 需要导入模块: from core.event_bus import EventBus [as 别名]
# 或者: from core.event_bus.EventBus import register_handler [as 别名]
def echo(self, msg):
address = "some-address"
class Handler(object):
def handler_func(self, received):
tu.check_thread()
EventBus.unregister_handler(self.id)
received.reply(received.body)
handler = Handler()
handler.id = EventBus.register_handler(address, handler=handler.handler_func)
def reply_handler(reply):
if isinstance(reply.body, dict):
for k,v in reply.body.iteritems():
tu.azzert(msg[k] == v)
else:
tu.azzert(msg == reply.body)
tu.test_complete()
EventBus.send(address, msg, reply_handler)
示例15: test_send_multiple_matching_handlers
# 需要导入模块: from core.event_bus import EventBus [as 别名]
# 或者: from core.event_bus.EventBus import register_handler [as 别名]
def test_send_multiple_matching_handlers(self):
json = {'message' : 'hello world!'}
address = "some-address"
num_handlers = 10
count = [0] # use an array to ensure pass by ref
for i in range(0,num_handlers):
class Handler(object):
def __init__(self, count):
self.count = count
def handler_func(self, msg):
tu.azzert(msg.body['message'] == json['message'])
EventBus.unregister_handler(self.id)
self.count[0] += 1
if self.count[0] == num_handlers:
tu.test_complete()
handler = Handler(count)
handler.id = EventBus.register_handler(address, handler=handler.handler_func)
EventBus.publish(address, json)