def _port_connected_remote(self, status, actor_id, port_id, peer_port_id, peer_node_id): _log.debug("Port remote connected %s %s %s %s %s" % (actor_id, port_id, peer_port_id, peer_node_id, str(status))) if not status: # Failed request for connecting, likely the actor having the peer port has migrated. # Find it and try again. peer_port_meta = PortMeta(self, port_id=peer_port_id) try: peer_port_meta.retrieve(callback=CalvinCB(self._found_peer_node, actor_id=actor_id, port_id=port_id, peer_port_id=peer_port_id)) except calvinresponse.CalvinResponseException as e: _log.exception("Failed retrieving peer port meta info %s" % str(e)) return
def connect(self, callback=None, actor_id=None, port_name=None, port_properties=None, port_id=None, peer_node_id=None, peer_actor_id=None, peer_port_name=None, peer_port_properties=None, peer_port_id=None): """ Obtain any missing information to enable making a connection and make actual connect callback: an optional callback that gets called with status when finished local port identified by: actor_id, port_name and port_dir='in'/'out' or port_id peer_node_id: an optional node id the peer port is locate on, will use storage to find it if not supplied peer port (remote or local) identified by: peer_actor_id, peer_port_name and peer_port_dir='in'/'out' or peer_port_id """ local_port_meta = PortMeta(self, actor_id=actor_id, port_id=port_id, port_name=port_name, properties=port_properties, node_id=self.node.id) peer_port_meta = PortMeta(self, actor_id=peer_actor_id, port_id=peer_port_id, port_name=peer_port_name, properties=peer_port_properties, node_id=peer_node_id) _log.analyze(self.node.id, "+", {'local': local_port_meta, 'peer': peer_port_meta}, peer_node_id=peer_node_id, tb=True) try: port = local_port_meta.port except response.CalvinResponseException as e: if callback: callback(status=e.response, actor_id=actor_id, port_name=port_name, port_id=port_id, peer_node_id=peer_node_id, peer_actor_id=peer_actor_id, peer_port_name=peer_port_name, peer_port_id=peer_port_id) return else: raise e.response # Retrieve node id etc, raise exception if not possible, continue in _connect otherwise try: peer_port_meta.retrieve(callback=CalvinCB(self._connect, local_port=port, callback=callback)) except response.CalvinResponseException as e: if callback: callback(status=e.response, actor_id=actor_id, port_name=port_name, port_id=port_id, peer_node_id=peer_node_id, peer_actor_id=peer_actor_id, peer_port_name=peer_port_name, peer_port_id=peer_port_id) return else: raise e.response