Example #1
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)
     self.srv_address = bind_socket(self.srv_socket, srv_address,
                                    nretry=nretry,
                                    retry_timeout=retry_timeout)
     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
Example #2
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))
Example #3
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))
Example #4
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))
Example #5
0
def get_queue(qid=None):
    r"""Create or return a sysv_ipc.MessageQueue and register it.

    Args:
        qid (int, optional): If provided, ID for existing queue that should be
           returned. Defaults to None and a new queue is returned.

    Returns:
        :class:`sysv_ipc.MessageQueue`: Message queue.

    """
    if _ipc_installed:
        kwargs = dict(max_message_size=tools.get_YGG_MSG_MAX())
        if qid is None:
            kwargs['flags'] = sysv_ipc.IPC_CREX
        mq = sysv_ipc.MessageQueue(qid, **kwargs)
        key = str(mq.key)
        CommBase.register_comm('IPCComm', key, mq)
        return mq
    else:  # pragma: windows
        logger.warning("IPC not installed. Queue cannot be returned.")
        return None