def event_accept(self, transport): self.log.debug("ACCEPT [%d]", self._state) if not self.server: self.log.debug("ACCEPT event for client side") return assert transport == self.listener sock, client_address = self.listener.accept() if self.transport is not None: self.log.info("ALREADY connected") sock.close() self.log.debug("ACCEPTED: %s [%s]", str(sock.getpeername()), type(sock)) if self.transport is None: self.transport = ConnectedTransport(transport.reaktor, sock, self) self.transport.add_channel() if self._state == Session.IDLE and self._ssl is not None: self.transport.socket.setblocking(1) self._state = Session.SSL_INIT self.transport.ssl_wrap(self._ssl) return self.listener.listen(0) self._state = Session.LOGIN timeout_sec = self.get_conf("login_wait_time", 20) self._tid = add_timer(timeout_sec, self._login_timeout)
def event_start(self, transport): if self.server: return self.log.debug("CREATE CONNECT TIMER") timeout_sec = self.get_conf("connect_timeout", default=30) self._tid = add_timer(int(timeout_sec), transport.timeout)
def save_states(self): for obj, path in self._savelist: try: obj.save(path) except: logging.debug("reaktor: saving failed for %s", str(obj)) self._stid = add_timer(5, self.save_states)
def event_accept(self, transport): self.log.debug("ACCEPT [%d]", self._state) if not self.server: self.log.debug("ACCEPT event for client side") return assert (transport == self.listener) sock, client_address = self.listener.accept() if self.transport is not None: self.log.info("ALREADY connected") sock.close() self.log.debug("ACCEPTED: %s [%s]", str(sock.getpeername()), type(sock)) if self.transport is None: self.transport = ConnectedTransport(transport.reaktor, sock, self) self.transport.add_channel() if self._state == Session.IDLE and self._ssl is not None: self.transport.socket.setblocking(1) self._state = Session.SSL_INIT self.transport.ssl_wrap(self._ssl) return self.listener.listen(0) self._state = Session.LOGIN timeout_sec = self.get_conf('login_wait_time', 20) self._tid = add_timer(timeout_sec, self._login_timeout)
def event_start(self, transport): if self.server: return self.log.debug("CREATE CONNECT TIMER") timeout_sec = self.get_conf('connect_timeout', default=30) self._tid = add_timer(int(timeout_sec), transport.timeout)
def save_states(self): for obj, path in self._savelist: try: obj.save(path) except: logging.debug( "reaktor: saving failed for %s", str(obj)) self._stid = add_timer(5, self.save_states)
def _start_hb_watchdog(self): del_timer(self._tid) self.watchdog_secs = self.get_conf("watchdog_interval", 0) self.hb_interval = self.get_conf("heartbeat_interval", 0) if self.watchdog_secs <= 0 and self.hb_interval > 0: self.watchdog_secs = max(1, self.hb_interval / 2) if self.watchdog_secs > 0: # self.log.debug("arming hb status checker %d sec", self.watchdog_secs) self._tid = add_timer(self.watchdog_secs, self._check_hb_status)
def _start_hb_watchdog(self): del_timer(self._tid) self.watchdog_secs = self.get_conf('watchdog_interval', 0) self.hb_interval = self.get_conf('heartbeat_interval', 0) if self.watchdog_secs <= 0 and self.hb_interval > 0: self.watchdog_secs = max(1, self.hb_interval / 2) if self.watchdog_secs > 0: # self.log.debug("arming hb status checker %d sec", self.watchdog_secs) self._tid = add_timer(self.watchdog_secs, self._check_hb_status)
def _check_hb_status(self): now = time() if now - self.last_send >= self.hb_interval: # self.log.debug("last send %d secs ago", now-self.last_send) self.protocol.send_hb() self.last_send = now if now - self.last_receive >= 3 * self.hb_interval: self.log.debug("last receive %d secs ago", now - self.last_receive) self.event_timeout(self.transport, exc.S_EHEARTBEAT) return self._tid = add_timer(self.watchdog_secs, self._check_hb_status)
def new_message(self): logging.debug("generating new message") message = NewOrderSingle(self.ctx) message.ClOrdID = "Oid-%04d" % random.randrange(1000, 3000) message.Side = random.choice(["1", "0"]) message.OrdType = "1" message.Symbol = "FOO" message.Currency = "EUR" message.SecurityID = "ISIN_000" message.OrderQty = random.randrange(50, 100) message._64 = str(datetime.now()) new_message = message.to_message(FixHeader(self.ctx)) logging.debug("writing: %s", str(new_message)) self.connection.send(new_message) # re-arm generator self.tid = add_timer(30, self.new_message) logging.debug("timer re-armed: %d", self.tid)
def new_message(self): logging.debug("generating new message") message = NewOrderSingle(self.ctx) message.ClOrdID = "Oid-%04d" % random.randrange(1000, 3000) message.Side = random.choice(['1', '0']) message.OrdType = "1" message.Symbol = "FOO" message.Currency = "EUR" message.SecurityID = "ISIN_000" message.OrderQty = random.randrange(50, 100) message._64 = str(datetime.now()) new_message = message.to_message(FixHeader(self.ctx)) logging.debug("writing: %s", str(new_message)) self.connection.send(new_message) # re-arm generator self.tid = add_timer(30, self.new_message) logging.debug("timer re-armed: %d", self.tid)
def run(self, savelist=[], exc_handler=None): self._savelist = savelist if self._savelist: self._stid = add_timer(5, self.save_states) while self.map and not self.stopped(): try: asyncore.loop(0.5, False, self.map, 1) run_timers() except KeyboardInterrupt, ke: for t in self.map.values(): t.session.stop() # break except Exception, exc: #logging.debug("reaktor loop: %s", type(exc)) #logging.debug(traceback.format_exc()) if exc_handler is not None: if not exc_handler(exc): break else: # what to do?? pass
def setup(self, connection): """We are not interested in writing back.""" self.connection = connection self.tid = add_timer(30, self.new_message) logging.debug("timer added %d", self.tid)
def _arm_login_timer(self): del_timer(self._tid) timeout_sec = int(self.get_conf('login_wait_time', 20)) self.log.debug("arming login timer %d", timeout_sec) self._tid = add_timer(timeout_sec, self._login_timeout)
def _arm_reconnect(self): if self.server: return del_timer(self._tid) timeout_sec = self.get_conf("reconnect_interval", 5) self._tid = add_timer(timeout_sec, self._request_reconnect)
def _arm_login_timer(self): del_timer(self._tid) timeout_sec = int(self.get_conf("login_wait_time", 20)) self.log.debug("arming login timer %d", timeout_sec) self._tid = add_timer(timeout_sec, self._login_timeout)
def _arm_reconnect(self): if self.server: return del_timer(self._tid) timeout_sec = self.get_conf('reconnect_interval', 5) self._tid = add_timer(timeout_sec, self._request_reconnect)