def register(self): """ Send a register message to the target. """ self._contChannel.send_json(RegisterMsg(self._label)) logging.debug("Register message sent for %s." % self._label)
def testReceiverShutdownByCall(self): # start a Receiver rec = Receiver(self.addr, self.printer, self.ctrl) rec.startReceiver() # non blocking call workChann, contChann = self._getSenderChannels() # send some messages to the receiver and shut it eventually contChann.send_json(RegisterMsg("Receiver_t")) workChann.send_json(Alert(Type="Alert", Level=20)) contChann.send_json(UnregisterMsg("Receiver_t")) # now messages are sent so shutdown the Receiver by a convenience # call, should block until the Receiver finishes, don't have to wait rec.shutdown()
def testReceiverShutdownByMessage(self): # start a Receiver rec = Receiver(self.addr, self.printer, self.ctrl) rec.startReceiver() # non blocking call workChann, contChann = self._getSenderChannels() # send some messages to the receiver and shut it eventually contChann.send_json(RegisterMsg("Receiver_t")) workChann.send_json(Alert(Type="Alert", Level=10)) contChann.send_json(UnregisterMsg("Receiver_t")) # terminate the Receiver contChann.send_json(ShutdownMsg()) # wait until the Receiver is properly shut # this will not be necessary when shutting down by a call while rec.isReady(): time.sleep(0.1)
def run(self): """ Start a sender and send some alert messages to the Receiver. """ context = zmq.Context() # set up a channel to send work sender = context.socket(zmq.PUSH) sender.connect(self.addr) controller = context.socket(zmq.PUB) controller.connect(self.ctrl) controller.send_json(RegisterMsg("Receiver_t")) for i in range(0, self.nAlerts): a = Alert(Type="Alert", Level=i) sender.send_json(a) controller.send_json(UnregisterMsg("Receiver_t")) controller.send_json(ShutdownMsg())
def testRegisterMsg(self): msg = RegisterMsg("mylabel") self.assertEqual(msg.key, "Register") self.assertEqual(msg[msg.key], "mylabel")