Exemple #1
0
    def __init__(self):
        """
        Constructor.

        Create ZeroMQ context.
        """
        self.connections = set()
        self.context = Context(self.ioThreads)
Exemple #2
0
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)
Exemple #3
0
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)
Exemple #4
0
    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)
Exemple #5
0
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
Exemple #6
0
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
Exemple #7
0
    def __init__(self):
        """
        Constructor.

        Create ZeroMQ context.
        """
        self.connections = set()
        self.context = Context(self.ioThreads)
        self.registerForShutdown()
Exemple #8
0
    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)