Example #1
0
 def logException(self, whileClause):
     errClass, errObject, errTB = sys.exc_info()[:3]
     errText = '%s.%s: %s' % (errClass.__module__,
                              errClass.__name__,
                              str(errObject))
     logging.warning(''.join(traceback.format_tb(errTB)))
     logging.warning(errText)
     logging.warning('[error while %s at time %s]', whileClause, getTimestamp())
Example #2
0
 def logException(self, whileClause):
     errClass, errObject, errTB = sys.exc_info()[:3]
     errText = '%s.%s: %s' % (errClass.__module__, errClass.__name__,
                              str(errObject))
     logging.warning(''.join(traceback.format_tb(errTB)))
     logging.warning(errText)
     logging.warning('[error while %s at time %s]', whileClause,
                     getTimestamp())
Example #3
0
 def handleDisconnectTimer(self):
     now = getTimestamp()
     disconnectModules = []
     for moduleName, entry in self.info.iteritems():
         timeout = entry.get('timeout', None)
         if timeout is not None and now > timeout:
             disconnectModules.append(moduleName)
     for moduleName in disconnectModules:
         self.announceDisconnect(moduleName)
         del self.info[moduleName]
Example #4
0
 def handleDisconnectTimer(self):
     now = getTimestamp()
     disconnectModules = []
     for moduleName, entry in self.info.iteritems():
         timeout = entry.get('timeout', None)
         if timeout is not None and now > timeout:
             disconnectModules.append(moduleName)
     for moduleName in disconnectModules:
         self.announceDisconnect(moduleName)
         del self.info[moduleName]
Example #5
0
    def handleHeartbeat(self, params):
        moduleName = params['module'].encode('utf-8')
        now = getTimestamp()

        oldInfo = self.info.get(moduleName, None)
        if oldInfo:
            if oldInfo.get('pub', None) != params.get('pub', None):
                self.announceDisconnect(moduleName)
                self.announceConnect(moduleName, params)
        else:
            self.announceConnect(moduleName, params)

        self.info[moduleName] = params
        keepalive = params.get('keepalive', DEFAULT_KEEPALIVE_US)
        params['timeout'] = now + keepalive
        return 'ok'
Example #6
0
    def handleHeartbeat(self, params):
        moduleName = params['module'].encode('utf-8')
        now = getTimestamp()

        oldInfo = self.info.get(moduleName, None)
        if oldInfo:
            if oldInfo.get('pub', None) != params.get('pub', None):
                self.announceDisconnect(moduleName)
                self.announceConnect(moduleName, params)
        else:
            self.announceConnect(moduleName, params)

        self.info[moduleName] = params
        keepalive = params.get('keepalive', DEFAULT_KEEPALIVE_US)
        params['timeout'] = now + keepalive
        return 'ok'
Example #7
0
 def logMessage(self, msg, posixTime=None, attachmentDir='-'):
     mlog = self.messageLog
     mlog.write('@@@ %d %d %s ' %
                (getTimestamp(posixTime), len(msg), attachmentDir))
     mlog.write(msg)
     mlog.write('\n')
Example #8
0
 def announceDisconnect(self, moduleName):
     logging.info('module %s disconnected', moduleName)
     self.injectStream.send(
         'central.disconnect.%s:%s' %
         (moduleName, json.dumps({'timestamp': str(getTimestamp())})))
Example #9
0
 def sendJson(self, topic, obj):
     if isinstance(obj, dict):
         obj.setdefault('module', self.moduleName)
         obj.setdefault('timestamp', str(getTimestamp()))
     self.sendRaw(topic, json.dumps(obj))
Example #10
0
 def sendJson(self, topic, obj):
     if isinstance(obj, dict):
         obj.setdefault('module', self.moduleName)
         obj.setdefault('timestamp', str(getTimestamp()))
     self.sendRaw(topic, json.dumps(obj))
Example #11
0
 def logMessage(self, msg, posixTime=None, attachmentDir='-'):
     mlog = self.messageLog
     mlog.write('@@@ %d %d %s ' % (getTimestamp(posixTime), len(msg), attachmentDir))
     mlog.write(msg)
     mlog.write('\n')
Example #12
0
 def announceDisconnect(self, moduleName):
     logging.info('module %s disconnected', moduleName)
     self.injectStream.send('central.disconnect.%s:%s'
                            % (moduleName,
                               json.dumps({'timestamp': str(getTimestamp())})))
Example #13
0
 def logMessage(self, msg):
     mlog = self.messageLog
     mlog.write('@@@ %d %d ' % (getTimestamp(), len(msg)))
     mlog.write(msg)
     mlog.write('\n')