Пример #1
0
class ConditionEngine:

	def __init__(self):
		self.evaluation_queue = EvaluationQueue(self)

	def init(self, system, state, router, task_scheduler):
		self.system = system
		self.router = router
		self.load_conditions(state)
		self.evaluation_queue.start()

	def load_conditions(self, state):
		condition_json = []
		try:
			condition_json = json.load(open('conditions.json','r+'))
		except:
			pass
		condition_list = []

		for condition in condition_json: #for each node in the configuration file
			condition_module = condition['module']
			condition_class = condition['class']
			new_condition = getattr(globals()[condition_module], condition_class)(state, self) # create the condition object...
			condition_list.append(new_condition)
			logger.info('Added new condition: ' + condition_class)

		self.condition_list = condition_list

	def evaluate_conditions(self, node_label, command):
		logger.info('Beginning evaluation: ' + str(command))
		for condition in self.condition_list:
			condition.evaluate(node_label, command)

	def add_message(self, message):
		self.evaluation_queue.add_message(message)

	def add_to_task_scheduler(self, message):
		self.task_scheduler.add_task(message)

	def send_to_node(self, node_label, message):
		self.router.send_to_node(node_label, message)

	def get_from_node(self, node_label, arguments):
		self.router.get_from_node(node_label, arguments)

	def send_to_system(self, node_label, message):
		self.system.send(node_label, message)

	def stop(self):
		self.evaluation_queue.stop()
Пример #2
0
	def __init__(self):
		self.evaluation_queue = EvaluationQueue(self)