summaryrefslogtreecommitdiff
path: root/java/src
diff options
context:
space:
mode:
authorBenoit Foucher <benoit@zeroc.com>2002-08-09 14:47:51 +0000
committerBenoit Foucher <benoit@zeroc.com>2002-08-09 14:47:51 +0000
commit8774379a65a2f03c22bd57a9f601ca2d65921acf (patch)
treeed4e80924ed87bacc30e9140470735d5eee5ef78 /java/src
parentAdded new IcePack test suite, add IcePack tracing properties, added IcePack (diff)
downloadice-8774379a65a2f03c22bd57a9f601ca2d65921acf.tar.bz2
ice-8774379a65a2f03c22bd57a9f601ca2d65921acf.tar.xz
ice-8774379a65a2f03c22bd57a9f601ca2d65921acf.zip
Added Ice application shutdown hook. Fixed IceBox to use Ice Application.
Added new IcePack deployer test suite.
Diffstat (limited to 'java/src')
-rw-r--r--java/src/Freeze/Application.java5
-rw-r--r--java/src/Ice/Application.java34
-rw-r--r--java/src/Ice/ShutdownHook.java (renamed from java/src/Freeze/ShutdownHook.java)12
-rw-r--r--java/src/IceBox/Server.java77
-rw-r--r--java/src/IceBox/ServiceManagerI.java28
-rw-r--r--java/src/IceInternal/LocatorInfo.java1
6 files changed, 80 insertions, 77 deletions
diff --git a/java/src/Freeze/Application.java b/java/src/Freeze/Application.java
index 4fe8d19d855..0cdf012a751 100644
--- a/java/src/Freeze/Application.java
+++ b/java/src/Freeze/Application.java
@@ -24,13 +24,9 @@ public abstract class Application extends Ice.Application
int status;
DBEnvironment dbEnv = null;
- ShutdownHook hook = null;
-
try
{
dbEnv = Freeze.Util.initialize(communicator(), _dbEnvName);
- hook = new ShutdownHook(dbEnv);
- Runtime.getRuntime().addShutdownHook(hook);
status = runFreeze(args, dbEnv);
}
catch(DBException ex)
@@ -70,7 +66,6 @@ public abstract class Application extends Ice.Application
status = 1;
}
dbEnv = null;
- Runtime.getRuntime().removeShutdownHook(hook);
}
return status;
diff --git a/java/src/Ice/Application.java b/java/src/Ice/Application.java
index a39c250d589..6e57ccdf582 100644
--- a/java/src/Ice/Application.java
+++ b/java/src/Ice/Application.java
@@ -123,25 +123,49 @@ public abstract class Application
return _communicator;
}
- //
- // TODO: These need to be implemented.
- //
public static void
shutdownOnInterrupt()
{
+ //
+ // As soon as the shutdown hook ends all the threads are
+ // terminated. So the shutdown hook will join the current
+ // thread before to end.
+ //
+ _shutdownHook = new ShutdownHook(Thread.currentThread());
+ Runtime.getRuntime().addShutdownHook(_shutdownHook);
}
-
+
public static void
ignoreInterrupt()
{
+ try
+ {
+ Runtime.getRuntime().removeShutdownHook(_shutdownHook);
+ }
+ catch(java.lang.IllegalStateException ex)
+ {
+ //
+ // Expected if we are in the process of shutting down.
+ //
+ }
}
public static void
defaultInterrupt()
{
+ try
+ {
+ Runtime.getRuntime().removeShutdownHook(_shutdownHook);
+ }
+ catch(java.lang.IllegalStateException ex)
+ {
+ //
+ // Expected if we are in the process of shutting down.
+ //
+ }
}
-
private static String _appName;
private static Communicator _communicator;
+ private static Thread _shutdownHook;
}
diff --git a/java/src/Freeze/ShutdownHook.java b/java/src/Ice/ShutdownHook.java
index d9e50784e07..735dc17630c 100644
--- a/java/src/Freeze/ShutdownHook.java
+++ b/java/src/Ice/ShutdownHook.java
@@ -8,13 +8,13 @@
//
// **********************************************************************
-package Freeze;
+package Ice;
public class ShutdownHook extends Thread
{
- ShutdownHook(DBEnvironment env)
+ ShutdownHook(Thread threadToJoin)
{
- _env = env;
+ _threadToJoin = threadToJoin;
}
public void
@@ -22,7 +22,9 @@ public class ShutdownHook extends Thread
{
try
{
- _env.close();
+ Ice.Application.communicator().shutdown();
+
+ _threadToJoin.join();
}
catch(Exception ex)
{
@@ -30,5 +32,5 @@ public class ShutdownHook extends Thread
}
}
- private DBEnvironment _env;
+ Thread _threadToJoin;
}
diff --git a/java/src/IceBox/Server.java b/java/src/IceBox/Server.java
index 2262e3ef5a1..8e21e76fa59 100644
--- a/java/src/IceBox/Server.java
+++ b/java/src/IceBox/Server.java
@@ -10,7 +10,7 @@
package IceBox;
-public final class Server
+public final class Server extends Ice.Application
{
private static void
usage()
@@ -25,54 +25,33 @@ public final class Server
public static void
main(String[] args)
{
- Ice.Communicator communicator = null;
- int status = 0;
-
- try
- {
- Ice.StringSeqHolder argsH = new Ice.StringSeqHolder(args);
- communicator = Ice.Util.initialize(argsH);
-
- Ice.Properties properties = communicator.getProperties();
- argsH.value = properties.parseCommandLineOptions("IceBox", argsH.value);
-
- for(int i = 1; i < argsH.value.length; ++i)
- {
- if(argsH.value[i].equals("-h") || argsH.value[i].equals("--help"))
- {
- usage();
- System.exit(0);
- }
- else if(!argsH.value[i].startsWith("--"))
- {
- System.err.println("Server: unknown option `" + argsH.value[i] + "'");
- usage();
- System.exit(1);
- }
- }
-
- ServiceManagerI serviceManagerImpl = new ServiceManagerI(communicator, argsH.value);
- status = serviceManagerImpl.run();
- }
- catch(Ice.LocalException ex)
- {
- ex.printStackTrace();
- status = 1;
- }
-
- if(communicator != null)
- {
- try
- {
- communicator.destroy();
- }
- catch(Ice.LocalException ex)
- {
- ex.printStackTrace();
- status = 1;
- }
- }
+ Server server = new Server();
+ server.main("IceBox.Server", args);
+ }
- System.exit(status);
+ public int
+ run(String[] args)
+ {
+ Ice.Properties properties = communicator().getProperties();
+ Ice.StringSeqHolder argsH = new Ice.StringSeqHolder(args);
+ argsH.value = properties.parseCommandLineOptions("IceBox", argsH.value);
+
+ for(int i = 1; i < argsH.value.length; ++i)
+ {
+ if(argsH.value[i].equals("-h") || argsH.value[i].equals("--help"))
+ {
+ usage();
+ return 0;
+ }
+ else if(!argsH.value[i].startsWith("--"))
+ {
+ System.err.println("Server: unknown option `" + argsH.value[i] + "'");
+ usage();
+ return 1;
+ }
+ }
+
+ ServiceManagerI serviceManagerImpl = new ServiceManagerI(this, argsH.value);
+ return serviceManagerImpl.run();
}
}
diff --git a/java/src/IceBox/ServiceManagerI.java b/java/src/IceBox/ServiceManagerI.java
index 7c0f18bbd82..cfd5c6206ab 100644
--- a/java/src/IceBox/ServiceManagerI.java
+++ b/java/src/IceBox/ServiceManagerI.java
@@ -13,20 +13,20 @@ package IceBox;
public final class ServiceManagerI extends _ServiceManagerDisp
{
public
- ServiceManagerI(Ice.Communicator communicator, String[] args)
+ ServiceManagerI(Ice.Application server, String[] args)
{
- _communicator = communicator;
- _logger = _communicator.getLogger();
+ _server = server;
+ _logger = _server.communicator().getLogger();
_argv = args;
- Ice.Properties properties = _communicator.getProperties();
+ Ice.Properties properties = _server.communicator().getProperties();
_options = properties.getCommandLineOptions();
}
public void
shutdown(Ice.Current current)
{
- _communicator.shutdown();
+ _server.communicator().shutdown();
}
int
@@ -38,7 +38,7 @@ public final class ServiceManagerI extends _ServiceManagerDisp
// Prefix the adapter name and object identity with the value
// of the IceBox.Name property.
//
- Ice.Properties properties = _communicator.getProperties();
+ Ice.Properties properties = _server.communicator().getProperties();
String namePrefix = properties.getProperty("IceBox.Name");
if(namePrefix.length() > 0)
{
@@ -51,7 +51,7 @@ public final class ServiceManagerI extends _ServiceManagerDisp
// will most likely need to be firewalled for security reasons.
//
Ice.ObjectAdapter adapter =
- _communicator.createObjectAdapterFromProperty(namePrefix + "ServiceManagerAdapter",
+ _server.communicator().createObjectAdapterFromProperty(namePrefix + "ServiceManagerAdapter",
"IceBox.ServiceManager.Endpoints");
String identity = properties.getPropertyWithDefault("IceBox.ServiceManager.Identity",
@@ -125,7 +125,9 @@ public final class ServiceManagerI extends _ServiceManagerDisp
//
adapter.activate();
- _communicator.waitForShutdown();
+ _server.shutdownOnInterrupt();
+ _server.communicator().waitForShutdown();
+ _server.ignoreInterrupt();
//
// Invoke stop() on the services.
@@ -266,7 +268,7 @@ public final class ServiceManagerI extends _ServiceManagerDisp
//
Service s = (Service)info.service;
info.dbEnvName = null;
- s.start(service, _communicator, serviceProperties, serviceArgs.value);
+ s.start(service, _server.communicator(), serviceProperties, serviceArgs.value);
}
catch(ClassCastException e)
{
@@ -278,7 +280,7 @@ public final class ServiceManagerI extends _ServiceManagerDisp
//
FreezeService fs = (FreezeService)info.service;
- Ice.Properties properties = _communicator.getProperties();
+ Ice.Properties properties = _server.communicator().getProperties();
String propName = "IceBox.DBEnvName." + service;
info.dbEnvName = properties.getProperty(propName);
@@ -286,7 +288,7 @@ public final class ServiceManagerI extends _ServiceManagerDisp
if(dbInfo == null)
{
dbInfo = new DBEnvironmentInfo();
- dbInfo.dbEnv = Freeze.Util.initialize(_communicator, info.dbEnvName);
+ dbInfo.dbEnv = Freeze.Util.initialize(_server.communicator(), info.dbEnvName);
dbInfo.openCount = 1;
}
else
@@ -295,7 +297,7 @@ public final class ServiceManagerI extends _ServiceManagerDisp
}
_dbEnvs.put(info.dbEnvName, dbInfo);
- fs.start(service, _communicator, serviceProperties, serviceArgs.value, dbInfo.dbEnv);
+ fs.start(service, _server.communicator(), serviceProperties, serviceArgs.value, dbInfo.dbEnv);
}
_services.put(service, info);
}
@@ -404,7 +406,7 @@ public final class ServiceManagerI extends _ServiceManagerDisp
public int openCount;
}
- private Ice.Communicator _communicator;
+ private Ice.Application _server;
private Ice.Logger _logger;
private String[] _argv; // Filtered server argument vector
private String[] _options; // Server property set converted to command-line options
diff --git a/java/src/IceInternal/LocatorInfo.java b/java/src/IceInternal/LocatorInfo.java
index cac55ec4cfb..a9131848a06 100644
--- a/java/src/IceInternal/LocatorInfo.java
+++ b/java/src/IceInternal/LocatorInfo.java
@@ -21,6 +21,7 @@ public final class LocatorInfo
synchronized public void
destroy()
{
+ _locator = null;
_locatorRegistry = null;
_adapterTable.clear();
}