def __init__(self, node): """ Create connection handler object. :type node: Pyrlang.Node :param node: Erlang node reference """ self.node_ = node """ Reference to the running Erlang node. (XXX forms a ref cycle) """ self.packet_len_size_ = 2 """ Packet size header is variable, 2 bytes before handshake is finished and 4 bytes afterwards. """ self.socket_ = None self.addr_ = None # refer to util.make_handler_in which reads this self.inbox_ = mailbox.Mailbox() """ Inbox is used to ask the connection to do something. """ self.peer_distr_version_ = (None, None) """ Protocol version range supported by the remote peer. Erlang/OTP versions 19-20 supports protocol version 7, older Erlangs down to R6B support version 5. """ self.peer_flags_ = 0 self.peer_name_ = None self.my_challenge_ = None self.state_ = None
def __init__(self, node) -> None: """ Create a process and register itself. Pid is generated by the node object. :param node: """ Greenlet.__init__(self) self.node_ = node """ Convenience field to see the Node. """ self.inbox_ = mailbox.Mailbox() """ Message queue (gevent.Queue). Messages are detected by the ``_run`` loop and handled one by one in ``handle_one_inbox_message()``. """ self.pid_ = node.register_new_process(self) """ Process identifier for this object. Remember that when creating a process, it registers itself in the node, and this creates a reference. References prevent an object from being garbage collected. To destroy a process, get rid of this extra reference by calling ``exit()`` and telling it the cause of its death. """ self.is_exiting_ = False self.monitors_ = set() # type: Set[Pid] """ Who monitors us. Either local or remote processes. """ self.monitor_targets_ = set() # type: Set[Pid] """ Who we monitor. """ self.start() # greenlet has to be scheduled for run
def __init__(self, name: str, cookie: str) -> None: Greenlet.__init__(self) if Node.singleton is not None: raise NodeException("Singleton Node was already created") Node.singleton = self self.inbox_ = mailbox.Mailbox() """ Message queue based on ``gevent.Queue``. It is periodically checked in the ``_run`` method and the receive handler is called. """ self.pid_counter_ = 0 """ An internal counter used to generate unique process ids. """ self.processes_ = {} """ Process dictionary which stores all the existing ``Process`` objects adressable by a pid. .. note:: This creates a python reference to an object preventing its automatic garbage collection. In the end of its lifetime an object must be explicitly removed from this dictionary using ``Process.exit`` method on the process. """ self.reg_names_ = {} """ Registered objects dictionary, which maps atoms to pids. """ self.is_exiting_ = False self.node_opts_ = NodeOpts(cookie=cookie) """ An option object with feature support flags packed into an integer. """ self.name_ = Atom(name) """ Node name as seen on the network. Use full node names here: ``name@hostname`` """ self.dist_nodes_ = {} self.dist_ = ErlangDistribution(node=self, name=name) # This is important before we can begin spawning processes # to get the correct node creation self.dist_.connect(self) # Spawn and register (automatically) the process 'rex' for remote # execution, which takes 'rpc:call's from Erlang from Pyrlang.rex import Rex self.rex_ = Rex(self) self.rex_.start() # Spawn and register (automatically) the 'net_kernel' process which # handles special ping messages from Pyrlang.net_kernel import NetKernel self.net_kernel_ = NetKernel(self) self.net_kernel_.start()