Skip to content

Commit

Permalink
enhancement #21 : Adding shutdown command
Browse files Browse the repository at this point in the history
  • Loading branch information
debbabi committed Mar 11, 2015
1 parent c143f92 commit 15d4e6d
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion python/cohorte/shell/forker.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,24 @@
import cohorte
import herald

import herald.beans as beans

# Shell constants
from pelix.shell import SHELL_COMMAND_SPEC

# iPOPO Decorators
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):
Expand All @@ -65,6 +70,7 @@ def __init__(self):
# Injected services
self._directory = None
self._forker = None
self._herald = None

def get_namespace(self):
"""
Expand All @@ -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):
"""
Expand Down Expand Up @@ -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

0 comments on commit 15d4e6d

Please sign in to comment.