Example #1
0
def __TestMBoxCallback(msg, *k, **kw):
    global mb
    print "Incoming msg=%s (k=%s, kw=%s)" % ( ` msg `, ` k `, ` kw `)
    if type(msg) == types.TupleType:
        if len(msg) == 2:
            if erl_term.IsErlPid(msg[0]):
                dest = msg[0]
                print "Sending it back to %s" % (dest, )
                mb.Send(dest, msg)
Example #2
0
def __TestMBoxCallback(msg, *k, **kw):
    global mb, quiet
    if not quiet:
        txt = "Incoming msg=%s (k=%s, kw=%s)" % (repr(msg), repr(k), repr(kw))
        print(txt.encode("ascii", errors="backslashreplace"))
    if type(msg) == tuple:
        if len(msg) == 2:
            if erl_term.IsErlPid(msg[0]):
                dest = msg[0]
                if not quiet:
                    print("Sending it back to %s" % (dest, ))
                reply = msg[1]
                mb.Send(dest, (mb.Self(), reply))
def __TestMBoxCallback(msg, *k, **kw):
    global mb, quiet
    if not quiet:
        print "Incoming msg=%s (k=%s, kw=%s)" % ( ` msg `, ` k `, ` kw `)
    data = msg[0].contents
    node = msg[1].atomText
    socket_id = msg[2].contents

    process_protocol(data, node, socket_id)

    if type(msg) == types.TupleType:
        if len(msg) == 2:
            if erl_term.IsErlPid(msg[0]):
                dest = msg[0]
                if not quiet:
                    print "Sending it back to %s" % (dest, )
                mb.Send(dest, msg)
Example #4
0
    def SendMsgFromMBox(self, sourceMBox, dest, msg):
        """This routine is intended to be called from an ErlMBox instance
        SOURCE-MBOX = <instance of ErlMBox>
        DEST        = <instance of ErlPid> |
                      string |
                      <instance of ErlAtom> |
                      tuple(DEST-REGNAME, DEST-NODE)
                      DEST-REGNAME = DEST-NODE = string | <instance of ErlAtom>
        MSG         = <term>
        Returns: void
        THrows:  <<to-be-documented>>
        """
        ## Possible dest types:
        ## - A tuple: (registered_name, node_name)
        ## - An atom: registered_name
        ## - A pid:   <erlpid ...>  (note: the pid contains the pid's node)

        sourcePid = self._mboxes[sourceMBox]

        ## First check for strings in the dest argument.
        ## Convert any strings to to atoms.
        if type(dest) == str or type(dest) == bytes:
            dest = erl_term.ErlAtom(dest)
        elif type(dest) == tuple:
            destPidName = dest[0]
            destNode = dest[1]
            if type(destPidName) == str or type(destPidName) == bytes:
                destPidName = erl_term.ErlAtom(destPidName)
            if type(destNode) == str or type(destNode) == bytes:
                destNode = erl_term.ErlAtom(destNode)
            dest = (destPidName, destNode)

        ## Then split the dest into:
        ##    destPid/destPidName   and   destNode
        ## depending on its type.
        if type(dest) == tuple:
            destPid = dest[0]
            destNode = dest[1]
        elif erl_term.IsErlAtom(dest):
            destNode = self
            name = dest.atomText
            if name not in self._registeredNames:
                return
            destPid = self._registeredNames[name]
        elif erl_term.IsErlPid(dest):
            destPid = dest
            destNode = dest.node
        else:
            return

        ## Now do the sending...
        if destNode == self:
            if destPid not in self._registeredPids:
                return
            mbox = self._registredPids[destPid]
            mbox.Msg(msg)
        else:  # dest node is remote
            # First make sure we are online
            # FIXME: Will this really work???
            #        Publish might register callbacks, but
            #        this code continues after the Publish...
            self.Publish()
            destNodeName = destNode.atomText
            if destNodeName not in self._connections:
                # We don't have a connection to the destination
                # We must open a connection.
                # This is done by pinging with the ping-callback
                # being a function that sends the message.

                cb = erl_common.Callback(self._SendMsgToRemoteNode, sourcePid,
                                         destNode, destPid, msg)
                destNodeName = destNode.atomText
                self.Ping(destNodeName, cb)
            else:
                ## We have contact with the remote node. Send at once!
                self._SendMsgToRemoteNode("pong", sourcePid, destNode, destPid,
                                          msg)