示例#1
0
文件: echo.py 项目: markokr/cc
 def on_recv (self, zmsg):
     """ Got reply from a remote CC, process it. """
     try:
         self.log.trace ("%r", zmsg)
         cmsg = CCMessage (zmsg)
         req = cmsg.get_dest()
         if req == "echo.response":
             self.process_response (cmsg)
         else:
             self.log.warn ("unknown msg: %s", req)
     except:
         self.log.exception ("crashed, dropping msg")
示例#2
0
 def on_recv(self, zmsg):
     """ Got reply from a remote CC, process it. """
     try:
         self.log.trace("%r", zmsg)
         cmsg = CCMessage(zmsg)
         req = cmsg.get_dest()
         if req == "echo.response":
             self.process_response(cmsg)
         else:
             self.log.warn("unknown msg: %s", req)
     except:
         self.log.exception("crashed, dropping msg")
示例#3
0
文件: proxy.py 项目: gamato/hots-cc
 def on_recv (self, zmsg):
     """ Got message from remote CC, process it. """
     try:
         # pongs to our pings should come back w/o any routing info
         if self.ping_remote and zmsg[0] == '':
             self.log.trace ("%r", zmsg)
             cmsg = CCMessage (zmsg)
             req = cmsg.get_dest()
             if req == "echo.response":
                 self._recv_pong (cmsg)
             else:
                 self.log.warn ("unknown msg: %s", req)
     except:
         self.log.exception ("crashed")
     finally:
         super(ProxyHandler, self).on_recv(zmsg)
示例#4
0
文件: proxy.py 项目: postsql/cc
 def on_recv(self, zmsg):
     """ Got message from remote CC, process it. """
     try:
         # pongs to our pings should come back w/o any routing info
         if self.ping_remote and zmsg[0] == '':
             self.log.trace("%r", zmsg)
             cmsg = CCMessage(zmsg)
             req = cmsg.get_dest()
             if req == "echo.response":
                 self._recv_pong(cmsg)
             else:
                 self.log.warn("unknown msg: %s", req)
     except:
         self.log.exception("crashed")
     finally:
         super(ProxyHandler, self).on_recv(zmsg)
示例#5
0
文件: server.py 项目: postsql/cc
    def handle_cc_recv(self, zmsg):
        """Got message from client, pick handler."""

        start = time.time()
        self.stat_inc('count')
        self.log.trace('got msg: %r', zmsg)
        try:
            cmsg = CCMessage(zmsg)
        except:
            self.log.exception('Invalid CC message')
            self.stat_increase('count.invalid')
            return

        try:
            dst = cmsg.get_dest()
            size = cmsg.get_size()
            route = tuple(dst.split('.'))

            # find and run all handlers that match
            cnt = 0
            for n in range(0, 1 + len(route)):
                p = route[:n]
                for h in self.routes.get(p, []):
                    self.log.trace('calling handler %s', h.hname)
                    h.handle_msg(cmsg)
                    cnt += 1
            if cnt == 0:
                self.log.warning('dropping msg, no route: %s', dst)
                stat = 'dropped'
            else:
                stat = 'ok'

        except Exception:
            self.log.exception('crashed, dropping msg: %s', dst)
            stat = 'crashed'

        # update stats
        taken = time.time() - start
        self.stat_inc('bytes', size)
        self.stat_inc('seconds', taken)
        self.stat_inc('count.%s' % stat)
        self.stat_inc('bytes.%s' % stat, size)
        self.stat_inc('seconds.%s' % stat, taken)
        if self.stat_level > 1:
            self.stat_inc('count.%s.msg.%s' % (stat, dst))
            self.stat_inc('bytes.%s.msg.%s' % (stat, dst), size)
            self.stat_inc('seconds.%s.msg.%s' % (stat, dst), taken)
示例#6
0
文件: server.py 项目: markokr/cc
    def handle_cc_recv(self, zmsg):
        """Got message from client, pick handler."""

        start = time.time()
        self.stat_inc("count")
        self.log.trace("got msg: %r", zmsg)
        try:
            cmsg = CCMessage(zmsg)
        except:
            self.log.exception("Invalid CC message")
            self.stat_increase("count.invalid")
            return

        try:
            dst = cmsg.get_dest()
            size = cmsg.get_size()
            route = tuple(dst.split("."))

            # find and run all handlers that match
            cnt = 0
            for n in range(0, 1 + len(route)):
                p = route[:n]
                for h in self.routes.get(p, []):
                    self.log.trace("calling handler %s", h.hname)
                    h.handle_msg(cmsg)
                    cnt += 1
            if cnt == 0:
                self.log.warning("dropping msg, no route: %s", dst)
                stat = "dropped"
            else:
                stat = "ok"

        except Exception:
            self.log.exception("crashed, dropping msg: %s", dst)
            stat = "crashed"

        # update stats
        taken = time.time() - start
        self.stat_inc("bytes", size)
        self.stat_inc("seconds", taken)
        self.stat_inc("count.%s" % stat)
        self.stat_inc("bytes.%s" % stat, size)
        self.stat_inc("seconds.%s" % stat, taken)
        if self.stat_level > 1:
            self.stat_inc("count.%s.msg.%s" % (stat, dst))
            self.stat_inc("bytes.%s.msg.%s" % (stat, dst), size)
            self.stat_inc("seconds.%s.msg.%s" % (stat, dst), taken)
示例#7
0
文件: server.py 项目: gamato/hots-cc
    def handle_cc_recv(self, zmsg):
        """Got message from client, pick handler."""

        start = time.time()
        self.stat_inc ('count')
        self.log.trace('got msg: %r', zmsg)
        try:
            cmsg = CCMessage(zmsg)
        except:
            self.log.exception('Invalid CC message')
            self.stat_increase('count.invalid')
            return

        try:
            dst = cmsg.get_dest()
            size = cmsg.get_size()
            route = tuple(dst.split('.'))

            # find and run all handlers that match
            cnt = 0
            for n in range(0, 1 + len(route)):
                p = route[ : n]
                for h in self.routes.get(p, []):
                    self.log.trace('calling handler %s', h.hname)
                    h.handle_msg(cmsg)
                    cnt += 1
            if cnt == 0:
                self.log.warning('dropping msg, no route: %s', dst)
                stat = 'dropped'
            else:
                stat = 'ok'

        except Exception:
            self.log.exception('crashed, dropping msg: %s', dst)
            stat = 'crashed'

        # update stats
        taken = time.time() - start
        self.stat_inc ('bytes', size)
        self.stat_inc ('seconds', taken)
        self.stat_inc ('count.%s' % stat)
        self.stat_inc ('bytes.%s' % stat, size)
        self.stat_inc ('seconds.%s' % stat, taken)
        if self.stat_level > 1:
            self.stat_inc ('count.%s.msg.%s' % (stat, dst))
            self.stat_inc ('bytes.%s.msg.%s' % (stat, dst), size)
            self.stat_inc ('seconds.%s.msg.%s' % (stat, dst), taken)