summaryrefslogtreecommitdiff
path: root/java/src/IceBox/ServiceManagerI.java
diff options
context:
space:
mode:
authorMatthew Newhook <matthew@zeroc.com>2005-10-20 05:34:48 +0000
committerMatthew Newhook <matthew@zeroc.com>2005-10-20 05:34:48 +0000
commit61e10b27cedb681675cf33b1ec96d56d8e01ea38 (patch)
treecbc26fcc329bd0281b80ca0900b7f8987c6c1615 /java/src/IceBox/ServiceManagerI.java
parenthttp://www.zeroc.com/vbulletin/showthread.php?t=1795 (diff)
downloadice-61e10b27cedb681675cf33b1ec96d56d8e01ea38.tar.bz2
ice-61e10b27cedb681675cf33b1ec96d56d8e01ea38.tar.xz
ice-61e10b27cedb681675cf33b1ec96d56d8e01ea38.zip
http://wiki.zeroc.com/bugzilla/show_bug.cgi?id=528
Diffstat (limited to 'java/src/IceBox/ServiceManagerI.java')
-rw-r--r--java/src/IceBox/ServiceManagerI.java545
1 files changed, 283 insertions, 262 deletions
diff --git a/java/src/IceBox/ServiceManagerI.java b/java/src/IceBox/ServiceManagerI.java
index ba0e00c03aa..86d7246d5ec 100644
--- a/java/src/IceBox/ServiceManagerI.java
+++ b/java/src/IceBox/ServiceManagerI.java
@@ -19,106 +19,106 @@ public class ServiceManagerI extends _ServiceManagerDisp
ServiceManagerI(Ice.Application server, String[] args)
{
_server = server;
- _logger = _server.communicator().getLogger();
- _argv = args;
+ _logger = _server.communicator().getLogger();
+ _argv = args;
}
public java.util.Map
getSliceChecksums(Ice.Current current)
{
- return SliceChecksums.checksums;
+ return SliceChecksums.checksums;
}
public void
shutdown(Ice.Current current)
{
- _server.communicator().shutdown();
+ _server.communicator().shutdown();
}
public int
run()
{
- try
- {
- //
- // Create an object adapter. Services probably should NOT share
- // this object adapter, as the endpoint(s) for this object adapter
- // will most likely need to be firewalled for security reasons.
- //
- Ice.ObjectAdapter adapter = _server.communicator().createObjectAdapter("IceBox.ServiceManager");
+ try
+ {
+ //
+ // Create an object adapter. Services probably should NOT share
+ // this object adapter, as the endpoint(s) for this object adapter
+ // will most likely need to be firewalled for security reasons.
+ //
+ Ice.ObjectAdapter adapter = _server.communicator().createObjectAdapter("IceBox.ServiceManager");
Ice.Properties properties = _server.communicator().getProperties();
String identity = properties.getPropertyWithDefault("IceBox.ServiceManager.Identity", "ServiceManager");
- adapter.add(this, Ice.Util.stringToIdentity(identity));
-
- //
- // Parse the IceBox.LoadOrder property.
- //
- String order = properties.getProperty("IceBox.LoadOrder");
- String[] loadOrder = null;
- if(order.length() > 0)
- {
- loadOrder = order.trim().split("[,\t ]+");
- }
-
- //
- // Load and start the services defined in the property set
- // with the prefix "IceBox.Service.". These properties should
- // have the following format:
- //
- // IceBox.Service.Foo=Package.Foo [args]
- //
- // We load the services specified in IceBox.LoadOrder first,
- // then load any remaining services.
- //
- final String prefix = "IceBox.Service.";
+ adapter.add(this, Ice.Util.stringToIdentity(identity));
+
+ //
+ // Parse the IceBox.LoadOrder property.
+ //
+ String order = properties.getProperty("IceBox.LoadOrder");
+ String[] loadOrder = null;
+ if(order.length() > 0)
+ {
+ loadOrder = order.trim().split("[,\t ]+");
+ }
+
+ //
+ // Load and start the services defined in the property set
+ // with the prefix "IceBox.Service.". These properties should
+ // have the following format:
+ //
+ // IceBox.Service.Foo=Package.Foo [args]
+ //
+ // We load the services specified in IceBox.LoadOrder first,
+ // then load any remaining services.
+ //
+ final String prefix = "IceBox.Service.";
java.util.Map services = properties.getPropertiesForPrefix(prefix);
- if(loadOrder != null)
- {
- for(int i = 0; i < loadOrder.length; ++i)
- {
- if(loadOrder[i].length() > 0)
- {
- String key = prefix + loadOrder[i];
- String value = (String)services.get(key);
- if(value == null)
- {
- FailureException ex = new FailureException();
- ex.reason = "ServiceManager: no service definition for `" + loadOrder[i] + "'";
- throw ex;
- }
- load(loadOrder[i], value);
- services.remove(key);
- }
- }
- }
+ if(loadOrder != null)
+ {
+ for(int i = 0; i < loadOrder.length; ++i)
+ {
+ if(loadOrder[i].length() > 0)
+ {
+ String key = prefix + loadOrder[i];
+ String value = (String)services.get(key);
+ if(value == null)
+ {
+ FailureException ex = new FailureException();
+ ex.reason = "ServiceManager: no service definition for `" + loadOrder[i] + "'";
+ throw ex;
+ }
+ load(loadOrder[i], value);
+ services.remove(key);
+ }
+ }
+ }
java.util.Iterator p = services.entrySet().iterator();
while(p.hasNext())
{
java.util.Map.Entry entry = (java.util.Map.Entry)p.next();
String name = ((String)entry.getKey()).substring(prefix.length());
String value = (String)entry.getValue();
- load(name, value);
- }
-
- //
- // We may want to notify external scripts that the services
- // have started. This is done by defining the property:
- //
- // IceBox.PrintServicesReady=bundleName
- //
- // Where bundleName is whatever you choose to call this set of
- // services. It will be echoed back as "bundleName ready".
- //
- // This must be done after start() has been invoked on the
- // services.
- //
- String bundleName = properties.getProperty("IceBox.PrintServicesReady");
- if(bundleName.length() > 0)
- {
- System.out.println(bundleName + " ready");
- }
+ load(name, value);
+ }
+
+ //
+ // We may want to notify external scripts that the services
+ // have started. This is done by defining the property:
+ //
+ // IceBox.PrintServicesReady=bundleName
+ //
+ // Where bundleName is whatever you choose to call this set of
+ // services. It will be echoed back as "bundleName ready".
+ //
+ // This must be done after start() has been invoked on the
+ // services.
+ //
+ String bundleName = properties.getProperty("IceBox.PrintServicesReady");
+ if(bundleName.length() > 0)
+ {
+ System.out.println(bundleName + " ready");
+ }
//
// Don't move after the adapter activation. This allows
@@ -126,11 +126,11 @@ public class ServiceManagerI extends _ServiceManagerDisp
// reachable before sending a signal to shutdown the
// IceBox.
//
- _server.shutdownOnInterrupt();
+ _server.shutdownOnInterrupt();
- //
- // Start request dispatching after we've started the services.
- //
+ //
+ // Start request dispatching after we've started the services.
+ //
try
{
adapter.activate();
@@ -142,71 +142,71 @@ public class ServiceManagerI extends _ServiceManagerDisp
//
}
- _server.communicator().waitForShutdown();
+ _server.communicator().waitForShutdown();
_server.defaultInterrupt();
- //
- // Invoke stop() on the services.
- //
- stopAll();
- }
- catch(FailureException ex)
- {
- java.io.StringWriter sw = new java.io.StringWriter();
- java.io.PrintWriter pw = new java.io.PrintWriter(sw);
- pw.println(ex.reason);
- ex.printStackTrace(pw);
- pw.flush();
- _logger.error(sw.toString());
- stopAll();
- return 1;
- }
- catch(Ice.LocalException ex)
- {
- java.io.StringWriter sw = new java.io.StringWriter();
- java.io.PrintWriter pw = new java.io.PrintWriter(sw);
- ex.printStackTrace(pw);
- pw.flush();
- _logger.error("ServiceManager: " + ex + "\n" + sw.toString());
- stopAll();
- return 1;
- }
- catch(java.lang.Exception ex)
- {
- java.io.StringWriter sw = new java.io.StringWriter();
- java.io.PrintWriter pw = new java.io.PrintWriter(sw);
- ex.printStackTrace(pw);
- pw.flush();
- _logger.error("ServiceManager: unknown exception\n" + sw.toString());
- stopAll();
- return 1;
- }
-
- return 0;
+ //
+ // Invoke stop() on the services.
+ //
+ stopAll();
+ }
+ catch(FailureException ex)
+ {
+ java.io.StringWriter sw = new java.io.StringWriter();
+ java.io.PrintWriter pw = new java.io.PrintWriter(sw);
+ pw.println(ex.reason);
+ ex.printStackTrace(pw);
+ pw.flush();
+ _logger.error(sw.toString());
+ stopAll();
+ return 1;
+ }
+ catch(Ice.LocalException ex)
+ {
+ java.io.StringWriter sw = new java.io.StringWriter();
+ java.io.PrintWriter pw = new java.io.PrintWriter(sw);
+ ex.printStackTrace(pw);
+ pw.flush();
+ _logger.error("ServiceManager: " + ex + "\n" + sw.toString());
+ stopAll();
+ return 1;
+ }
+ catch(java.lang.Exception ex)
+ {
+ java.io.StringWriter sw = new java.io.StringWriter();
+ java.io.PrintWriter pw = new java.io.PrintWriter(sw);
+ ex.printStackTrace(pw);
+ pw.flush();
+ _logger.error("ServiceManager: unknown exception\n" + sw.toString());
+ stopAll();
+ return 1;
+ }
+
+ return 0;
}
private void
load(String name, String value)
throws FailureException
{
- //
- // Separate the entry point from the arguments.
- //
- String className;
- String[] args;
- int pos = IceUtil.StringUtil.findFirstOf(value, " \t\n");
- if(pos == -1)
- {
- className = value;
- args = new String[0];
- }
- else
- {
- className = value.substring(0, pos);
- args = value.substring(pos).trim().split("[ \t\n]+", pos);
- }
-
- start(name, className, args);
+ //
+ // Separate the entry point from the arguments.
+ //
+ String className;
+ String[] args;
+ int pos = IceUtil.StringUtil.findFirstOf(value, " \t\n");
+ if(pos == -1)
+ {
+ className = value;
+ args = new String[0];
+ }
+ else
+ {
+ className = value.substring(0, pos);
+ args = value.substring(pos).trim().split("[ \t\n]+", pos);
+ }
+
+ start(name, className, args);
}
private void
@@ -220,68 +220,68 @@ public class ServiceManagerI extends _ServiceManagerDisp
// shared communicator, depending on the value of the
// IceBox.UseSharedCommunicator property.
//
- java.util.ArrayList l = new java.util.ArrayList();
- for(int j = 0; j < args.length; j++)
- {
- l.add(args[j]);
- }
- for(int j = 0; j < _argv.length; j++)
- {
- if(_argv[j].startsWith("--" + service + "."))
- {
- l.add(_argv[j]);
- }
- }
+ java.util.ArrayList l = new java.util.ArrayList();
+ for(int j = 0; j < args.length; j++)
+ {
+ l.add(args[j]);
+ }
+ for(int j = 0; j < _argv.length; j++)
+ {
+ if(_argv[j].startsWith("--" + service + "."))
+ {
+ l.add(_argv[j]);
+ }
+ }
String[] serviceArgs = new String[l.size()];
- l.toArray(serviceArgs);
+ l.toArray(serviceArgs);
- //
- // Instantiate the class.
- //
+ //
+ // Instantiate the class.
+ //
ServiceInfo info = new ServiceInfo();
- try
- {
- Class c = Class.forName(className);
- java.lang.Object obj = c.newInstance();
- try
- {
- info.service = (Service)obj;
- }
- catch(ClassCastException ex)
- {
- FailureException e = new FailureException();
- e.reason = "ServiceManager: class " + className + " does not implement IceBox.Service";
- throw e;
- }
- }
- catch(ClassNotFoundException ex)
- {
- FailureException e = new FailureException();
- e.reason = "ServiceManager: class " + className + " not found";
- e.initCause(ex);
- throw e;
- }
- catch(IllegalAccessException ex)
- {
- FailureException e = new FailureException();
- e.reason = "ServiceManager: unable to access default constructor in class " + className;
- e.initCause(ex);
- throw e;
- }
- catch(InstantiationException ex)
- {
- FailureException e = new FailureException();
- e.reason = "ServiceManager: unable to instantiate class " + className;
- e.initCause(ex);
- throw e;
- }
-
- //
- // Invoke Service::start().
- //
- try
- {
+ try
+ {
+ Class c = Class.forName(className);
+ java.lang.Object obj = c.newInstance();
+ try
+ {
+ info.service = (Service)obj;
+ }
+ catch(ClassCastException ex)
+ {
+ FailureException e = new FailureException();
+ e.reason = "ServiceManager: class " + className + " does not implement IceBox.Service";
+ throw e;
+ }
+ }
+ catch(ClassNotFoundException ex)
+ {
+ FailureException e = new FailureException();
+ e.reason = "ServiceManager: class " + className + " not found";
+ e.initCause(ex);
+ throw e;
+ }
+ catch(IllegalAccessException ex)
+ {
+ FailureException e = new FailureException();
+ e.reason = "ServiceManager: unable to access default constructor in class " + className;
+ e.initCause(ex);
+ throw e;
+ }
+ catch(InstantiationException ex)
+ {
+ FailureException e = new FailureException();
+ e.reason = "ServiceManager: unable to instantiate class " + className;
+ e.initCause(ex);
+ throw e;
+ }
+
+ //
+ // Invoke Service::start().
+ //
+ try
+ {
//
// If Ice.UseSharedCommunicator.<name> is defined, create a
// communicator for the service. The communicator inherits
@@ -302,9 +302,9 @@ public class ServiceManagerI extends _ServiceManagerDisp
{
Ice.Properties serviceProperties = properties._clone();
- //
- // Initialize the Ice.ProgramName property with the name of this service.
- //
+ //
+ // Initialize the Ice.ProgramName property with the name of this service.
+ //
String name = serviceProperties.getProperty("Ice.ProgramName");
if(!name.equals(service))
{
@@ -325,19 +325,29 @@ public class ServiceManagerI extends _ServiceManagerDisp
info.service.start(service, communicator, serviceArgs);
- _services.put(service, info);
- }
- catch(FailureException ex)
- {
- throw ex;
- }
- catch(java.lang.Exception ex)
- {
- FailureException e = new FailureException();
- e.reason = "ServiceManager: exception while starting service " + service + ": " + ex;
- e.initCause(ex);
- throw e;
- }
+ _services.put(service, info);
+ }
+ catch(FailureException ex)
+ {
+ if(info.communicator != null)
+ {
+ destroyCommunicator(service, info.communicator);
+ }
+
+ throw ex;
+ }
+ catch(java.lang.Exception ex)
+ {
+ if(info.communicator != null)
+ {
+ destroyCommunicator(service, info.communicator);
+ }
+
+ FailureException e = new FailureException();
+ e.reason = "ServiceManager: exception while starting service " + service + ": " + ex;
+ e.initCause(ex);
+ throw e;
+ }
}
private void
@@ -359,75 +369,86 @@ public class ServiceManagerI extends _ServiceManagerDisp
}
catch(java.lang.Exception e)
{
- java.io.StringWriter sw = new java.io.StringWriter();
- java.io.PrintWriter pw = new java.io.PrintWriter(sw);
- e.printStackTrace(pw);
- pw.flush();
- _logger.warning("ServiceManager: exception in stop for service " + name + "\n" + sw.toString());
+ java.io.StringWriter sw = new java.io.StringWriter();
+ java.io.PrintWriter pw = new java.io.PrintWriter(sw);
+ e.printStackTrace(pw);
+ pw.flush();
+ _logger.warning("ServiceManager: exception in stop for service " + name + "\n" + sw.toString());
+ }
+
+ if(info.communicator != null)
+ {
+ destroyCommunicator(name, info.communicator);
}
}
- //
- // Finally, for each service, we shutdown and wait for the service communicator to be shutdown,
- // close the service database environment (must be done after waitForShutdown returns and before
- // destroy) and destroy the service communicator.
- //
- p = _services.entrySet().iterator();
- while(p.hasNext())
- {
- java.util.Map.Entry entry = (java.util.Map.Entry)p.next();
- String name = (String)entry.getKey();
- ServiceInfo info = (ServiceInfo)entry.getValue();
+/*
+//
+// Finally, for each service, we shutdown and wait for the
+// service communicator to be shutdown, and destroy the
+// service communicator.
+//
+p = _services.entrySet().iterator();
+while(p.hasNext())
+{
+java.util.Map.Entry entry = (java.util.Map.Entry)p.next();
+String name = (String)entry.getKey();
+ServiceInfo info = (ServiceInfo)entry.getValue();
- if(info.communicator != null)
+}
+*/
+
+ _services.clear();
+ }
+
+ private void
+ destroyCommunicator(String name, Ice.Communicator communicator)
+ {
+ if(communicator != null)
+ {
+ try
{
- try
- {
- info.communicator.shutdown();
- info.communicator.waitForShutdown();
- }
- catch(Ice.CommunicatorDestroyedException e)
- {
- //
- // Ignore, the service might have already destroyed
- // the communicator for its own reasons.
- //
- }
- catch(java.lang.Exception e)
- {
- java.io.StringWriter sw = new java.io.StringWriter();
- java.io.PrintWriter pw = new java.io.PrintWriter(sw);
- e.printStackTrace(pw);
- pw.flush();
- _logger.warning("ServiceManager: exception in stop for service " + name + "\n" + sw.toString());
- }
+ communicator.shutdown();
+ communicator.waitForShutdown();
+ }
+ catch(Ice.CommunicatorDestroyedException e)
+ {
+ //
+ // Ignore, the service might have already destroyed
+ // the communicator for its own reasons.
+ //
}
+ catch(java.lang.Exception e)
+ {
+ java.io.StringWriter sw = new java.io.StringWriter();
+ java.io.PrintWriter pw = new java.io.PrintWriter(sw);
+ e.printStackTrace(pw);
+ pw.flush();
+ _logger.warning("ServiceManager: exception in stop for service " + name + "\n" + sw.toString());
+ }
+ }
- if(info.communicator != null)
+ if(communicator != null)
+ {
+ try
{
- try
- {
- info.communicator.destroy();
- }
- catch(java.lang.Exception e)
- {
- java.io.StringWriter sw = new java.io.StringWriter();
- java.io.PrintWriter pw = new java.io.PrintWriter(sw);
- e.printStackTrace(pw);
- pw.flush();
- _logger.warning("ServiceManager: exception in stop for service " + name + "\n" + sw.toString());
- }
+ communicator.destroy();
+ }
+ catch(java.lang.Exception e)
+ {
+ java.io.StringWriter sw = new java.io.StringWriter();
+ java.io.PrintWriter pw = new java.io.PrintWriter(sw);
+ e.printStackTrace(pw);
+ pw.flush();
+ _logger.warning("ServiceManager: exception in stop for service " + name + "\n" + sw.toString());
}
}
-
- _services.clear();
}
class ServiceInfo
{
public Service service;
public Ice.Communicator communicator = null;
- String envName;
}
private Ice.Application _server;