public Shutdown(String[] args) throws StartupException {
Config config = getConfig(args);
if (config == null) {
return;
}
String portStr = null;
if (config.isArg(Constants.Arg.AdminPort)) {
portStr = (String)config.getConfig().getAttribute(
Constants.Attribute.AdminPort);
} else {
Properties props = getProperties();
portStr = props.getProperty(Constants.Property.AdminPort);
}
Registry registry = getRegistry(portStr);
String[] services = getServices(registry);
int counter = 0;
for (int i = 0; i < services.length; i++) {
String service = services[i];
if (service.startsWith(Constants.Registry.Service + ":")) {
boolean exit =
(++counter == services.length) ? true : false;
try {
((Admin)(registry.lookup(service))).stopService(exit);
registry.unbind(service);
} catch (Exception e) {
System.out.println(sm.getString("shutdown.service.e"));
System.out.println(e.toString());
e.printStackTrace();
}
}
}
services = getServices(registry);
if (services.length == 0) {
File f = null;
try {
f = new File(Constants.Server.LogFile);
} catch (NullPointerException npe) {
System.out.println(sm.getString("shutdown.log.npe",
Constants.Server.ConfigFile));
}
try {
if (f.exists() &&
f.isFile()) {
f.delete();
}
} catch (SecurityException se) {
System.out.println(sm.getString("shutdown.log.se",
Constants.Server.LogFile));
}
}
}
|