Skip to content

Commit

Permalink
Update ObjectAdapter.deactivate in Java (#2901)
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardnormier authored Oct 16, 2024
1 parent 470bdab commit c7d1db6
Show file tree
Hide file tree
Showing 17 changed files with 188 additions and 128 deletions.
8 changes: 2 additions & 6 deletions cpp/include/Ice/Communicator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
33 changes: 27 additions & 6 deletions java/src/Ice/src/main/java/com/zeroc/Ice/Communicator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
*
Expand Down
38 changes: 12 additions & 26 deletions java/src/Ice/src/main/java/com/zeroc/Ice/Connection.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,4 @@
//
// Copyright (c) ZeroC, Inc. All rights reserved.
//
//
// Ice version 3.7.10
//
// <auto-generated>
//
// Generated from file `Connection.ice'
//
// Warning: do not edit this file.
//
// </auto-generated>
//
// Copyright (c) ZeroC, Inc.

package com.zeroc.Ice;

Expand Down Expand Up @@ -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();

Expand Down
14 changes: 9 additions & 5 deletions java/src/Ice/src/main/java/com/zeroc/Ice/ConnectionI.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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()) {
Expand Down
Loading

0 comments on commit c7d1db6

Please sign in to comment.