Exemplo n.º 1
0
 def remove_ws(self, ws):
     """Remove websocket that has been closed."""
     if ws in self.clients:
         self.clients.pop(ws)
     elif ws in self.gateways.keys():
         # Notify clients that the nodes behind the closed gateway are out.
         for node_uid in self.gateways[ws]:
             self.broadcast(Message.out_node(node_uid))
         self.gateways.pop(ws)
Exemplo n.º 2
0
 def check_dead_nodes(self):
     """Check and remove nodes that are not alive anymore."""
     to_remove = [
         node for node in self.nodes.keys()
         if int(time.time()) > node.check_time + self.max_time
     ]
     for node in to_remove:
         uid = self.nodes[node]['uid']
         self.nodes.pop(node)
         logger.debug("Removing inactive node {}".format(uid))
         self._on_message_cb(Msg.out_node(uid))
Exemplo n.º 3
0
 def check_dead_nodes(self):
     """Check and remove nodes that are not alive anymore."""
     to_remove = [node for node in self.nodes.keys()
                  if int(time.time()) > node.check_time + self.max_time]
     for node in to_remove:
         asyncio.get_event_loop().create_task(
             self._disconnect_from_node(node))
         for resource in node.resources:
             pass
         uid = self.nodes[node]['uid']
         self.nodes.pop(node)
         logger.info("Removing inactive node {}".format(uid))
         logger.debug("Available nodes {}".format(self.nodes))
         self._on_message_cb(Msg.out_node(uid))
Exemplo n.º 4
0
 def remove_node(self, node):
     """Remove the given node from known nodes and notify the broker."""
     self.nodes.pop(node.uid)
     logger.debug("Remaining nodes {}".format(self.nodes))
     self.send_to_broker(Message.out_node(node.uid))
Exemplo n.º 5
0
def test_out_node():
    serialized = Message.out_node('1234')

    assert serialized == Message.serialize({'type': 'out', 'uid': '1234'})
Exemplo n.º 6
0
 def remove_ws(self, ws):
     """Remove websocket that has been closed."""
     if ws in self.nodes:
         self.send_to_broker(Message.out_node(self.nodes[ws]['uid']))
         self.nodes.pop(ws)