def __init__(self, identity=None, default_recipient=None): """ Prepares ZMQ socket. You can supply an identity to be able to bootstrap communication by sending messages to well-known participants. Participants sending most messages to a single recipient can set it as default as ommit it's name when calling the send method. Every message contains a timestamp that is checked by recipient. If the time difference is larger than 15 seconds, message is dropped. Make sure your machines use NTP to synchronize their clocks. """ # Create the 0MQ socket. self.socket = zmq.Context.instance().socket(zmq.ROUTER) # Assume either user-specified identity or generate our own. if identity is not None: self.socket.setsockopt(zmq.IDENTITY, identity) else: self.socket.setsockopt(zmq.IDENTITY, uuidgen()) # Remember the default recipient. self.default_recipient = default_recipient # Register ourselves with Twisted reactor loop. reactor.addReader(self)
def __init__(self, sparkle): # Thingies to help us stay in touch with Sparkle. self.sparkle = sparkle self.incarnation = uuidgen() self.sparkle_incarnation = None self.outseq = 1 self.inseq = 0 # Our primary configuration store. Seed with our identity. # Identity will be sent with initial resync. self.model = Model() self.model.load([('host', self.uuid, 'current', {'uuid': self.uuid})]) # Start watching the model for changes. self.watch_model()
def __init__(self, sparkle): """ Stores the Sparkle connection for later use. """ self.sparkle = sparkle self.incarnation = uuidgen()