diff --git a/cpp/include/Ice/Communicator.h b/cpp/include/Ice/Communicator.h index af9103b6f06..9b181cc66dd 100644 --- a/cpp/include/Ice/Communicator.h +++ b/cpp/include/Ice/Communicator.h @@ -45,12 +45,8 @@ namespace Ice void destroy() noexcept; /** - * Shuts down this communicator's server functionality, which includes the deactivation of all object adapters. - * Attempts to use a deactivated object adapter raise ObjectAdapterDeactivatedException. Subsequent calls to - * shutdown are ignored. - * After shutdown returns, no new requests are processed. However, requests that have been started before - * shutdown was called might still be active. You can use {@link #waitForShutdown} to wait for the completion of - * all requests. + * Shuts down this communicator: call deactivate on all object adapters created by this communicator. Shutting + * down a communicator has no effect on outgoing connections. * @see #destroy * @see #waitForShutdown * @see ObjectAdapter#deactivate diff --git a/java/src/Ice/src/main/java/com/zeroc/Ice/CollocatedRequestHandler.java b/java/src/Ice/src/main/java/com/zeroc/Ice/CollocatedRequestHandler.java index 3864a425bcc..1786ba518c6 100644 --- a/java/src/Ice/src/main/java/com/zeroc/Ice/CollocatedRequestHandler.java +++ b/java/src/Ice/src/main/java/com/zeroc/Ice/CollocatedRequestHandler.java @@ -185,7 +185,7 @@ private void dispatchAll(OutputStream os, int requestId, int requestCount) { // try { _adapter.incDirectCount(); - } catch (ObjectAdapterDeactivatedException ex) { + } catch (ObjectAdapterDestroyedException ex) { handleException(ex, requestId, false); break; } diff --git a/java/src/Ice/src/main/java/com/zeroc/Ice/Communicator.java b/java/src/Ice/src/main/java/com/zeroc/Ice/Communicator.java index 50db9f55d88..3913b8ce681 100644 --- a/java/src/Ice/src/main/java/com/zeroc/Ice/Communicator.java +++ b/java/src/Ice/src/main/java/com/zeroc/Ice/Communicator.java @@ -42,12 +42,9 @@ public void destroy() { } /** - * Shuts down this communicator's server functionality, which includes the deactivation of all - * object adapters. Attempts to use a deactivated object adapter raise - * ObjectAdapterDeactivatedException. Subsequent calls to shutdown are ignored. After shutdown - * returns, no new requests are processed. However, requests that have been started before - * shutdown was called might still be active. You can use {@link #waitForShutdown} to wait for - * the completion of all requests. + * Shuts down this communicator: call {@link ObjectAdapter#deactivate} on all object adapters + * created by this communicator. Shutting down a communicator has no effect on outgoing + * connections. * * @see #destroy * @see #waitForShutdown @@ -286,6 +283,30 @@ public ObjectAdapter createObjectAdapterWithRouter(String name, RouterPrx router return _instance.objectAdapterFactory().createObjectAdapter(name, router, null); } + /** + * Gets the object adapter that is associated by default with new outgoing connections created + * by this communicator. This method returns null unless you set a non-null default object + * adapter using {@link setDefaultObjectAdapter}. + * + * @return The object adapter associated by default with new outgoing connections. + * @see Connection#getAdapter + */ + public ObjectAdapter getDefaultObjectAdapter() { + return _instance.outgoingConnectionFactory().getDefaultObjectAdapter(); + } + + /** + * Sets the object adapter that will be associated with new outgoing connections created by this + * communicator. This method has no effect on existing outgoing connections, or on incoming + * connections. + * + * @param adapter The object adapter to associate with new outgoing connections. + * @see Connection#setAdapter + */ + public void setDefaultObjectAdapter(ObjectAdapter adapter) { + _instance.outgoingConnectionFactory().setDefaultObjectAdapter(adapter); + } + /** * Get the implicit context associated with this communicator. * diff --git a/java/src/Ice/src/main/java/com/zeroc/Ice/Connection.java b/java/src/Ice/src/main/java/com/zeroc/Ice/Connection.java index 127779308d1..cb2ee3435b2 100644 --- a/java/src/Ice/src/main/java/com/zeroc/Ice/Connection.java +++ b/java/src/Ice/src/main/java/com/zeroc/Ice/Connection.java @@ -1,17 +1,4 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// -// -// Ice version 3.7.10 -// -// -// -// Generated from file `Connection.ice' -// -// Warning: do not edit this file. -// -// -// +// Copyright (c) ZeroC, Inc. package com.zeroc.Ice; @@ -40,27 +27,26 @@ public interface Connection { ObjectPrx createProxy(Identity id); /** - * Explicitly set an object adapter that dispatches requests that are received over this - * connection. A client can invoke an operation on a server using a proxy, and then set an - * object adapter for the outgoing connection that is used by the proxy in order to receive - * callbacks. This is useful if the server cannot establish a connection back to the client, for - * example because of firewalls. + * Associates an object adapter with this connection. When a connection receives a request, it + * dispatches this request using its associated object adapter. If the associated object adapter + * is null, the connection rejects any incoming request with an {@link ObjectNotExistException}. + * The default object adapter of an incoming connection is the object adapter that created this + * connection; the default object adapter of an outgoing connection is the communicator's + * default object adapter. * - * @param adapter The object adapter that should be used by this connection to dispatch - * requests. The object adapter must be activated. When the object adapter is deactivated, - * it is automatically removed from the connection. Attempts to use a deactivated object - * adapter raise {@link ObjectAdapterDeactivatedException} + * @param adapter The object adapter to associate with the connection. * @see #createProxy * @see #getAdapter + * @see Communicator#setDefaultObjectAdapter */ void setAdapter(ObjectAdapter adapter); /** - * Get the object adapter that dispatches requests for this connection. + * Gets the object adapter associated with this connection. * - * @return The object adapter that dispatches requests for the connection, or null if no adapter - * is set. + * @return The object adapter associated with this connection. * @see #setAdapter + * @see Communicator#getDefaultObjectAdapter */ ObjectAdapter getAdapter(); diff --git a/java/src/Ice/src/main/java/com/zeroc/Ice/ConnectionI.java b/java/src/Ice/src/main/java/com/zeroc/Ice/ConnectionI.java index a1026279822..3c1fd7db3b7 100644 --- a/java/src/Ice/src/main/java/com/zeroc/Ice/ConnectionI.java +++ b/java/src/Ice/src/main/java/com/zeroc/Ice/ConnectionI.java @@ -11,7 +11,7 @@ import java.util.function.Consumer; /** - * @hidden Public because it's used by the 'Ice\metrics' test. + * @hidden Public because it's used by the 'Ice/metrics' test. */ public final class ConnectionI extends EventHandler implements Connection, CancellationHandler { public interface StartCallback { @@ -198,7 +198,8 @@ private synchronized void closeImpl() { if (!(_exception instanceof ConnectionClosedException || _exception instanceof CloseConnectionException || _exception instanceof CommunicatorDestroyedException - || _exception instanceof ObjectAdapterDeactivatedException)) { + || _exception instanceof ObjectAdapterDeactivatedException + || _exception instanceof ObjectAdapterDestroyedException)) { assert (_exception != null); throw _exception; } @@ -997,7 +998,8 @@ public void finish(boolean close) { || _exception instanceof ConnectionAbortedException || _exception instanceof ConnectionClosedException || _exception instanceof CommunicatorDestroyedException - || _exception instanceof ObjectAdapterDeactivatedException)) { + || _exception instanceof ObjectAdapterDeactivatedException + || _exception instanceof ObjectAdapterDestroyedException)) { s.append("\n"); s.append(_exception); } @@ -1269,7 +1271,7 @@ public synchronized void sendHeartbeat() { instance.initializationData().properties.getIcePropertyAsInt("Ice.Warn.Datagrams") > 0; _nextRequestId = 1; - _messageSizeMax = adapter != null ? adapter.messageSizeMax() : instance.messageSizeMax(); + _messageSizeMax = connector == null ? adapter.messageSizeMax() : instance.messageSizeMax(); _batchRequestQueue = new BatchRequestQueue(instance, _endpoint.datagram()); _readStream = new InputStream(instance, Protocol.currentProtocolEncoding); _readHeader = false; @@ -1372,6 +1374,7 @@ private void setState(int state, LocalException ex) { || _exception instanceof ConnectionClosedException || _exception instanceof CommunicatorDestroyedException || _exception instanceof ObjectAdapterDeactivatedException + || _exception instanceof ObjectAdapterDestroyedException || (_exception instanceof ConnectionLostException && _state >= StateClosing))) { warning("connection exception", _exception); @@ -1538,6 +1541,7 @@ private void setState(int state) { || _exception instanceof ConnectionClosedException || _exception instanceof CommunicatorDestroyedException || _exception instanceof ObjectAdapterDeactivatedException + || _exception instanceof ObjectAdapterDestroyedException || (_exception instanceof ConnectionLostException && _state >= StateClosing))) { _observer.failed(_exception.ice_id()); @@ -1640,7 +1644,7 @@ private boolean validate(int operation) { if (!_endpoint.datagram()) // Datagram connections are always implicitly // validated. { - if (_adapter != null) // The server side has the active role for + if (_connector == null) // The server side has the active role for // connection validation. { if (_writeStream.isEmpty()) { diff --git a/java/src/Ice/src/main/java/com/zeroc/Ice/ObjectAdapter.java b/java/src/Ice/src/main/java/com/zeroc/Ice/ObjectAdapter.java index 4a14594e92d..3d8720b9f22 100644 --- a/java/src/Ice/src/main/java/com/zeroc/Ice/ObjectAdapter.java +++ b/java/src/Ice/src/main/java/com/zeroc/Ice/ObjectAdapter.java @@ -201,18 +201,13 @@ public void waitForHold() { } /** - * Deactivate all endpoints that belong to this object adapter. After deactivation, the object - * adapter stops receiving requests through its endpoints. Object adapters that have been - * deactivated must not be reactivated again, and cannot be used otherwise. Attempts to use a - * deactivated object adapter raise {@link ObjectAdapterDeactivatedException} however, attempts - * to {@link #deactivate} an already deactivated object adapter are ignored and do nothing. Once - * deactivated, it is possible to destroy the adapter to clean up resources and then create and - * activate a new adapter with the same name. - * - *

After {@link #deactivate} returns, no new requests are processed by the - * object adapter. However, requests that have been started before {@link #deactivate} was - * called might still be active. You can use {@link #waitForDeactivate} to wait for the - * completion of all requests for this object adapter. + * Deactivates this object adapter: stop accepting new connections from clients and close + * gracefully all incoming connections created by this object adapter once all outstanding + * dispatches have completed. If this object adapter is indirect, this method also unregisters + * the object adapter from the Locator. This function does not cancel outstanding dispatches--it + * lets them execute until completion. A new incoming request on an existing connection will be + * accepted and can delay the closure of the connection. A deactivated object adapter cannot be + * reactivated again; it can only be destroyed. * * @see #activate * @see #hold @@ -246,18 +241,6 @@ public void deactivate() { // try { - if (_routerInfo != null) { - // - // Remove entry from the router manager. - // - _instance.routerManager().erase(_routerInfo.getRouter()); - - // - // Clear this object adapter with the router. - // - _routerInfo.setAdapter(null); - } - updateLocatorRegistry(_locatorInfo, null); } catch (LocalException ex) { // @@ -270,8 +253,6 @@ public void deactivate() { factory.destroy(); } - _instance.outgoingConnectionFactory().removeAdapter(this); - synchronized (this) { _state = StateDeactivated; notifyAll(); @@ -375,6 +356,16 @@ public void destroy() { _state = StateDestroying; } + if (_routerInfo != null) { + // Remove entry from the router manager. + _instance.routerManager().erase(_routerInfo.getRouter()); + + // Clear this object adapter with the router. + _routerInfo.setAdapter(null); + } + + _instance.outgoingConnectionFactory().removeAdapter(this); + // // Now it's also time to clean up our servants and servant // locators. @@ -470,7 +461,7 @@ public ObjectPrx add(Object servant, Identity identity) { * @see #findFacet */ public synchronized ObjectPrx addFacet(Object servant, Identity identity, String facet) { - checkForDeactivation(); + checkForDestruction(); checkIdentity(identity); if (servant == null) { throw new IllegalArgumentException("cannot add null servant to Object Adapter"); @@ -550,7 +541,7 @@ public ObjectPrx addFacetWithUUID(Object servant, String facet) { * @see #findDefaultServant */ public synchronized void addDefaultServant(Object servant, String category) { - checkForDeactivation(); + checkForDestruction(); if (servant == null) { throw new IllegalArgumentException("cannot add null servant to Object Adapter"); } @@ -586,7 +577,7 @@ public Object remove(Identity identity) { * @see #addFacetWithUUID */ public synchronized Object removeFacet(Identity identity, String facet) { - checkForDeactivation(); + checkForDestruction(); checkIdentity(identity); return _servantManager.removeServant(identity, facet); @@ -603,7 +594,7 @@ public synchronized Object removeFacet(Identity identity, String facet) { * @see #removeFacet */ public synchronized Map removeAllFacets(Identity identity) { - checkForDeactivation(); + checkForDestruction(); checkIdentity(identity); return _servantManager.removeAllFacets(identity); @@ -619,7 +610,7 @@ public synchronized Map removeAllFacets(Identity identity) { * @see #findDefaultServant */ public synchronized Object removeDefaultServant(String category) { - checkForDeactivation(); + checkForDestruction(); return _servantManager.removeDefaultServant(category); } @@ -655,7 +646,7 @@ public Object find(Identity identity) { * @see #findByProxy */ public synchronized Object findFacet(Identity identity, String facet) { - checkForDeactivation(); + checkForDestruction(); checkIdentity(identity); return _servantManager.findServant(identity, facet); @@ -671,7 +662,7 @@ public synchronized Object findFacet(Identity identity, String facet) { * @see #findFacet */ public synchronized java.util.Map findAllFacets(Identity identity) { - checkForDeactivation(); + checkForDestruction(); checkIdentity(identity); return _servantManager.findAllFacets(identity); @@ -689,7 +680,7 @@ public synchronized java.util.Map findAllFacets(Identity identit * @see #findFacet */ public synchronized Object findByProxy(ObjectPrx proxy) { - checkForDeactivation(); + checkForDestruction(); Reference ref = proxy._getReference(); return findFacet(ref.getIdentity(), ref.getFacet()); @@ -727,7 +718,7 @@ public synchronized Object findByProxy(ObjectPrx proxy) { * @see ServantLocator */ public synchronized void addServantLocator(ServantLocator locator, String category) { - checkForDeactivation(); + checkForDestruction(); _servantManager.addServantLocator(locator, category); } @@ -745,7 +736,7 @@ public synchronized void addServantLocator(ServantLocator locator, String catego * @see ServantLocator */ public synchronized ServantLocator removeServantLocator(String category) { - checkForDeactivation(); + checkForDestruction(); return _servantManager.removeServantLocator(category); } @@ -762,7 +753,7 @@ public synchronized ServantLocator removeServantLocator(String category) { * @see ServantLocator */ public synchronized ServantLocator findServantLocator(String category) { - checkForDeactivation(); + checkForDestruction(); return _servantManager.findServantLocator(category); } @@ -776,7 +767,7 @@ public synchronized ServantLocator findServantLocator(String category) { * @see #removeDefaultServant */ public synchronized Object findDefaultServant(String category) { - checkForDeactivation(); + checkForDestruction(); return _servantManager.findDefaultServant(category); } @@ -808,7 +799,7 @@ public synchronized Object dispatchPipeline() { * @see Identity */ public synchronized ObjectPrx createProxy(Identity identity) { - checkForDeactivation(); + checkForDestruction(); checkIdentity(identity); return newProxy(identity, ""); @@ -823,7 +814,7 @@ public synchronized ObjectPrx createProxy(Identity identity) { * @see Identity */ public synchronized ObjectPrx createDirectProxy(Identity identity) { - checkForDeactivation(); + checkForDestruction(); checkIdentity(identity); return newDirectProxy(identity, ""); @@ -839,7 +830,7 @@ public synchronized ObjectPrx createDirectProxy(Identity identity) { * @see Identity */ public synchronized ObjectPrx createIndirectProxy(Identity identity) { - checkForDeactivation(); + checkForDestruction(); checkIdentity(identity); return newIndirectProxy(identity, "", _id); @@ -871,6 +862,7 @@ public synchronized void setLocator(LocatorPrx locator) { * @see #setLocator */ public synchronized LocatorPrx getLocator() { + checkForDeactivation(); if (_locatorInfo == null) { return null; } else { @@ -963,7 +955,7 @@ public boolean isLocal(Reference ref) { // Proxies which have at least one endpoint in common with the published endpoints // are considered local. synchronized (this) { - checkForDeactivation(); + checkForDestruction(); EndpointI[] endpoints = ref.getEndpoints(); return java.util.Arrays.stream(_publishedEndpoints) @@ -1004,7 +996,7 @@ public void updateThreadObservers() { } public synchronized void incDirectCount() { - checkForDeactivation(); + checkForDestruction(); assert (_directCount >= 0); ++_directCount; @@ -1038,7 +1030,7 @@ public ThreadPool getThreadPool() { } public synchronized void setAdapterOnConnection(com.zeroc.Ice.ConnectionI connection) { - checkForDeactivation(); + checkForDestruction(); connection.setAdapterFromAdapter(this); } @@ -1291,11 +1283,18 @@ private ObjectPrx newIndirectProxy(Identity ident, String facet, String id) { } private void checkForDeactivation() { + checkForDestruction(); if (_state >= StateDeactivating) { throw new ObjectAdapterDeactivatedException(getName()); } } + private void checkForDestruction() { + if (_state >= StateDestroying) { + throw new ObjectAdapterDestroyedException(getName()); + } + } + private static void checkIdentity(Identity ident) { if (ident.name == null || ident.name.isEmpty()) { throw new IllegalArgumentException( @@ -1523,8 +1522,8 @@ private void updateLocatorRegistry(LocatorInfo locatorInfo, ObjectPrx proxy) { } throw new ObjectAdapterIdInUseException(_id); - } catch (ObjectAdapterDeactivatedException e) { - // Expected if collocated call and OA is deactivated, ignore. + } catch (ObjectAdapterDestroyedException e) { + // Expected if collocated call and OA is destroyed, ignore. } catch (CommunicatorDestroyedException e) { // Ignore } catch (LocalException e) { diff --git a/java/src/Ice/src/main/java/com/zeroc/Ice/ObjectAdapterDestroyedException.java b/java/src/Ice/src/main/java/com/zeroc/Ice/ObjectAdapterDestroyedException.java new file mode 100644 index 00000000000..9221bb39d69 --- /dev/null +++ b/java/src/Ice/src/main/java/com/zeroc/Ice/ObjectAdapterDestroyedException.java @@ -0,0 +1,20 @@ +// Copyright (c) ZeroC, Inc. + +package com.zeroc.Ice; + +/** This exception is raised if an attempt is made to use a destroyed {@link ObjectAdapter}. */ +public final class ObjectAdapterDestroyedException extends LocalException { + public ObjectAdapterDestroyedException(String name) { + super("Object adapter '" + name + "' is destroyed."); + this.name = name; + } + + public String ice_id() { + return "::Ice::ObjectAdapterDestroyedException"; + } + + /** Name of the adapter. */ + public final String name; + + private static final long serialVersionUID = -1946575462194055987L; +} diff --git a/java/src/Ice/src/main/java/com/zeroc/Ice/ObjectAdapterFactory.java b/java/src/Ice/src/main/java/com/zeroc/Ice/ObjectAdapterFactory.java index 4b0eec59276..9ba5789a28c 100644 --- a/java/src/Ice/src/main/java/com/zeroc/Ice/ObjectAdapterFactory.java +++ b/java/src/Ice/src/main/java/com/zeroc/Ice/ObjectAdapterFactory.java @@ -179,7 +179,7 @@ public ObjectAdapter findObjectAdapter(Reference ref) { if (adapter.isLocal(ref)) { return adapter; } - } catch (ObjectAdapterDeactivatedException ex) { + } catch (ObjectAdapterDestroyedException ex) { // Ignore. } } diff --git a/java/src/Ice/src/main/java/com/zeroc/Ice/OutgoingConnectionFactory.java b/java/src/Ice/src/main/java/com/zeroc/Ice/OutgoingConnectionFactory.java index c709f3c4372..539408507f1 100644 --- a/java/src/Ice/src/main/java/com/zeroc/Ice/OutgoingConnectionFactory.java +++ b/java/src/Ice/src/main/java/com/zeroc/Ice/OutgoingConnectionFactory.java @@ -43,6 +43,7 @@ public synchronized void destroy() { _destroyed = true; _communicator = null; + _defaultObjectAdapter = null; notifyAll(); } @@ -292,6 +293,14 @@ private synchronized ConnectionI findConnectionByEndpoint( return null; } + synchronized void setDefaultObjectAdapter(ObjectAdapter adapter) { + _defaultObjectAdapter = adapter; + } + + synchronized ObjectAdapter getDefaultObjectAdapter() { + return _defaultObjectAdapter; + } + // // Must be called while synchronized. // @@ -423,7 +432,7 @@ private synchronized ConnectionI createConnection(Transceiver transceiver, Conne transceiver, ci.connector, ci.endpoint.compress(false).timeout(-1), - null, + _defaultObjectAdapter, this::removeConnection, _connectionOptions); } catch (LocalException ex) { @@ -888,6 +897,7 @@ private boolean connectionStartFailedImpl(LocalException ex) { private Communicator _communicator; private final Instance _instance; private final ConnectionOptions _connectionOptions; + private ObjectAdapter _defaultObjectAdapter; private boolean _destroyed; private MultiHashMap _connections = new MultiHashMap<>(); diff --git a/java/src/Ice/src/main/java/com/zeroc/Ice/ProxyOutgoingAsyncBase.java b/java/src/Ice/src/main/java/com/zeroc/Ice/ProxyOutgoingAsyncBase.java index 8ca63c0f9ce..1121f8da30d 100644 --- a/java/src/Ice/src/main/java/com/zeroc/Ice/ProxyOutgoingAsyncBase.java +++ b/java/src/Ice/src/main/java/com/zeroc/Ice/ProxyOutgoingAsyncBase.java @@ -407,9 +407,10 @@ private int checkRetryAfterException(LocalException ex) { throw ex; } - // Don't retry if the communicator is destroyed or object adapter is deactivated. + // Don't retry if the communicator is destroyed or object adapter is deactivated/destroyed if (ex instanceof CommunicatorDestroyedException - || ex instanceof ObjectAdapterDeactivatedException) { + || ex instanceof ObjectAdapterDeactivatedException + || ex instanceof ObjectAdapterDestroyedException) { throw ex; } diff --git a/java/src/Ice/src/main/java/com/zeroc/Ice/RouterManager.java b/java/src/Ice/src/main/java/com/zeroc/Ice/RouterManager.java index 25e22ee4cc4..2b9bcee691d 100644 --- a/java/src/Ice/src/main/java/com/zeroc/Ice/RouterManager.java +++ b/java/src/Ice/src/main/java/com/zeroc/Ice/RouterManager.java @@ -18,15 +18,15 @@ synchronized void destroy() { // Returns router info for a given router. Automatically creates // the router info if it doesn't exist yet. // - public RouterInfo get(RouterPrx rtr) { - if (rtr == null) { + public RouterInfo get(RouterPrx router) { + if (router == null) { return null; } // // The router cannot be routed. // - RouterPrx router = RouterPrx.uncheckedCast(rtr.ice_router(null)); + router = RouterPrx.uncheckedCast(router.ice_router(null)); synchronized (this) { RouterInfo info = _table.get(router); @@ -39,17 +39,9 @@ public RouterInfo get(RouterPrx rtr) { } } - public RouterInfo erase(RouterPrx rtr) { - RouterInfo info = null; - if (rtr != null) { - // The router cannot be routed. - RouterPrx router = RouterPrx.uncheckedCast(rtr.ice_router(null)); - - synchronized (this) { - info = _table.remove(router); - } - } - return info; + public synchronized void erase(RouterPrx router) { + assert router.ice_getRouter() == null; + _table.remove(router); } private java.util.HashMap _table = new java.util.HashMap<>(); diff --git a/java/src/Ice/src/main/java/com/zeroc/Ice/WSTransceiver.java b/java/src/Ice/src/main/java/com/zeroc/Ice/WSTransceiver.java index abdc7d11e50..f9bc26bf8fd 100644 --- a/java/src/Ice/src/main/java/com/zeroc/Ice/WSTransceiver.java +++ b/java/src/Ice/src/main/java/com/zeroc/Ice/WSTransceiver.java @@ -250,6 +250,7 @@ public int closing(boolean initiator, LocalException reason) { if (reason instanceof CloseConnectionException) { _closingReason = CLOSURE_NORMAL; } else if (reason instanceof ObjectAdapterDeactivatedException + || reason instanceof ObjectAdapterDestroyedException || reason instanceof CommunicatorDestroyedException) { _closingReason = CLOSURE_SHUTDOWN; } else if (reason instanceof ProtocolException) { diff --git a/java/src/IceBox/src/main/java/com/zeroc/IceBox/ServiceManagerI.java b/java/src/IceBox/src/main/java/com/zeroc/IceBox/ServiceManagerI.java index 4ccf79fe064..c79f95d3cb3 100644 --- a/java/src/IceBox/src/main/java/com/zeroc/IceBox/ServiceManagerI.java +++ b/java/src/IceBox/src/main/java/com/zeroc/IceBox/ServiceManagerI.java @@ -325,6 +325,8 @@ public int run() { // Expected if the communicator is shutdown by the shutdown hook } catch (com.zeroc.Ice.ObjectAdapterDeactivatedException ex) { // Expected if the communicator is shutdown by the shutdown hook + } catch (com.zeroc.Ice.ObjectAdapterDestroyedException ex) { + // Expected } catch (Throwable ex) { java.io.StringWriter sw = new java.io.StringWriter(); java.io.PrintWriter pw = new java.io.PrintWriter(sw); @@ -873,6 +875,8 @@ private void removeAdminFacets(String prefix) { // Ignored } catch (com.zeroc.Ice.ObjectAdapterDeactivatedException ex) { // Ignored + } catch (com.zeroc.Ice.ObjectAdapterDestroyedException ex) { + // Ignored } } diff --git a/java/src/IceLocatorDiscovery/src/main/java/com/zeroc/IceLocatorDiscovery/PluginI.java b/java/src/IceLocatorDiscovery/src/main/java/com/zeroc/IceLocatorDiscovery/PluginI.java index 040977bbd5a..66b7dd1304d 100644 --- a/java/src/IceLocatorDiscovery/src/main/java/com/zeroc/IceLocatorDiscovery/PluginI.java +++ b/java/src/IceLocatorDiscovery/src/main/java/com/zeroc/IceLocatorDiscovery/PluginI.java @@ -62,6 +62,8 @@ private void exception(com.zeroc.Ice.LocalException ex) { _future.completeExceptionally(new com.zeroc.Ice.ObjectNotExistException()); } catch (com.zeroc.Ice.ObjectAdapterDeactivatedException exc) { _future.completeExceptionally(new com.zeroc.Ice.ObjectNotExistException()); + } catch (com.zeroc.Ice.ObjectAdapterDestroyedException exc) { + _future.completeExceptionally(new com.zeroc.Ice.ObjectNotExistException()); } catch (com.zeroc.Ice.CommunicatorDestroyedException exc) { _future.completeExceptionally(new com.zeroc.Ice.ObjectNotExistException()); } catch (com.zeroc.Ice.LocalException exc) { diff --git a/java/test/src/main/java/test/Ice/adapterDeactivation/AllTests.java b/java/test/src/main/java/test/Ice/adapterDeactivation/AllTests.java index 5929b3f7017..b467b72a362 100644 --- a/java/test/src/main/java/test/Ice/adapterDeactivation/AllTests.java +++ b/java/test/src/main/java/test/Ice/adapterDeactivation/AllTests.java @@ -250,14 +250,36 @@ public static TestIntfPrx allTests(test.TestHelper helper) { if (obj.ice_getConnection() != null) { out.print("testing object adapter with bi-dir connection... "); out.flush(); - com.zeroc.Ice.ObjectAdapter adapter = communicator.createObjectAdapter(""); - obj.ice_getConnection().setAdapter(adapter); - obj.ice_getConnection().setAdapter(null); - adapter.deactivate(); + + test(communicator.getDefaultObjectAdapter() == null); + test(obj.ice_getCachedConnection().getAdapter() == null); + + ObjectAdapter adapter = communicator.createObjectAdapter(""); + + communicator.setDefaultObjectAdapter(adapter); + test(communicator.getDefaultObjectAdapter() == adapter); + + // create new connection + obj.ice_getCachedConnection().close(); + obj.ice_ping(); + + test(obj.ice_getCachedConnection().getAdapter() == adapter); + communicator.setDefaultObjectAdapter(null); + + // create new connection + obj.ice_getCachedConnection().close(); + obj.ice_ping(); + + test(obj.ice_getCachedConnection().getAdapter() == null); + obj.ice_getCachedConnection().setAdapter(adapter); + test(obj.ice_getCachedConnection().getAdapter() == adapter); + obj.ice_getCachedConnection().setAdapter(null); + + adapter.destroy(); try { obj.ice_getConnection().setAdapter(adapter); test(false); - } catch (com.zeroc.Ice.ObjectAdapterDeactivatedException ex) { + } catch (com.zeroc.Ice.ObjectAdapterDestroyedException ex) { } out.println("ok"); } @@ -272,6 +294,7 @@ public static TestIntfPrx allTests(test.TestHelper helper) { base.ice_identity(routerId).ice_connectionId("rc")); com.zeroc.Ice.ObjectAdapter adapter = communicator.createObjectAdapterWithRouter("", router); + test(adapter.getPublishedEndpoints().length == 1); test( adapter.getPublishedEndpoints()[0] @@ -283,6 +306,7 @@ public static TestIntfPrx allTests(test.TestHelper helper) { } catch (IllegalArgumentException ex) { // Expected. } + adapter.destroy(); try { @@ -293,7 +317,6 @@ public static TestIntfPrx allTests(test.TestHelper helper) { } catch (com.zeroc.Ice.OperationNotExistException ex) { // Expected: the "test" object doesn't implement Ice::Router! } - try { router = com.zeroc.Ice.RouterPrx.createProxy( @@ -302,7 +325,6 @@ public static TestIntfPrx allTests(test.TestHelper helper) { test(false); } catch (com.zeroc.Ice.ConnectFailedException ex) { } - try { router = com.zeroc.Ice.RouterPrx.createProxy( @@ -341,12 +363,19 @@ public static TestIntfPrx allTests(test.TestHelper helper) { out.print("testing whether server is gone... "); out.flush(); - try { - obj.ice_invocationTimeout(100).ice_ping(); // Use timeout to speed up testing on Windows - test(false); - } catch (com.zeroc.Ice.LocalException ex) { + if (obj.ice_getConnection() == null) { // collocated + obj.ice_ping(); // works fine out.println("ok"); out.flush(); + } else { + try { + obj.ice_invocationTimeout(100) + .ice_ping(); // Use timeout to speed up testing on Windows + test(false); + } catch (com.zeroc.Ice.LocalException ex) { + out.println("ok"); + out.flush(); + } } out.print("testing server idle time..."); diff --git a/java/test/src/main/java/test/Ice/binding/RemoteObjectAdapterI.java b/java/test/src/main/java/test/Ice/binding/RemoteObjectAdapterI.java index b9c65b45bd0..44778e3532a 100644 --- a/java/test/src/main/java/test/Ice/binding/RemoteObjectAdapterI.java +++ b/java/test/src/main/java/test/Ice/binding/RemoteObjectAdapterI.java @@ -23,10 +23,7 @@ public TestIntfPrx getTestIntf(com.zeroc.Ice.Current current) { @Override public void deactivate(com.zeroc.Ice.Current current) { - try { - _adapter.destroy(); - } catch (com.zeroc.Ice.ObjectAdapterDeactivatedException ex) { - } + _adapter.destroy(); } final com.zeroc.Ice.ObjectAdapter _adapter; diff --git a/java/test/src/main/java/test/Ice/hold/HoldI.java b/java/test/src/main/java/test/Ice/hold/HoldI.java index c484186da53..5c10042b8f2 100644 --- a/java/test/src/main/java/test/Ice/hold/HoldI.java +++ b/java/test/src/main/java/test/Ice/hold/HoldI.java @@ -51,12 +51,10 @@ public void run() { current.adapter.waitForHold(); current.adapter.activate(); - } catch (com.zeroc.Ice.ObjectAdapterDeactivatedException ex) { - // + } catch (com.zeroc.Ice.LocalException ex) { // This shouldn't occur. The test ensures all the - // waitForHold timers are - // finished before shutting down the communicator. - // + // waitForHold timers are finished before shutting down the + // communicator. test(false); } }