def handler_func(self, msg): tu.azzert(msg.address == address) 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()
def handler(msg): if self.received: tu.azzert(False, "handler already called") tu.azzert(msg.body['message'] == json['message']) EventBus.unregister_handler(id) self.received = True def timer_complete(id): tu.test_complete() # End test on a timer to give time for other messages to arrive vertx.set_timer(100, timer_complete)
class HBCAgent(object): STATUS_ADDRESS = "hbdriver:stati" SHUTDOWN_ADDRESS = "hbdriver:shutdown" 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) @property def name(self): if self.cfg.get('name'): return "%s-%s" % (self.cfg['name'], self.id) return self.id def start(self): logger.info("Connecting hosebird for %s..." % self.name) self.client.connect() def _build_client(self, cfg, creds): logger.info("Configuring hosebird for %s" % self.id) queue = EventBusQueue(cfg['publishChannel']) endpoint = StatusesFilterEndpoint() if cfg.get('track'): endpoint.trackTerms(cfg['track']) if cfg.get('follow'): endpoint.followings(cfg['follow']) if cfg.get('locations'): locations = [Location(Location.Coordinate(w, s), Location.Coordinate(e, n)) for s, w, n, e in cfg['locations']] endpoint.locations(locations) auth = OAuth1(*creds) client = ClientBuilder()\ .hosts(Constants.STREAM_HOST)\ .endpoint(endpoint)\ .authentication(auth)\ .processor(StringDelimitedProcessor(queue))\ .build() return client def _status(self): t = self.client.getStatsTracker() stats = {} for a, v in [('getNum200s', '200s'), ('getNum400s', '400s'), ('getNumDisconnects', 'disconnects'), ('getNumConnects', 'connects'), ('getNumConnectionFailures', 'connfailures'), ('getNumClientEventsDropped', 'eventsdropped')]: stats[v] = getattr(t, a)() if not self.client.isDone(): return dict(status=200, address=self.address, stats=stats) else: return dict(status=500, address=self.address, status=stats) def status_handler(self, msg): EventBus.publish(msg.body['replyTo'], self._status()) def shutdown_handler(self, msg): EventBus.publish(msg.body['replyTo'], self._shutdown()) def _shutdown(self): logger.warn("Shutting down %s..." % self.address) EventBus.send(CredentialManager.ADDRESS, dict(command="release", id=self.id)) status = 200 msg = None try: self.client.stop(100) except Exception, e: logger.error("Failed to stop: %s" % self.address, e) status = 500 msg = str(e) self.client = None for hid in self._handlers: EventBus.unregister_handler(hid) logger.info("Shutdown %s: status=%s" % (self.address, status)) return dict(status=status, address=self.address, msg=msg)
def wrapped_closed_handler(): EventBus.unregister_handler(self.write_handler_id) if hasattr(self, "_closed_handler"): self._closed_handler()
def reply_handler(error, msg): tu.azzert(error != None) EventBus.unregister_handler(id) tu.test_complete()
def handler(msg): tu.azzert(msg.body == {}) EventBus.unregister_handler(id) tu.test_complete()
def reply_handler3(reply2): tu.azzert("reply-of-reply-of-reply" == reply2.body) EventBus.unregister_handler(id) tu.test_complete()
def handler_func(self, received): tu.check_thread() EventBus.unregister_handler(self.id) tu.azzert(received.address == address) received.reply(received.body)
def handler(msg): tu.azzert(msg.body['message'] == json['message']) EventBus.unregister_handler(id) tu.test_complete()
def handler_func(self, received): tu.check_thread() EventBus.unregister_handler(self.id) received.reply(received.body)
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()
def vertx_stop(): EventBus.unregister_handler(handler_id) tu.unregister_all() tu.app_stopped()
def reply_handler(error, msg): tu.azzert(error != None) tu.azzert(isinstance(error, ReplyError)) tu.azzert(error.type == ReplyError.TIMEOUT) EventBus.unregister_handler(id) tu.test_complete()
def handler_func(self, received): #print "received: %s type %s"% type(received.body, type(received.body)) tu.check_context() EventBus.unregister_handler(self.id) received.reply(received.body)
def user_handler(user): message.reply(user.body) EventBus.unregister_handler(get_user_eb)
def close(self): """Close the socket""" EventBus.unregister_handler(self.handler_id) self.java_obj.close()
def reply_handler(error, msg): tu.azzert(error == None) tu.azzert(msg.body['cheese'] == reply['cheese']) EventBus.unregister_handler(id) tu.test_complete()
def reply_handler(msg): tu.azzert(msg.body == {}) EventBus.unregister_handler(id) tu.test_complete()
def closing(msg): EventBus.unregister_handler(resultHandleId)