Esempio n. 1
0
    def onHeartBeat(self):
        try:
            t = datetime.datetime.now()
            if t.minute == 1 and t.second == 1:
                self.gdata.checkUserObjects(self.gdata)
        except:
            TyContext.ftlog.exception()

        try:
            if self.udpProtocol:
                mi = TyContext.MsgLine(0, [],
                                       '{"cmd":"server_heart_beat"}\n\0')
                tc = getattr(self.udpProtocol, 'makeTimerTasklet', None)
                if tc != None:
                    c = self.udpProtocol.makeTimerTasklet(self)
                else:
                    c = self.udpProtocol.makeTasklet(mi, None, None)
                stackless.tasklet(c.tasklet)()
                reactor.callLater(0, stackless.schedule)
            elif self.httpFactory:
                c = self.httpFactory.makeHeartBeatTasklet()
                if c:
                    stackless.tasklet(c.tasklet)()
                    reactor.callLater(0, stackless.schedule)
            else:
                TyContext.ftlog.error(
                    'ERROR, Can not creat heart beat tasklet !')
        except:
            TyContext.ftlog.exception('onHeartBeat')
Esempio n. 2
0
 def lineReceived(self, data):
     from tyframework.context import TyContext
     try:
         if TyContext.ftlog.is_debug_net():
             TyContext.ftlog.debug('====== BRIDGE RECEIVE ', self._key,
                                   self.userId, data)
         msgline = TyContext.MsgLine(0, None, data)
         c = self.makeTasklet(msgline)
         stackless.tasklet(c.tasklet)()
     except Exception, e:
         TyContext.ftlog.error('\n' * 5)
         TyContext.ftlog.error("ERROR ======BRIDGE RECEIVE ", e)
         TyContext.ftlog.exception()
         TyContext.ftlog.error('\n' * 5)
         self.transport.write(
             TyContext.MsgPack.makeErrorString('error pack'))
         self.transport.loseConnection()
Esempio n. 3
0
 def lineReceived(cls, protocol, data):
     try:
         if TyContext.ftlog.is_debug_net():
             TyContext.ftlog.debug('====== RECEIVE ', protocol._key, protocol.userId, data)
         msgline = TyContext.MsgLine(0, None, data)
         """
         if msgline.cmd == 'heart_beat' :
             uhc = protocol.heart_beat_count + 1
             protocol.heart_beat_count = uhc
             if uhc % HEART_BEAT_RECIVE_MOD == 0 :
                 return
         """
         c = protocol.makeTasklet(msgline)
         stackless.tasklet(c.tasklet)()
     except Exception, e:
         TyContext.ftlog.error('\n' * 5)
         TyContext.ftlog.error("ERROR ====== RECEIVE ", e)
         TyContext.ftlog.exception()
         TyContext.ftlog.error('\n' * 5)
         protocol.transport.write(TyContext.MsgPack.makeErrorString('error pack'))
         protocol.transport.loseConnection()