def __init__(self): """ Initialisation of the generator and the ControlDispatcher() """ self.qid_generator = generator.uid_generator() Connector.__init__(self) self.dispatcher = ControlEventDispatcher() self.dispatcher.control = weakref.ref(self)
class ControlConnector(Connector): """ This Class is the implemenetation of the control connector. It implement all standard connector method plus it is designed to send event, answer and query """ name = "control" def __init__(self): """ Initialisation of the generator and the ControlDispatcher() """ self.qid_generator = generator.uid_generator() Connector.__init__(self) self.dispatcher = ControlEventDispatcher() self.dispatcher.control = weakref.ref(self) def query(self, msg, peerid): """ This method send a control query to the given peerid ( only if the connection is already active) and encapsulate the msg. This method returns a defered which fires when the answer is received. """ if logger.isEnabledFor(logging.DEBUG): logger.debug("Sending Query ... to %s" % str(peerid)) qid = self.qid_generator.next() answer = self.dispatcher.addWaitingAnswer(qid, peerid) self.send(CONTROL_QUERY % (qid, msg), peerid=peerid) return answer def answer(self, msg, qid, peerid): """ This method is called to answer a particular query. It encapsulate the msg in the right header for the dispatch. """ if logger.isEnabledFor(logging.DEBUG): logger.debug("Sending Answer ... to %s" % str(peerid)) self.send(CONTROL_ANSWER % (qid, msg), peerid=peerid) def event(self, msg, peerid): """ This method is called to send an event to a particular peerid. It encapsulate the msg in the right header for the dispatch. """ if logger.isEnabledFor(logging.DEBUG): logger.debug("Sending Event ... to %s" % str(peerid)) self.send(CONTROL_EVENT % (msg), peerid=peerid)
class ControlConnector(Connector): """ This Class is the implemenetation of the control connector. It implement all standard connector method plus it is designed to send event, answer and query """ name = "control" def __init__(self): """ Initialisation of the generator and the ControlDispatcher() """ self.qid_generator = generator.uid_generator() Connector.__init__(self) self.dispatcher = ControlEventDispatcher() self.dispatcher.control = weakref.ref(self) def query(self, msg, peerid): """ This method send a control query to the given peerid ( only if the connection is already active) and encapsulate the msg. This method returns a defered which fires when the answer is received. """ if logger.isEnabledFor(logging.DEBUG): logger.debug("Sending Query ... to %s" % str(peerid)) qid = self.qid_generator.next() answer = self.dispatcher.addWaitingAnswer(qid, peerid) self.send(CONTROL_QUERY % (qid, msg), peerid = peerid) return answer def answer(self, msg, qid, peerid): """ This method is called to answer a particular query. It encapsulate the msg in the right header for the dispatch. """ if logger.isEnabledFor(logging.DEBUG): logger.debug("Sending Answer ... to %s" % str(peerid)) self.send(CONTROL_ANSWER % (qid, msg), peerid = peerid) def event(self, msg, peerid): """ This method is called to send an event to a particular peerid. It encapsulate the msg in the right header for the dispatch. """ if logger.isEnabledFor(logging.DEBUG): logger.debug("Sending Event ... to %s" % str(peerid)) self.send(CONTROL_EVENT % (msg), peerid = peerid)