예제 #1
0
class TCPDispatcher(Pyactive):
   
    def __init__(self, host, addr):
        Pyactive.__init__(self)  
        ip, port = addr
        self.name = ip + ':' + str(port)
        self.conn = Server(ip, port, self)
        self.addr = addr
        self.host = host
        
        self.callback = {}

    #@async
    def _stop(self):
        self.conn.close()
        super(TCPDispatcher, self)._stop()
     
            
    def receive(self, msg):
        if msg[MODE] == SYNC and msg[TYPE] == CALL:
            self.callback[msg[RPC_ID]] = msg[SRC]
        msg[SRC] = self.addr
        
        self.conn.send(msg)
   
    def is_local(self, name):
        return name == self.name
    
    def on_message(self, msg):
        try:
            if msg[TYPE] == RESULT:
                if msg.has_key(MULTI):
                    target = self.callback[msg[RPC_ID]]
                    target.send(msg)
                if pending.has_key(msg[RPC_ID]):
                    del pending[msg[RPC_ID]]
                    target = self.callback[msg[RPC_ID]]
                    del self.callback[msg[RPC_ID]]
                    target.send(msg)
            else:
                if msg[MODE] == SYNC:
                    msg[TARGET] = msg[SRC]
                    msg[SRC] = self.channel
                    pending[msg[RPC_ID]] = 1
                aref = msg[TO]
                aurl = urlparse(aref)
                self.host.objects[aurl.path].channel.send(msg)
        except Exception, e:
            print e, 'TCP ERROR2'
예제 #2
0
class TCPDispatcher(Pyactive):
    def __init__(self, host, addr):
        Pyactive.__init__(self)
        ip, port = addr
        self.name = ip + ':' + str(port)
        self.conn = Server(ip, port, self)
        self.addr = addr
        self.host = host

        self.callback = {}

    #@async
    def _stop(self):
        self.conn.close()
        super(TCPDispatcher, self)._stop()

    def receive(self, msg):
        if msg[MODE] == SYNC and msg[TYPE] == CALL:
            self.callback[msg[RPC_ID]] = msg[SRC]
        msg[SRC] = self.addr

        self.conn.send(msg)

    def is_local(self, name):
        return name == self.name

    def on_message(self, msg):
        try:
            if msg[TYPE] == RESULT:
                if msg.has_key(MULTI):
                    target = self.callback[msg[RPC_ID]]
                    target.send(msg)
                if pending.has_key(msg[RPC_ID]):
                    del pending[msg[RPC_ID]]
                    target = self.callback[msg[RPC_ID]]
                    del self.callback[msg[RPC_ID]]
                    target.send(msg)
            else:
                if msg[MODE] == SYNC:
                    msg[TARGET] = msg[SRC]
                    msg[SRC] = self.channel
                    pending[msg[RPC_ID]] = 1
                aref = msg[TO]
                aurl = urlparse(aref)
                self.host.objects[aurl.path].channel.send(msg)
        except Exception, e:
            print e, 'TCP ERROR2'
예제 #3
0
class TCPDispatcher(Actor):

    def __init__(self,host, addr):
        Actor.__init__(self)
        ip, port = addr
        self.name = ip + ':' + str(port)
        self.conn = Server(ip, port, self)
        self.addr = addr
        self.host = host

        self.callback = {}

    def receive(self,msg):
        if msg[MODE]==SYNC and msg[TYPE]==CALL:
            self.callback[msg[RPC_ID]]= msg[SRC]

        msg[SRC] = self.addr
        try:
            self.conn.send(msg)
        except Exception,e:
            print e,'TCP ERROR 2'
예제 #4
0
class TCPDispatcher(Pyactive):
    """ """
    def __init__(self, host, addr=('127.0.0.1', 40406)):
        Pyactive.__init__(self)
        self.aref = 'asdhsah'
        ip, port = addr
        self.name = ip + ':' + str(port)
        self.conn = Server(ip, port, self)
        self.addr = addr
        self.host = host
        self.callback = {}

    def receive(self, msg):

        if msg[MODE] == SYNC and msg[TYPE] == CALL:
            self.callback[msg[RPC_ID]] = msg[SRC]

        msg[SRC] = self.addr

        try:
            self.conn.send(msg)
        except Exception, e:
            pass
예제 #5
0
class TCPDispatcher(Pyactive):
    """ """

    def __init__(self, host, addr=("127.0.0.1", 40406)):
        Pyactive.__init__(self)
        self.aref = "asdhsah"
        ip, port = addr
        self.name = ip + ":" + str(port)
        self.conn = Server(ip, port, self)
        self.addr = addr
        self.host = host
        self.callback = {}

    def receive(self, msg):

        if msg[MODE] == SYNC and msg[TYPE] == CALL:
            self.callback[msg[RPC_ID]] = msg[SRC]

        msg[SRC] = self.addr

        try:
            self.conn.send(msg)
        except Exception, e:
            pass