diff --git a/python/cohorte/shell/forker.py b/python/cohorte/shell/forker.py index ff8760be..b62468d0 100644 --- a/python/cohorte/shell/forker.py +++ b/python/cohorte/shell/forker.py @@ -39,6 +39,8 @@ import cohorte import herald +import herald.beans as beans + # Shell constants from pelix.shell import SHELL_COMMAND_SPEC @@ -46,12 +48,15 @@ from pelix.ipopo.decorators import ComponentFactory, Requires, Provides, \ Instantiate +import threading + # ------------------------------------------------------------------------------ @ComponentFactory("cohorte-forker-shell-commands-factory") @Requires("_directory", herald.SERVICE_DIRECTORY) @Requires("_forker", cohorte.SERVICE_FORKER) +@Requires('_herald', herald.SERVICE_HERALD) @Provides(SHELL_COMMAND_SPEC) @Instantiate("cohorte-forker-shell-commands") class ForkerCommands(object): @@ -65,6 +70,7 @@ def __init__(self): # Injected services self._directory = None self._forker = None + self._herald = None def get_namespace(self): """ @@ -77,7 +83,8 @@ def get_methods(self): Retrieves the list of tuples (command, method) for this command handler """ return [("stop", self.stop_isolate), - ("ping", self.ping)] + ("ping", self.ping), + ("shutdown", self.shutdown)] def get_methods_names(self): """ @@ -127,3 +134,21 @@ def stop_isolate(self, io_handler, isolate): self._forker.stop_isolate(uid) except KeyError as ex: io_handler.write_line("Error: {0}", ex) + + def shutdown(self, io_handler): + """ + Shutdown all the platform (all the nodes) + """ + msg = beans.Message(cohorte.monitor.SIGNAL_STOP_PLATFORM) + try: + # send to other monitors + self._herald.fire_group('monitors', msg) + except: + pass + + try: + # send to local peer + msg2 = beans.MessageReceived(msg.uid, msg.subject, msg.content, "local", "local", "local") + threading.Thread(target=self._herald.handle_message, args=[msg2]).start() + except: + pass