예제 #1
0
def test_queue():
    r"""Test creation/removal of queue."""
    mq = IPCComm.get_queue()
    key = str(mq.key)
    assert(CommBase.is_registered('IPCComm', key))
    CommBase.unregister_comm('IPCComm', key, dont_close=True)
    assert_raises(KeyError, IPCComm.remove_queue, mq)
    CommBase.register_comm('IPCComm', key, mq)
    IPCComm.remove_queue(mq)
    assert(not CommBase.is_registered('IPCComm', key))
예제 #2
0
 def close_sockets(self):
     r"""Close the sockets."""
     self.debug('Closing sockets')
     if self.cli_socket:
         self.cli_socket.close()
         self.cli_socket = None
     if self.srv_socket:
         self.srv_socket.close()
         self.srv_socket = None
     CommBase.unregister_comm('ZMQComm', 'ROUTER_server_' + self.cli_address)
     CommBase.unregister_comm('ZMQComm', 'DEALER_server_' + self.srv_address)
예제 #3
0
def remove_queue(mq):
    r"""Remove a sysv_ipc.MessageQueue and unregister it.

    Args:
        mq (:class:`sysv_ipc.MessageQueue`) Message queue.
    
    Raises:
        KeyError: If the provided queue is not registered.

    """
    key = str(mq.key)
    if not CommBase.is_registered('IPCComm', key):
        raise KeyError("Queue not registered.")
    CommBase.unregister_comm('IPCComm', key)
예제 #4
0
def test_registry():
    r"""Test registry of comm."""
    comm_class = 'CommBase'
    key = 'key1'
    value = None
    assert (not CommBase.is_registered(comm_class, key))
    assert (not CommBase.unregister_comm(comm_class, key))
    assert_equal(CommBase.get_comm_registry(None), {})
    assert_equal(CommBase.get_comm_registry(comm_class), {})
    CommBase.register_comm(comm_class, key, value)
    assert (key in CommBase.get_comm_registry(comm_class))
    assert (CommBase.is_registered(comm_class, key))
    assert (not CommBase.unregister_comm(comm_class, key, dont_close=True))
    CommBase.register_comm(comm_class, key, value)
    assert (not CommBase.unregister_comm(comm_class, key))
예제 #5
0
 def __init__(self,
              srv_address,
              zmq_context=None,
              retry_timeout=-1,
              nretry=1,
              **kwargs):
     # Get parameters
     srv_param = parse_address(srv_address)
     cli_param = dict()
     for k in ['protocol', 'host', 'port']:
         cli_param[k] = kwargs.pop(k, srv_param[k])
     zmq_context = zmq_context or _global_context
     # Create new address for the frontend
     if cli_param['protocol'] in ['inproc', 'ipc']:
         cli_param['host'] = get_ipc_host()
     cli_address = format_address(cli_param['protocol'], cli_param['host'])
     self.cli_socket = zmq_context.socket(zmq.ROUTER)
     self.cli_address = bind_socket(self.cli_socket,
                                    cli_address,
                                    nretry=nretry,
                                    retry_timeout=retry_timeout)
     self.cli_socket.setsockopt(zmq.LINGER, 0)
     CommBase.register_comm('ZMQComm', 'ROUTER_server_' + self.cli_address,
                            self.cli_socket)
     # Bind backend
     self.srv_socket = zmq_context.socket(zmq.DEALER)
     self.srv_socket.setsockopt(zmq.LINGER, 0)
     try:
         self.srv_address = bind_socket(self.srv_socket,
                                        srv_address,
                                        nretry=nretry,
                                        retry_timeout=retry_timeout)
     except zmq.ZMQError:  # pragma: debug
         self.cli_socket.close()
         self.cli_socket = None
         CommBase.unregister_comm('ZMQComm',
                                  'ROUTER_server_' + self.cli_address)
         raise
     CommBase.register_comm('ZMQComm', 'DEALER_server_' + self.srv_address,
                            self.srv_socket)
     # Set up poller
     # self.poller = zmq.Poller()
     # self.poller.register(frontend, zmq.POLLIN)
     self.reply_socket = None
     # Set name
     super(ZMQProxy, self).__init__(self.srv_address, self.cli_address,
                                    **kwargs)
     self._name = 'ZMQProxy.%s' % srv_address
예제 #6
0
def test_registry():
    r"""Test registry of comm."""
    from yggdrasil.communication import CommBase
    comm_class = 'CommBase'
    key = 'key1'
    value = None
    assert (not CommBase.is_registered(comm_class, key))
    assert (not CommBase.unregister_comm(comm_class, key))
    assert (CommBase.get_comm_registry(None) == {})
    assert (CommBase.get_comm_registry(comm_class) == {})
    CommBase.register_comm(comm_class, key, value)
    assert (key in CommBase.get_comm_registry(comm_class))
    assert (CommBase.is_registered(comm_class, key))
    assert (not CommBase.unregister_comm(comm_class, key, dont_close=True))
    CommBase.register_comm(comm_class, key, value)
    assert (not CommBase.unregister_comm(comm_class, key))
예제 #7
0
파일: RMQComm.py 프로젝트: langmm/yggdrasil
 def terminate(self, *args, **kwargs):
     CommBase.unregister_comm('RMQComm', self.srv_address)
     super(RMQServer, self).terminate(*args, **kwargs)