def _run(self): try: args = self.srcname, self.select, self.reject # TODO Review this queue size # TODO Review reasoning behind using OrbreapThr vs. normal ORB API # I think it had something to do with orb.reap() blocking forever # on comms failures; maybe we could create our own orbreapthr # implementation? with OrbreapThr(*args, timeout=1, queuesize=10000) as orbreapthr: log.info("Connected to ORB %s %s %s" % (self.srcname, self.select, self.reject, self.after)) threadpool = ThreadPool(maxsize=1) try: while True: try: success, value = threadpool.spawn( wrap_errors, (Exception,), orbreapthr.get, [], {}).get() timestamp = ntp.now() if not success: raise value except (Timeout, NoData), e: log.debug("orbreapthr.get exception %r" % type(e)) pass else: if value is None: raise Exception('Nothing to publish') self._publish(value, timestamp) finally: # This blocks until all threads in the pool return. That's # critical; if the orbreapthr dies before the get thread, # segfaults ensue. threadpool.kill() except Exception, e: log.error("OrbPktSrc terminating due to exception", exc_info=True) raise
def heartbeat_sender(self, sock, addr, socklock, parent): try: with closing(sock): while True: self.heartbeat_event.wait() pkt = makepacket(PacketType.PORT_AGENT_HEARTBEAT, ntp.now(), "") with socklock: sock.sendall(pkt) sleep() except socket.error, e: log.debug("heartbeat socket err: %s" % e)
def ping(self, val, sock): msg = "pong. version: " + __version__ sock.sendall(makepacket(PacketType.PORT_AGENT_STATUS, ntp.now(), msg))
def get_state(self, val, sock): statestr = self.states[self.state] sock.sendall(makepacket(PacketType.PORT_AGENT_STATUS, ntp.now(), statestr))