def main(self): """ Called to run twisted in the mainloop so messaging will work correctly. The webapp will be run via appmain. """ if self.messengerConf['state'] == 'on': # Only import if we use it: from evasion import messenger self.setUpStomp() self.log.info("main: running mainloop until done.") messenger.run(self.appmain) self.log.info("main: Exiting.") else: self.log.info("main: running mainloop (no messenger).") self.appmain(None) self.log.info("main: Exiting.")
def main(self, director_testing=False): """ The main thread in which twisted and the messagin system runs. The manager main run inside its own thread. The appman(...) is the main of the director. """ self.log.info("main: running.") c = config.get_cfg() class ExitTime(object): def __init__(self): self.exitTime = False def isExit(self): return self.exitTime et = ExitTime() # Allow twisted to be disable if no messaging is used or an alternative # approach is used. if NO_MESSAGING or c.director.messaging == 'no': try: self.appmain(et.isExit) except KeyboardInterrupt: self.log.warn("Ctrl-C, Exiting.") except: self.log.exception("Exiting on exception: ") finally: # Indicate the director should exit then call shutdown to # cleanly tell all controllers to shutdown as well et.exitTime = True self.shutdown() else: disable_broker = c.director.disable_broker if disable_broker == 'no': # Set up the messenger protocols where using: self.log.info("main: setting up stomp connection to broker.") messenger.stompprotocol.setup( dict( host=c.director.msg_host, port=int(c.director.msg_port), username=c.director.msg_username, password=c.director.msg_password, channel=c.director.msg_channel, )) else: self.log.warn( "main: the director's broker connection is disabled (disable_broker = 'yes')." ) # Use internal broker? This allow simplifies things and # means we don't have to run a morbid/other program as # a child process. # if c.director.internal_broker == 'yes': self.log.warn( "main: Starting the interal light weight broker (internal_broker = 'yes')." ) from evasion.director import testing testing.setup_broker(int(c.director.msg_port), c.director.msg_interface) noproxydispatchbroker = c.director.noproxydispatch if noproxydispatchbroker == 'no': from evasion.director import proxydispatch port = int(c.director.proxy_dispatch_port) self.log.info( "main: setting up reply proxy dispatch http://127.0.0.1:%s/ ." % port) proxydispatch.setup(port) else: self.log.warn( "main: the director's proxydispatch is disabled (noproxydispatch = 'yes')." ) if director_testing: self.log.warn( "main: testing active! The main loop is running elsewhere." ) else: try: self.log.info("main: Running.") messenger.run(self.appmain) finally: self.log.info("main: shutdown!") self.shutdown() self.exit()
def main(self, director_testing=False): """ The main thread in which twisted and the messagin system runs. The manager main run inside its own thread. The appman(...) is the main of the director. """ self.log.info("main: running.") c = config.get_cfg() class ExitTime(object): def __init__(self): self.exitTime = False def isExit(self): return self.exitTime et = ExitTime() # Allow twisted to be disable if no messaging is used or an alternative # approach is used. if NO_MESSAGING or c.director.messaging == 'no': try: self.appmain(et.isExit) except KeyboardInterrupt: self.log.warn("Ctrl-C, Exiting.") except: self.log.exception("Exiting on exception: ") finally: # Indicate the director should exit then call shutdown to # cleanly tell all controllers to shutdown as well et.exitTime = True self.shutdown() else: disable_broker = c.director.disable_broker if disable_broker == 'no': # Set up the messenger protocols where using: self.log.info("main: setting up stomp connection to broker.") messenger.stompprotocol.setup(dict( host=c.director.msg_host, port=int(c.director.msg_port), username=c.director.msg_username, password=c.director.msg_password, channel=c.director.msg_channel, )) else: self.log.warn("main: the director's broker connection is disabled (disable_broker = 'yes').") # Use internal broker? This allow simplifies things and # means we don't have to run a morbid/other program as # a child process. # if c.director.internal_broker == 'yes': self.log.warn("main: Starting the interal light weight broker (internal_broker = 'yes').") from evasion.director import testing testing.setup_broker( int(c.director.msg_port), c.director.msg_interface ) noproxydispatchbroker = c.director.noproxydispatch if noproxydispatchbroker == 'no': from evasion.director import proxydispatch port = int(c.director.proxy_dispatch_port) self.log.info("main: setting up reply proxy dispatch http://127.0.0.1:%s/ ." % port) proxydispatch.setup(port) else: self.log.warn("main: the director's proxydispatch is disabled (noproxydispatch = 'yes').") if director_testing: self.log.warn("main: testing active! The main loop is running elsewhere.") else: try: self.log.info("main: Running.") messenger.run(self.appmain) finally: self.log.info("main: shutdown!") self.shutdown() self.exit()