summaryrefslogtreecommitdiff
path: root/java/src
diff options
context:
space:
mode:
Diffstat (limited to 'java/src')
-rw-r--r--java/src/Ice/CommunicatorI.java42
-rw-r--r--java/src/Ice/ObjectAdapterI.java14
-rw-r--r--java/src/Ice/PluginManagerI.java43
-rw-r--r--java/src/IceInternal/Instance.java33
-rw-r--r--java/src/IceInternal/ObjectAdapterFactory.java6
5 files changed, 80 insertions, 58 deletions
diff --git a/java/src/Ice/CommunicatorI.java b/java/src/Ice/CommunicatorI.java
index e9eaffc97d2..cdcce594075 100644
--- a/java/src/Ice/CommunicatorI.java
+++ b/java/src/Ice/CommunicatorI.java
@@ -15,12 +15,14 @@ class CommunicatorI implements Communicator
public synchronized void
destroy()
{
- if(_instance != null)
+ if(!_destroyed) // Don't destroy twice.
{
- _serverThreadPool = null;
+ _destroyed = true;
+
_instance.objectAdapterFactory().shutdown();
_instance.destroy();
- _instance = null;
+
+ _serverThreadPool = null;
}
}
@@ -52,7 +54,7 @@ class CommunicatorI implements Communicator
public synchronized Ice.ObjectPrx
stringToProxy(String s)
{
- if(_instance == null)
+ if(_destroyed)
{
throw new CommunicatorDestroyedException();
}
@@ -62,7 +64,7 @@ class CommunicatorI implements Communicator
public synchronized String
proxyToString(Ice.ObjectPrx proxy)
{
- if(_instance == null)
+ if(_destroyed)
{
throw new CommunicatorDestroyedException();
}
@@ -72,7 +74,7 @@ class CommunicatorI implements Communicator
public synchronized ObjectAdapter
createObjectAdapter(String name)
{
- if(_instance == null)
+ if(_destroyed)
{
throw new CommunicatorDestroyedException();
}
@@ -97,7 +99,7 @@ class CommunicatorI implements Communicator
public synchronized ObjectAdapter
createObjectAdapterFromProperty(String name, String property)
{
- if(_instance == null)
+ if(_destroyed)
{
throw new CommunicatorDestroyedException();
}
@@ -110,7 +112,7 @@ class CommunicatorI implements Communicator
public synchronized ObjectAdapter
createObjectAdapterWithEndpoints(String name, String endpts)
{
- if(_instance == null)
+ if(_destroyed)
{
throw new CommunicatorDestroyedException();
}
@@ -133,7 +135,7 @@ class CommunicatorI implements Communicator
public synchronized void
addObjectFactory(ObjectFactory factory, String id)
{
- if(_instance == null)
+ if(_destroyed)
{
throw new CommunicatorDestroyedException();
}
@@ -143,7 +145,7 @@ class CommunicatorI implements Communicator
public synchronized void
removeObjectFactory(String id)
{
- if(_instance == null)
+ if(_destroyed)
{
throw new CommunicatorDestroyedException();
}
@@ -153,7 +155,7 @@ class CommunicatorI implements Communicator
public synchronized ObjectFactory
findObjectFactory(String id)
{
- if(_instance == null)
+ if(_destroyed)
{
throw new CommunicatorDestroyedException();
}
@@ -163,7 +165,7 @@ class CommunicatorI implements Communicator
public synchronized void
addUserExceptionFactory(UserExceptionFactory factory, String id)
{
- if(_instance == null)
+ if(_destroyed)
{
throw new CommunicatorDestroyedException();
}
@@ -173,7 +175,7 @@ class CommunicatorI implements Communicator
public synchronized void
removeUserExceptionFactory(String id)
{
- if(_instance == null)
+ if(_destroyed)
{
throw new CommunicatorDestroyedException();
}
@@ -183,7 +185,7 @@ class CommunicatorI implements Communicator
public synchronized UserExceptionFactory
findUserExceptionFactory(String id)
{
- if(_instance == null)
+ if(_destroyed)
{
throw new CommunicatorDestroyedException();
}
@@ -193,7 +195,7 @@ class CommunicatorI implements Communicator
public synchronized Properties
getProperties()
{
- if(_instance == null)
+ if(_destroyed)
{
throw new CommunicatorDestroyedException();
}
@@ -203,7 +205,7 @@ class CommunicatorI implements Communicator
public synchronized Logger
getLogger()
{
- if(_instance == null)
+ if(_destroyed)
{
throw new CommunicatorDestroyedException();
}
@@ -213,7 +215,7 @@ class CommunicatorI implements Communicator
public synchronized void
setLogger(Logger logger)
{
- if(_instance == null)
+ if(_destroyed)
{
throw new CommunicatorDestroyedException();
}
@@ -240,6 +242,7 @@ class CommunicatorI implements Communicator
CommunicatorI(StringSeqHolder args, Properties properties)
{
+ _destroyed = false;
_instance = new IceInternal.Instance(this, args, properties);
}
@@ -247,9 +250,9 @@ class CommunicatorI implements Communicator
finalize()
throws Throwable
{
- if(_instance != null)
+ if(!_destroyed)
{
- _instance.logger().warning("communicator has not been destroyed");
+ _instance.logger().warning("Ice::Communicator::destroy() has not been called");
}
super.finalize();
@@ -274,6 +277,7 @@ class CommunicatorI implements Communicator
return _instance;
}
+ private boolean _destroyed;
private IceInternal.Instance _instance;
//
diff --git a/java/src/Ice/ObjectAdapterI.java b/java/src/Ice/ObjectAdapterI.java
index 81bd1d060dc..e0d96a50572 100644
--- a/java/src/Ice/ObjectAdapterI.java
+++ b/java/src/Ice/ObjectAdapterI.java
@@ -18,10 +18,15 @@ public class ObjectAdapterI implements ObjectAdapter
return _name; // _name is immutable
}
- public Communicator
+ public synchronized Communicator
getCommunicator()
{
- return _instance.communicator(); // _instance is immutable
+ if(_instance == null)
+ {
+ throw new ObjectAdapterDeactivatedException();
+ }
+
+ return _communicator;
}
public synchronized void
@@ -126,6 +131,7 @@ public class ObjectAdapterI implements ObjectAdapter
_locatorMap.clear();
_instance = null;
+ _communicator = null;
}
public void
@@ -391,9 +397,10 @@ public class ObjectAdapterI implements ObjectAdapter
// Only for use by IceInternal.ObjectAdapterFactory
//
public
- ObjectAdapterI(IceInternal.Instance instance, String name, String endpts)
+ ObjectAdapterI(IceInternal.Instance instance, Communicator communicator, String name, String endpts)
{
_instance = instance;
+ _communicator = communicator;
_printAdapterReadyDone = false;
_name = name;
@@ -597,6 +604,7 @@ public class ObjectAdapterI implements ObjectAdapter
}
private IceInternal.Instance _instance;
+ private Communicator _communicator;
private boolean _printAdapterReadyDone;
private String _name;
private boolean _useEndpointsInProxy;
diff --git a/java/src/Ice/PluginManagerI.java b/java/src/Ice/PluginManagerI.java
index 72583dcbff2..d2584cc1e5e 100644
--- a/java/src/Ice/PluginManagerI.java
+++ b/java/src/Ice/PluginManagerI.java
@@ -15,6 +15,11 @@ public final class PluginManagerI implements PluginManager
public synchronized Plugin
getPlugin(String name)
{
+ if(_communicator == null)
+ {
+ throw new CommunicatorDestroyedException();
+ }
+
Plugin p = (Plugin)_plugins.get(name);
if(p != null)
{
@@ -26,6 +31,11 @@ public final class PluginManagerI implements PluginManager
public synchronized void
addPlugin(String name, Plugin plugin)
{
+ if(_communicator == null)
+ {
+ throw new CommunicatorDestroyedException();
+ }
+
if(_plugins.containsKey(name))
{
throw new PluginExistsException();
@@ -36,23 +46,30 @@ public final class PluginManagerI implements PluginManager
public synchronized void
destroy()
{
- java.util.Iterator i = _plugins.entrySet().iterator();
- while(i.hasNext())
- {
- Plugin p = (Plugin)i.next();
- p.destroy();
- }
+ if(_communicator != null)
+ {
+ java.util.Iterator i = _plugins.entrySet().iterator();
+ while(i.hasNext())
+ {
+ Plugin p = (Plugin)i.next();
+ p.destroy();
+ }
+
+ _communicator = null;
+ }
}
public
- PluginManagerI(IceInternal.Instance instance)
+ PluginManagerI(Communicator communicator)
{
- _instance = instance;
+ _communicator = communicator;
}
- public void
+ private void
loadPlugins(StringSeqHolder cmdArgs)
{
+ assert(_communicator != null);
+
//
// Load and initialize the plug-ins defined in the property set
// with the prefix "Ice.Plugin.". These properties should
@@ -61,7 +78,7 @@ public final class PluginManagerI implements PluginManager
// Ice.Plugin.name=entry_point [args]
//
final String prefix = "Ice.Plugin.";
- Ice.Properties properties = _instance.properties();
+ Ice.Properties properties = _communicator.getProperties();
java.util.Map plugins = properties.getPropertiesForPrefix(prefix);
java.util.Iterator p = plugins.entrySet().iterator();
while(p.hasNext())
@@ -110,6 +127,8 @@ public final class PluginManagerI implements PluginManager
private void
loadPlugin(String name, String className, String[] args)
{
+ assert(_communicator != null);
+
//
// Instantiate the class.
//
@@ -158,7 +177,7 @@ public final class PluginManagerI implements PluginManager
Plugin plugin = null;
try
{
- plugin = factory.create(_instance.communicator(), name, args);
+ plugin = factory.create(_communicator, name, args);
}
catch(Exception ex)
{
@@ -171,6 +190,6 @@ public final class PluginManagerI implements PluginManager
_plugins.put(name, plugin);
}
- private IceInternal.Instance _instance;
+ private Communicator _communicator;
private java.util.HashMap _plugins = new java.util.HashMap();
}
diff --git a/java/src/IceInternal/Instance.java b/java/src/IceInternal/Instance.java
index 58a8c697aa3..1e61d5e38f1 100644
--- a/java/src/IceInternal/Instance.java
+++ b/java/src/IceInternal/Instance.java
@@ -12,12 +12,6 @@ package IceInternal;
public class Instance
{
- public synchronized Ice.Communicator
- communicator()
- {
- return _communicator;
- }
-
public Ice.Properties
properties()
{
@@ -102,7 +96,7 @@ public class Instance
public synchronized ThreadPool
clientThreadPool()
{
- if(_communicator != null) // Not destroyed?
+ if(!_destroyed)
{
if(_clientThreadPool == null) // Lazy initialization.
{
@@ -116,7 +110,7 @@ public class Instance
public synchronized ThreadPool
serverThreadPool()
{
- if(_communicator != null) // Not destroyed?
+ if(!_destroyed)
{
if(_serverThreadPool == null) // Lazy initialization.
{
@@ -152,7 +146,7 @@ public class Instance
public
Instance(Ice.Communicator communicator, Ice.StringSeqHolder args, Ice.Properties properties)
{
- _communicator = communicator;
+ _destroyed = false;
_properties = properties;
//
@@ -182,7 +176,7 @@ public class Instance
EndpointFactory udpEndpointFactory = new UdpEndpointFactory(this);
_endpointFactoryManager.add(udpEndpointFactory);
- _pluginManager = new Ice.PluginManagerI(this);
+ _pluginManager = new Ice.PluginManagerI(communicator);
_outgoingConnectionFactory = new OutgoingConnectionFactory(this);
@@ -190,7 +184,7 @@ public class Instance
_userExceptionFactoryManager = new UserExceptionFactoryManager();
- _objectAdapterFactory = new ObjectAdapterFactory(this);
+ _objectAdapterFactory = new ObjectAdapterFactory(this, communicator);
_bufferManager = new BufferManager(); // Must be created before the ThreadPool
}
@@ -205,7 +199,7 @@ public class Instance
finalize()
throws Throwable
{
- assert(_communicator == null);
+ assert(_destroyed);
assert(_referenceFactory == null);
assert(_proxyFactory == null);
assert(_outgoingConnectionFactory == null);
@@ -266,17 +260,12 @@ public class Instance
synchronized(this)
{
- //
- // Destroy all contained objects. Then set all references to null,
- // to avoid cyclic object dependencies.
- //
-
- if(_communicator != null)
+ if(_destroyed)
{
- // Don't destroy the communicator -- the communicator destroys
- // this object, not the other way.
- _communicator = null;
+ return; // Don't destroy twice.
}
+
+ _destroyed = true;
if(_objectAdapterFactory != null)
{
@@ -370,7 +359,7 @@ public class Instance
}
}
- private Ice.Communicator _communicator;
+ private boolean _destroyed;
private Ice.Properties _properties; // Immutable, not reset by destroy().
private Ice.Logger _logger; // Not reset by destroy().
private TraceLevels _traceLevels; // Immutable, not reset by destroy().
diff --git a/java/src/IceInternal/ObjectAdapterFactory.java b/java/src/IceInternal/ObjectAdapterFactory.java
index 80b295fa7ea..4f9939a2669 100644
--- a/java/src/IceInternal/ObjectAdapterFactory.java
+++ b/java/src/IceInternal/ObjectAdapterFactory.java
@@ -34,7 +34,7 @@ public final class ObjectAdapterFactory
return adapter;
}
- adapter = new Ice.ObjectAdapterI(_instance, name, endpts);
+ adapter = new Ice.ObjectAdapterI(_instance, _communicator, name, endpts);
_adapters.put(name, adapter);
return adapter;
}
@@ -58,11 +58,13 @@ public final class ObjectAdapterFactory
//
// Only for use by Instance
//
- ObjectAdapterFactory(Instance instance)
+ ObjectAdapterFactory(Instance instance, Ice.Communicator communicator)
{
_instance = instance;
+ _communicator = communicator;
}
private Instance _instance;
+ private Ice.Communicator _communicator;
private java.util.HashMap _adapters = new java.util.HashMap();
}