def shutdown(self): """ Shutdown the thread. """ self._running = 0 from ioidslogging import EVENTTRIGGER_STATUS, getDefaultLogger getDefaultLogger().newMessage(EVENTTRIGGER_STATUS, 'Event Trigger process stopped')
def shutdown(self): """ Shutdown the data engine thread. """ self._running = 0 from ioidslogging import DATAENGINE_STATUS, getDefaultLogger getDefaultLogger().newMessage(DATAENGINE_STATUS, 'Data engine process stopped')
def runUntilShutdown(self): """ This is the function, running in the thread, which will initiate the event download frequently. """ from ioidslogging import EVENTTRIGGER_UPDATE, getDefaultLogger import time time.sleep(self._interval) while self._running: getDefaultLogger().newMessage(EVENTTRIGGER_UPDATE, 'Event Trigger: Synchronise with event database.') self._triggerEventsNow() time.sleep(self._interval)
def startup(self): """ Puts the trigger in the background thread and makes it waiting until it's shutdown. """ from config import DB_POLL_INTERVAL self._interval = DB_POLL_INTERVAL self._running = 1 import thread thread.start_new_thread(self.runUntilShutdown, ()) from ioidslogging import EVENTTRIGGER_STATUS, getDefaultLogger getDefaultLogger().newMessage(EVENTTRIGGER_STATUS, 'Event Trigger process started')
def startup(self): """ Start up the data engine in its background thread. """ from config import DATA_ENGINE_PROCESSING_INTERVAL self._interval = DATA_ENGINE_PROCESSING_INTERVAL self._running = 1 import thread thread.start_new_thread(self.runUntilShutdown, ()) ## self.runUntilShutdown() from ioidslogging import DATAENGINE_STATUS, getDefaultLogger getDefaultLogger().newMessage(DATAENGINE_STATUS, 'Data engine process started')
def runUntilShutdown(self): """ In here, all the queues are checked frequently and appropriate actions are undertaken. """ from ioidslogging import DATAENGINE_PROCESSING_DETAILS, getDefaultLogger, DATAENGINE_ERROR_GENERIC import time time.sleep(self._interval) while self._running: try: getDefaultLogger().newMessage(DATAENGINE_PROCESSING_DETAILS, 'Data engine details: check my lists') counter = 0 while len(self._localEvents): self._processEventFromLocal(self._localEvents[0]) del self._localEvents[0] counter += 1 getDefaultLogger().newMessage(DATAENGINE_PROCESSING_DETAILS, '-- Data engine details: Processed %d local events.' %(counter)) counter = 0 while len(self._localIoidsEvents): self._processIoidsEventFromLocal(self._localIoidsEvents[0]) del self._localIoidsEvents[0] counter += 1 getDefaultLogger().newMessage(DATAENGINE_PROCESSING_DETAILS, '-- Data engine details: Processed %d local ioids events.' %(counter)) ## except Exception, msg: except ValueError, msg: getDefaultLogger().newMessage(DATAENGINE_ERROR_GENERIC, 'Data engine ERROR: %s' %(msg)) time.sleep(self._interval)
def startup(self): """ Loads the policy XML files into memory. """ tmpRules = [] parser = PolicyParser() locations = config.LOCATION_POLICY_FILES for location in locations: file = open(location, 'r') policy = file.read() file.close() rules = parser.parsePolicy(policy) tmpRules += rules from ioidslogging import getDefaultLogger, DATAENGINE_POLICY_STATUS getDefaultLogger().newMessage(DATAENGINE_POLICY_STATUS, 'PolicyEngine: Processed %d rule(s) from %d file(s) on startup' %(len(tmpRules), len(locations))) for rule in tmpRules: self._rules[rule['id']] = rule self._sortedKeys = self._rules.keys() self._sortedKeys.sort()
def sendMessage(self, data, action, receiver = None): """ Testing - send it off to everybody in the service :) """ if not receiver: from config import G4DS_SERVICE_ID receiver = G4DS_SERVICE_ID self._g4ds.sendMessage(receiver, None, data, action) from ioidslogging import getDefaultLogger, G4DS_CONNECTOR_OUTGOING_MSG, G4DS_CONNECTOR_OUTGOING_MSG_DETAILS getDefaultLogger().newMessage(G4DS_CONNECTOR_OUTGOING_MSG, 'G4DS Outgoing message: Passed new message to %s' %(receiver)) getDefaultLogger().newMessage(G4DS_CONNECTOR_OUTGOING_MSG_DETAILS, '-- Outgoing message details: action is %s' %(action)) getDefaultLogger().newMessage(G4DS_CONNECTOR_OUTGOING_MSG_DETAILS, '-- Outgoing message details: data size is %s' %(len(data)))
def dispatch(self, data, metadata): """ First instance for incoming messages. """ ## print "My meta data: %s" %metadata from ioidslogging import getDefaultLogger, G4DS_CONNECTOR_INCOMING_MSG, G4DS_CONNECTOR_INCOMING_MSG_DETAILS getDefaultLogger().newMessage(G4DS_CONNECTOR_INCOMING_MSG, 'G4DS Incoming message: Received data from %s | %s' %(metadata['senderid'], metadata['communityid'])) getDefaultLogger().newMessage(G4DS_CONNECTOR_INCOMING_MSG_DETAILS, '-- G4DS Incoming message details: action is %s ' %(metadata['actionstring'])) getDefaultLogger().newMessage(G4DS_CONNECTOR_INCOMING_MSG_DETAILS, '-- G4DS Incoming message details: data size is %s ' %(len(data))) if metadata['actionstring'] == 'ioids.write.newevent': self._incomingMessageNewIoidsEvent(data) elif metadata['actionstring'] == 'ioids.read.events': sender = metadata['senderid'] community = metadata['communityid'] self._replyToKnowledgeRequest(sender, community, data)