The RestartManager service allows developers to perform framework and OS restarts on demand. Using the service one can:
Registering bundle
The service is registered by System bundle.
Turning RestartManager on
The RestartManager service is registered under the com.prosyst.mbs.framework.restartmanager.RestartManager interface and is available when the mbs.restartmanager system property is set to true prior to framework startup.
Types of restarts
In the case of "storage factory reset", specify the following system properties:
Initiating a system restart
To initiate a system restart, you have to call the restart method of the RestartManager service. The method requires three arguments:
The code example from below contains an application that restarts the framework when a console command is issued. To supply the command, it implements the com.prosyst.util.pcommands.PluggableCommands interface. Then restart is called in the executeCommand method when the user executes the restartFW command or its shortcut rf.
This example shows how to use the RestartManager service:
package test.mbs.bundles.restart;
import java.io.PrintStream;
import java.util.Hashtable;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;
import com.prosyst.mbs.framework.restartmanager.RestartManager;
import com.prosyst.util.pcommands.CommandInfo;
import com.prosyst.util.pcommands.PluggableCommands;
public class RestartPluggableCommands implements BundleActivator, PluggableCommands {
ServiceReference restartRef;
RestartManager restartMngr;
ServiceRegistration pluggableReg;
final static String RESTART_REASON = "To test the Restart Manager";
final static String RESTART_COMMAND = "restartFW";
final static String RESTART_COMMAND_GROUP = "examples";
final static String RESTART_COMMAND_SHORTCUT = "rf";
public void start(BundleContext bc) throws Exception {
// Retrieving the Restart Manager
restartRef = bc.getServiceReference(RestartManager.class.getName());
restartMngr = (RestartManager) bc.getService(restartRef);
// Registering a service for exporting console commands
Hashtable regProps = new Hashtable(2);
regProps.put("group", RESTART_COMMAND_GROUP);
regProps.put("description", getGroupHelpMessage());
pluggableReg = bc.registerService(PluggableCommands.class.getName(), this, regProps);
}
// Executes the "restartFW" command or its "rf" shortcut
public void executeCommand(String name, String[] params, PrintStream pStream) {
if (name.equals(name) || name.equals(RESTART_COMMAND_SHORTCUT)) {
restartMngr.restart(RestartManager.RESTART_FW, RestartManager.FW_FACTORY, null);
}
}
public CommandInfo[] getCommandsInfo() {
CommandInfo[] commands = new CommandInfo[1];
String[] names = { RESTART_COMMAND, RESTART_COMMAND_SHORTCUT };
commands[0] = new CommandInfo(names, "Restarts the framework", null);
return commands;
}
public String getGroupHelpMessage() {
return "A command group to test the framework Restart Manager";
}
public String getGroupName() {
return RESTART_COMMAND_GROUP;
}
public void stop(BundleContext bc) throws Exception {
pluggableReg.unregister();
bc.ungetService(restartRef);
}
}