Ejemplo n.º 1
0
    def __init__(self,
                 in_addr,
                 out_addr,
                 mon_addr=None,
                 in_type=zmq.SUB,
                 out_type=zmq.DEALER,
                 mon_type=zmq.PUB,
                 heart_id=None):
        if mon_addr is None:
            self.device = ThreadDevice(zmq.FORWARDER, in_type, out_type)
        else:
            self.device = ThreadMonitoredQueue(in_type,
                                               out_type,
                                               mon_type,
                                               in_prefix=b"",
                                               out_prefix=b"")
        # do not allow the device to share global Context.instance,
        # which is the default behavior in pyzmq > 2.1.10
        self.device.context_factory = zmq.Context

        self.device.daemon = True
        self.device.connect_in(in_addr)
        self.device.connect_out(out_addr)
        if mon_addr is not None:
            self.device.connect_mon(mon_addr)
        if in_type == zmq.SUB:
            self.device.setsockopt_in(zmq.SUBSCRIBE, b"")
        if heart_id is None:
            heart_id = uuid.uuid4().bytes
        self.device.setsockopt_out(zmq.IDENTITY, heart_id)
        self.id = heart_id
Ejemplo n.º 2
0
 def __init__(self, in_addr, out_addr, mon_addr=None, in_type=zmq.SUB, out_type=zmq.DEALER, mon_type=zmq.PUB, heart_id=None):
     if mon_addr is None:
         self.device = ThreadDevice(zmq.FORWARDER, in_type, out_type)
     else:
         self.device = ThreadMonitoredQueue(in_type, out_type, mon_type, in_prefix=b"", out_prefix=b"")
     # do not allow the device to share global Context.instance,
     # which is the default behavior in pyzmq > 2.1.10
     self.device.context_factory = zmq.Context
     
     self.device.daemon=True
     self.device.connect_in(in_addr)
     self.device.connect_out(out_addr)
     if mon_addr is not None:
         self.device.connect_mon(mon_addr)
     if in_type == zmq.SUB:
         self.device.setsockopt_in(zmq.SUBSCRIBE, b"")
     if heart_id is None:
         heart_id = uuid.uuid4().bytes
     self.device.setsockopt_out(zmq.IDENTITY, heart_id)
     self.id = heart_id
Ejemplo n.º 3
0
class Heart:
    """A basic heart object for responding to a HeartMonitor.
    This is a simple wrapper with defaults for the most common
    Device model for responding to heartbeats.

    Builds a threadsafe zmq.FORWARDER Device, defaulting to using
    SUB/DEALER for in/out.

    You can specify the DEALER's IDENTITY via the optional heart_id argument."""

    device = None
    id = None

    def __init__(
        self,
        in_addr,
        out_addr,
        mon_addr=None,
        in_type=zmq.SUB,
        out_type=zmq.DEALER,
        mon_type=zmq.PUB,
        heart_id=None,
        curve_serverkey=None,
        curve_secretkey=None,
        curve_publickey=None,
    ):
        if mon_addr is None:
            self.device = ThreadDevice(zmq.FORWARDER, in_type, out_type)
        else:
            self.device = ThreadMonitoredQueue(
                in_type, out_type, mon_type, in_prefix=b"", out_prefix=b""
            )
        # do not allow the device to share global Context.instance,
        # which is the default behavior in pyzmq > 2.1.10
        self.device.context_factory = zmq.Context

        self.device.daemon = True
        self.device.connect_in(in_addr)
        self.device.connect_out(out_addr)
        if curve_serverkey:
            self.device.setsockopt_in(zmq.CURVE_SERVERKEY, curve_serverkey)
            self.device.setsockopt_in(zmq.CURVE_PUBLICKEY, curve_publickey)
            self.device.setsockopt_in(zmq.CURVE_SECRETKEY, curve_secretkey)

            self.device.setsockopt_out(zmq.CURVE_SERVERKEY, curve_serverkey)
            self.device.setsockopt_out(zmq.CURVE_PUBLICKEY, curve_publickey)
            self.device.setsockopt_out(zmq.CURVE_SECRETKEY, curve_secretkey)
            if mon_addr is not None:
                self.device.setsockopt_mon(zmq.CURVE_SERVERKEY, curve_publickey)
                self.device.setsockopt_mon(zmq.CURVE_PUBLICKEY, curve_publickey)
                self.device.setsockopt_mon(zmq.CURVE_SECRETKEY, curve_secretkey)

        if mon_addr is not None:
            self.device.connect_mon(mon_addr)
        if in_type == zmq.SUB:
            self.device.setsockopt_in(zmq.SUBSCRIBE, b"")
        if heart_id is None:
            heart_id = uuid.uuid4().bytes
        self.device.setsockopt_out(zmq.IDENTITY, heart_id)
        self.id = heart_id

    def start(self):
        return self.device.start()
Ejemplo n.º 4
0
class Heart(object):
    """A basic heart object for responding to a HeartMonitor.
    This is a simple wrapper with defaults for the most common
    Device model for responding to heartbeats.

    It simply builds a threadsafe zmq.FORWARDER Device, defaulting to using
    SUB/DEALER for in/out.

    You can specify the DEALER's IDENTITY via the optional heart_id argument."""
    device=None
    id=None
    def __init__(self, in_addr, out_addr, mon_addr=None, in_type=zmq.SUB, out_type=zmq.DEALER, mon_type=zmq.PUB, heart_id=None):
        if mon_addr is None:
            self.device = ThreadDevice(zmq.FORWARDER, in_type, out_type)
        else:
            self.device = ThreadMonitoredQueue(in_type, out_type, mon_type, in_prefix=b"", out_prefix=b"")
        # do not allow the device to share global Context.instance,
        # which is the default behavior in pyzmq > 2.1.10
        self.device.context_factory = zmq.Context
        
        self.device.daemon=True
        self.device.connect_in(in_addr)
        self.device.connect_out(out_addr)
        if mon_addr is not None:
            self.device.connect_mon(mon_addr)
        if in_type == zmq.SUB:
            self.device.setsockopt_in(zmq.SUBSCRIBE, b"")
        if heart_id is None:
            heart_id = uuid.uuid4().bytes
        self.device.setsockopt_out(zmq.IDENTITY, heart_id)
        self.id = heart_id

    def start(self):
        return self.device.start()