message response queue and added classes to ahenkd service

This commit is contained in:
İsmail Başaran 2016-03-02 17:20:42 +02:00
parent 8939ac4a36
commit 3956c0539b
4 changed files with 46 additions and 14 deletions

View file

@ -7,10 +7,12 @@ from base.deamon.BaseDeamon import BaseDaemon
from base.logger.AhenkLogger import Logger
from base.Scope import Scope
from base.messaging.Messaging import Messaging
from base.messaging.MessageResponseQueue import MessageResponseQueue
from base.plugin.PluginManager import PluginManager
from base.task.TaskManager import TaskManager
from multiprocessing import Process
from threading import Thread
import sys,logging
import time
import sys,logging,queue,time
class AhenkDeamon(BaseDaemon):
@ -29,11 +31,21 @@ class AhenkDeamon(BaseDaemon):
config = configManager.read()
globalscope.setConfigurationManager(config)
# Logger must be second
logger = Logger()
logger.info("obaraaa")
logger.info("this is info log")
globalscope.setLogger(logger)
pluginManager = PluginManager()
pluginManager.loadPlugins()
globalscope.setPluginManager(pluginManager)
taskManger = TaskManager()
globalscope.setTaskManager(taskManger)
# add services after this line
"""
xmpp = Messaging()
print("xmpp is created")
p = Process(target=xmpp.connect_to_server)
@ -44,7 +56,16 @@ class AhenkDeamon(BaseDaemon):
time.sleep(5)
print("sleep is over ")
xmpp.send_direct_message("asdasdas")# not working ->connection error
"""
"""
this is must be created after message services
responseQueue = queue.Queue()
messageResponseQueue = MessageResponseQueue(responseQueue)
messageResponseQueue.setDaemon(True)
messageResponseQueue.start()
globalscope.setResponseQueue(responseQueue)
"""
if __name__ == '__main__':

View file

@ -16,6 +16,7 @@ class Scope(object):
self.logger=None
self.pluginManager=None
self.taskManager=None
self.responseQueue=None
@staticmethod
def getInstance():
@ -64,3 +65,9 @@ class Scope(object):
def setTaskManager(self,taskManager):
self.taskManager = taskManager
def getResponseQueue(self):
return self.responseQueue
def setResponseQueue(self,responseQueue):
self.responseQueue=responseQueue

View file

@ -24,6 +24,6 @@ class MessageResponseQueue(threading.Thread):
print(item)
# Call message manager for response
self.messageManager.sendResponse(responseMessage)
self.outQueue.task_done()
#self.outQueue.task_done()
except:
pass

View file

@ -18,6 +18,7 @@ class PluginManager(object):
self.logger = scope.getLogger()
def loadPlugins(self):
print("loading")
self.plugins = []
possibleplugins = os.listdir(self.configManager.get("PLUGIN", "pluginFolderPath"))
for pname in possibleplugins:
@ -72,3 +73,6 @@ class PluginManager(object):
def checkCommandExist(self,pluginName,commandId):
# Not implemented yet
pass
def printQueueSize(self):
print("size " + str(len(self.pluginQueueDict)))