def main(argv): global mb, quiet, node_to_connect_to try: opts, args = getopt.getopt(argv[1:], "?dn:c:qr:") except getopt.error as info: print(info) sys.exit(1) hostName = "localhost" ownNodeName = "py_interface_test" cookie = "cookie" doDebug = 0 for (optchar, optarg) in opts: if optchar == "-?": print("Usage: %s erlnode" % argv[0]) sys.exit(1) elif optchar == "-c": cookie = optarg elif optchar == "-d": doDebug = 1 elif optchar == "-q": quiet = 1 elif optchar == "-n": ownNodeName = optarg elif optchar == "-r": global res_pidname res_pidname = optarg if len(args) >= 4: node_to_connect_to = args[0] mod = args[1] fn = args[2] args = eval(args[3]) else: print("Error: missing args: " + "node_to_connect_to mod fn args") sys.exit(1) if doDebug: erl_common.DebugOnAll() print("Creating node...") n = erl_node.ErlNode(ownNodeName, erl_opts.ErlNodeOpts(cookie=cookie)) n.SetEpmdConnectedOkCb( erl_common.Callback(__EpmdConnectedOk, node_to_connect_to, mod, fn, args, __RpcResult)) print("Publishing node...") n.Publish() print("Creating mbox...") mb = n.CreateMBox(None) m = n.CreateMBox(__TestMBoxCallback) evhand = erl_eventhandler.GetEventHandler() evhand.PushReadEvent(sys.stdin, __FlushStdout) print("-GOING LOOPING-") # Erlang side will pick this text up sys.stdout.flush() evhand.Loop()
def __init__(self, nodeName, opts=erl_opts.ErlNodeOpts()): """Constructor. NODE-NAME = string The name for this node. OPTS = <instance of ErlNodeOpts> Creates an ErlNode. The name of the node is determined by NODE-NAME as described below. A node-name consists of two parts: an alive-name and a host-name, separated by an `@'. The host-name can be short (not including the domain) or long (including the domain). Short and long node-names must not be mixed among the nodes in a system, see the erlang documentation for further details. 1. If the NODE-NAME contains an `@', then NODE-NAME is used unchanged as name for the node. 2. If the NODE-NAME does not contain an `@', then the node's name is constructed as NODE-NAME + "@" + host-name, where host-name is either on short or long form, depending on what is specified in the OPTS. """ shortNodeNames = opts.GetShortNodeNames() self._nodeName = erl_common.AlignNodeName(nodeName, shortNodeNames) self._opts = opts self._creation = 0 self._connections = {} self._epmd = erl_epmd.ErlEpmd(hostName=opts.GetEpmdHost(), portNum=opts.GetEpmdPort()) self._ongoingPings = {} self._isServerPublished = 0 self._pids = {} # mapping pid --> ErlMBox() self._mboxes = {} # mapping ErlMBox --> pid self._registeredNames = {} # mapping name --> pid self._registeredPids = {} # mapping pid --> name self._nodeUpCb = [] # stores (id, callback) self._nodeDownCb = [] # stores (id, callback) self._cbId = 0 self._server = erl_node_conn.ErlNodeServerSocket( self._nodeName, self._opts) self._portNum = self._server.Start(self._NodeUp, self._NodeDown, self._PassThroughMsg) self._epmd.SetOwnPortNum(self._portNum) self._epmd.SetOwnNodeName(self._nodeName) self._epmdConnectedOkCb = erl_common.Callback(self._Sink) self._CreateRex()
def main(argv): global mb, quiet try: opts, args = getopt.getopt(argv[1:], "?dn:c:q") except getopt.error as info: print(info) sys.exit(1) hostName = "localhost" ownNodeName = "py_interface_test" cookie = "cookie" doDebug = 0 for (optchar, optarg) in opts: if optchar == "-?": print("Usage: %s erlnode" % argv[0]) sys.exit(1) elif optchar == "-c": cookie = optarg elif optchar == "-d": doDebug = 1 elif optchar == "-q": quiet = 1 elif optchar == "-n": ownNodeName = optarg if doDebug: erl_common.DebugOnAll() print("Creating node...") n = erl_node.ErlNode(ownNodeName, erl_opts.ErlNodeOpts(cookie=cookie)) print("Publishing node...") n.Publish() print("Creating mbox...") mb = n.CreateMBox(None) m = n.CreateMBox(__TestMBoxCallback) print("Registering mbox as p...") m.RegisterName("p") evhand = erl_eventhandler.GetEventHandler() evhand.PushReadEvent(sys.stdin, __FlushStdout) print("-GOING LOOPING-") # Erlang side will pick this text up sys.stdout.flush() evhand.Loop()
def start_looping(own_node_name, cookie, debug_on_all): if debug_on_all: erl_common.DebugOnAll() LOGGER.debug("Creating node...") node = erl_node.ErlNode(own_node_name, erl_opts.ErlNodeOpts(cookie=cookie)) LOGGER.debug("Publishing node...") node.Publish() LOGGER.debug("Creating mbox...") mbox = node.CreateMBox(__TestMBoxCallback) LOGGER.debug("Registering mbox as p...") mbox.RegisterName("p") event_handler = erl_eventhandler.GetEventHandler() event_thread = Thread(target=event_handler.Loop, args=()) # not necessary to flag as daemon since thread will end when stopping loop event_thread.daemon = True event_thread.start() return node, mbox, event_handler
def init_erlang_node(): node = erl_node.ErlNode(SELF_NODE_NAME, erl_opts.ErlNodeOpts(cookie=ERLANG_COOKIE)) node.Publish() return node
for (optchar, optarg) in opts: if optchar == "-?": print "Usage: %s erlnode" % argv[0] sys.exit(1) elif optchar == "-c": cookie = optarg elif optchar == "-d": doDebug = 1 elif optchar == "-n": ownNodeName = optarg if doDebug: erl_common.DebugOnAll() print "Creating node..." n = erl_node.ErlNode(ownNodeName, erl_opts.ErlNodeOpts(cookie=cookie)) print "Publishing node..." n.Publish() print "Creating mbox..." mb = n.CreateMBox(None) m = n.CreateMBox(__TestMBoxCallback) print "Registering mbox as p..." m.RegisterName("p") print "Looping..." evhand = erl_eventhandler.GetEventHandler() evhand.Loop() try: main(sys.argv)
ownDistrVersion = string.atoi(optarg) elif optchar == "-f": ownFlags = string.atoi(optarg) if len(args) >= 2: hostName = args[0] portNum = string.atoi(args[1]) elif len(args) >= 1: portNum = string.atoi(args[0]) else: sys.exit(1) ownNodeName = erl_common.AlignNodeName(ownNodeName, 1) print "Connecting to %s:%d" print " ownNodeName=\"%s\"" % ownNodeName print " cookie=\"%s\"" % cookie print " ownDistrVersion=%d" % ownDistrVersion print " ownFlags=%d" % ownFlags opts = erl_opts.ErlNodeOpts(cookie=cookie) c = erl_node_conn.ErlNodeOutConnection(ownNodeName, opts) c.InitiateConnection(hostName, portNum, __TestConnectOk, __TestConnectFailed, __TestConnectionBroken, __TestPassThroughMsg) evhandler = erl_eventhandler.GetEventHandler() evhandler.Loop() main(sys.argv)