def __init__(self): """ Constructor. Create ZeroMQ context. """ self.connections = set() self.context = Context(self.ioThreads)
class ZmqFactory(object): """ I control individual ZeroMQ connections. Factory creates and destroys ZeroMQ context. @cvar reactor: reference to Twisted reactor used by all the connections @cvar ioThreads: number of IO threads ZeroMQ will be using for this context @type ioThreads: C{int} @cvar: lingerPeriod: number of milliseconds to block when closing socket (terminating context), when there are some messages pending to be sent @type lingerPeriod: C{int} @ivar connections: set of instanciated L{ZmqConnection}s @type connections: C{set} @ivar context: ZeroMQ context @type context: L{Context} """ reactor = reactor ioThreads = 1 lingerPeriod = 100 def __init__(self): """ Constructor. Create ZeroMQ context. """ self.connections = set() self.context = Context(self.ioThreads) self.registerForShutdown() def __repr__(self): return "ZmqFactory()" def shutdown(self): """ Shutdown factory. This is shutting down all created connections and terminating ZeroMQ context. """ for connection in self.connections.copy(): connection.shutdown() self.connections = None self.context.term() self.context = None def registerForShutdown(self): """ Register factory to be automatically shut down on reactor shutdown. """ reactor.addSystemEventTrigger('before', 'shutdown', self.shutdown)
class ZmqFactory(object): """ I control individual ZeroMQ connections. Factory creates and destroys ZeroMQ context. @cvar reactor: reference to Twisted reactor used by all the connections @cvar ioThreads: number of IO threads ZeroMQ will be using for this context @type ioThreads: C{int} @cvar: lingerPeriod: number of milliseconds to block when closing socket (terminating context), when there are some messages pending to be sent @type lingerPeriod: C{int} @ivar connections: set of instanciated L{ZmqConnection}s @type connections: C{set} @ivar context: ZeroMQ context @type context: L{Context} """ reactor = reactor ioThreads = 1 lingerPeriod = 100 def __init__(self): """ Constructor. Create ZeroMQ context. """ self.connections = set() self.context = Context(self.ioThreads) def __repr__(self): return "ZmqFactory()" def shutdown(self): """ Shutdown factory. This is shutting down all created connections and terminating ZeroMQ context. """ for connection in self.connections.copy(): connection.shutdown() self.connections = None self.context.term() self.context = None def registerForShutdown(self): """ Register factory to be automatically shut down on reactor shutdown. """ reactor.addSystemEventTrigger('during', 'shutdown', self.shutdown)
def __init__(self, io_threads=1): """ @param io_threads; Passed through to zmq.core.context.Context """ global _context assert _context is None, 'Only one ZmqContext instance is permitted' self._sockets = set() self._zctx = Context(io_threads) _context = self reactor.addSystemEventTrigger('during', 'shutdown', _cleanup)
class _ZmqContext(object): """ This class wraps a ZeroMQ Context object and integrates it into the Twisted reactor framework. @cvar reactor: reference to Twisted reactor used by all the sockets @ivar sockets: set of instanciated L{ZmqSocket}s @type sockets: C{set} @ivar _zctx: ZeroMQ context @type _zctx: L{Context} """ reactor = reactor def __init__(self, io_threads=1): """ @param io_threads; Passed through to zmq.core.context.Context """ global _context assert _context is None, 'Only one ZmqContext instance is permitted' self._sockets = set() self._zctx = Context(io_threads) _context = self reactor.addSystemEventTrigger('during', 'shutdown', _cleanup) def shutdown(self): """ Shutdown the ZeroMQ context and all associated sockets. """ global _context if self._zctx is not None: for socket in self._sockets.copy(): socket.close() self._sockets = None self._zctx.term() self._zctx = None _context = None
def __init__(self): """ Constructor. Create ZeroMQ context. """ self.connections = set() self.context = Context(self.ioThreads) self.registerForShutdown()