Skip to content

Commit

Permalink
Merge branch 'main' into 2798-fixed-property-names
Browse files Browse the repository at this point in the history
  • Loading branch information
externl authored Oct 14, 2024
2 parents 4790517 + ab69b4e commit 66dd217
Show file tree
Hide file tree
Showing 37 changed files with 342 additions and 303 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"Browsable",
"istr",
"ostr",
"unregisters",
"Upcall"
],
"gradle.nestedProjects": true,
Expand Down
1 change: 1 addition & 0 deletions cpp/test/Ice/inactivityTimeout/Test.ice
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module Test
{
interface TestIntf
{
["amd"]
void sleep(int ms);

void shutdown();
Expand Down
10 changes: 8 additions & 2 deletions cpp/test/Ice/inactivityTimeout/TestI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,15 @@
using namespace std;

void
TestIntfI::sleep(int32_t ms, const Ice::Current&)
TestIntfI::sleepAsync(int32_t ms, function<void()> response, function<void(exception_ptr)>, const Ice::Current&)
{
this_thread::sleep_for(chrono::milliseconds(ms));
_sleepFuture = std::async(
std::launch::async,
[ms, response]
{
this_thread::sleep_for(chrono::milliseconds(ms));
response();
});
}

void
Expand Down
10 changes: 9 additions & 1 deletion cpp/test/Ice/inactivityTimeout/TestI.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,16 @@
class TestIntfI final : public Test::TestIntf
{
public:
void sleep(std::int32_t, const Ice::Current&) final;
void sleepAsync(
std::int32_t ms,
std::function<void()> response,
std::function<void(std::exception_ptr)> exception,
const Ice::Current& current) final;

void shutdown(const Ice::Current&) final;

private:
// has a blocking destructor
std::future<void> _sleepFuture;
};
#endif
26 changes: 20 additions & 6 deletions csharp/src/Ice/Communicator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,8 @@ public sealed class Communicator : IDisposable
public void destroy() => instance.destroy();

/// <summary>
/// Shuts down this communicator's server functionality, which includes the deactivation of all object adapters.
/// Attempts to use a deactivated object adapter throws <see cref="ObjectAdapterDeactivatedException" />. Subsequent
/// calls to shutdown are ignored.
/// After shutdown returns, no new requests are processed. However, requests that started to be dispatched before
/// shutdown was called might still be active. You can use <see cref="waitForShutdown" /> to wait for the completion
/// of all dispatches.
/// Shuts down this communicator: call <see cref="ObjectAdapter.deactivate"/> on all object adapters created by
/// this communicator. Shutting down a communicator has no effect on outgoing connections.
/// </summary>
public void shutdown()
{
Expand Down Expand Up @@ -205,6 +201,24 @@ public ObjectAdapter createObjectAdapterWithRouter(string name, RouterPrx router
return instance.objectAdapterFactory().createObjectAdapter(name, router, serverAuthenticationOptions: null);
}

/// <summary>
/// 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
/// <see cref="setDefaultObjectAdapter" />.
/// </summary>
/// <returns>The object adapter associated by default with new outgoing connections.</returns>
/// <seealso cref="Connection.getAdapter" />
public ObjectAdapter? getDefaultObjectAdapter() => instance.outgoingConnectionFactory().getDefaultObjectAdapter();

/// <summary>
/// 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.
/// </summary>
/// <param name="adapter">The object adapter to associate with new outgoing connections.</param>
/// <seealso cref="Connection.setAdapter" />
public void setDefaultObjectAdapter(ObjectAdapter? adapter) =>
instance.outgoingConnectionFactory().setDefaultObjectAdapter(adapter);

/// <summary>
/// Gets the implicit context associated with this communicator.
/// </summary>
Expand Down
23 changes: 10 additions & 13 deletions csharp/src/Ice/Connection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,23 +107,20 @@ public interface Connection
ObjectPrx createProxy(Identity id);

/// <summary>
/// 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 <see cref="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 null.
/// </summary>
/// <param name="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 ObjectAdapterDeactivatedException.</param>
void setAdapter(ObjectAdapter adapter);
/// <param name="adapter">The object adapter to associate with this connection.</param>
void setAdapter(ObjectAdapter? adapter);

/// <summary>
/// Get the object adapter that dispatches requests for this connection.
/// Gets the object adapter associated with this connection.
/// </summary>
/// <returns>The object adapter that dispatches requests for the connection, or null if no adapter is set.
/// </returns>
ObjectAdapter getAdapter();
/// <returns>The object adapter associated with this connection.</returns>
ObjectAdapter? getAdapter();

/// <summary>
/// Get the endpoint from which the connection was created.
Expand Down
44 changes: 10 additions & 34 deletions csharp/src/Ice/ConnectionI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,34 +202,6 @@ internal bool isActiveOrHolding()
}
}

internal bool isFinished()
{
//
// We can use TryLock here, because as long as there are still
// threads operating in this connection object, connection
// destruction is considered as not yet finished.
//
if (!Monitor.TryEnter(_mutex))
{
return false;
}

try
{
if (_state != StateFinished || _upcallCount != 0)
{
return false;
}

Debug.Assert(_state == StateFinished);
return true;
}
finally
{
Monitor.Exit(_mutex);
}
}

public void throwException()
{
lock (_mutex)
Expand Down Expand Up @@ -1386,7 +1358,7 @@ public Ice.Internal.ThreadPool getThreadPool()
internal ConnectionI(
Instance instance,
Transceiver transceiver,
Connector connector,
Connector connector, // null for incoming connections, non-null for outgoing connections
EndpointI endpoint,
ObjectAdapter adapter,
Action<ConnectionI> removeFromFactory, // can be null
Expand All @@ -1410,7 +1382,7 @@ internal ConnectionI(
_warn = initData.properties.getIcePropertyAsInt("Ice.Warn.Connections") > 0;
_warnUdp = initData.properties.getIcePropertyAsInt("Ice.Warn.Datagrams") > 0;
_nextRequestId = 1;
_messageSizeMax = adapter is not null ? adapter.messageSizeMax() : instance.messageSizeMax();
_messageSizeMax = connector is null ? adapter.messageSizeMax() : instance.messageSizeMax();
_batchRequestQueue = new BatchRequestQueue(instance, _endpoint.datagram());
_readStream = new InputStream(instance, Util.currentProtocolEncoding);
_readHeader = false;
Expand Down Expand Up @@ -1443,12 +1415,16 @@ internal ConnectionI(

try
{
if (adapter is not null)
if (connector is null)
{
// adapter is always set for incoming connections
Debug.Assert(adapter is not null);
_threadPool = adapter.getThreadPool();
}
else
{
// we use the client thread pool for outgoing connections, even if there is an
// object adapter with its own thread pool.
_threadPool = instance.clientThreadPool();
}
_threadPool.initialize(this);
Expand Down Expand Up @@ -1860,7 +1836,7 @@ private bool validate(int operation)
{
if (!_endpoint.datagram()) // Datagram connections are always implicitly validated.
{
if (_adapter is not null) // The server side has the active role for connection validation.
if (_connector is null) // The server side has the active role for connection validation.
{
if (_writeStream.size() == 0)
{
Expand Down Expand Up @@ -2688,7 +2664,7 @@ private ConnectionInfo initConnectionInfo()
for (ConnectionInfo info = _info; info is not null; info = info.underlying)
{
info.connectionId = _endpoint.connectionId();
info.adapterName = _adapter is not null ? _adapter.getName() : "";
info.adapterName = _adapter?.getName() ?? "";
info.incoming = _connector is null;
}
return _info;
Expand Down Expand Up @@ -2909,7 +2885,7 @@ internal void completed(LocalException ex)

private string _desc;
private string _type;
private Connector _connector;
private readonly Connector _connector;
private EndpointI _endpoint;

private ObjectAdapter _adapter;
Expand Down
4 changes: 2 additions & 2 deletions csharp/src/Ice/Internal/CollocatedRequestHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ internal int invokeAsyncRequest(OutgoingAsyncBase outAsync, int batchRequestCoun
{
//
// Increase the direct count to prevent the thread pool from being destroyed before
// invokeAll is called. This will also throw if the object adapter has been deactivated.
// invokeAll is called. This will also throw if the object adapter has been destroyed.
//
_adapter.incDirectCount();

Expand Down Expand Up @@ -193,7 +193,7 @@ private void dispatchAll(Ice.OutputStream os, int requestId, int requestCount)
{
_adapter.incDirectCount();
}
catch (Ice.ObjectAdapterDeactivatedException ex)
catch (Ice.ObjectAdapterDestroyedException ex)
{
handleException(ex, requestId, amd: false);
break;
Expand Down
26 changes: 22 additions & 4 deletions csharp/src/Ice/Internal/ConnectionFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public void destroy()

_destroyed = true;
_communicator = null;
_defaultObjectAdapter = null;
System.Threading.Monitor.PulseAll(_mutex);
}
}
Expand Down Expand Up @@ -261,6 +262,22 @@ internal OutgoingConnectionFactory(Ice.Communicator communicator, Instance insta
_pendingConnectCount = 0;
}

internal void setDefaultObjectAdapter(ObjectAdapter adapter)
{
lock (_mutex)
{
_defaultObjectAdapter = adapter;
}
}

internal ObjectAdapter getDefaultObjectAdapter()
{
lock (_mutex)
{
return _defaultObjectAdapter;
}
}

private Ice.ConnectionI findConnection(List<EndpointI> endpoints, out bool compress)
{
lock (_mutex)
Expand Down Expand Up @@ -476,7 +493,7 @@ private Ice.ConnectionI createConnection(Transceiver transceiver, ConnectorInfo
transceiver,
ci.connector,
ci.endpoint.compress(false).timeout(-1),
adapter: null,
adapter: _defaultObjectAdapter,
removeConnection,
_connectionOptions);
}
Expand Down Expand Up @@ -644,8 +661,7 @@ private void handleConnectionException(Ice.LocalException ex, bool hasMore)
}
}

private bool
addToPending(ConnectCallback cb, List<ConnectorInfo> connectors)
private bool addToPending(ConnectCallback cb, List<ConnectorInfo> connectors)
{
//
// Add the callback to each connector pending list.
Expand Down Expand Up @@ -1051,6 +1067,8 @@ private bool connectionStartFailedImpl(Ice.LocalException ex)
private MultiDictionary<EndpointI, Ice.ConnectionI> _connectionsByEndpoint = new();
private Dictionary<Connector, HashSet<ConnectCallback>> _pending = new();
private int _pendingConnectCount;

private ObjectAdapter _defaultObjectAdapter;
private readonly object _mutex = new();
}

Expand Down Expand Up @@ -1411,7 +1429,7 @@ public override void message(ThreadPoolCurrent current)
connection = new Ice.ConnectionI(
_instance,
transceiver,
null,
connector: null,
_endpoint,
_adapter,
removeConnection,
Expand Down
14 changes: 4 additions & 10 deletions csharp/src/Ice/Internal/Instance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1127,12 +1127,9 @@ public void destroy()
_initData.observer.setObserverUpdater(null);
}

if (_initData.logger is LoggerAdminLogger loggerAdminLogger)
{
LoggerAdminLogger logger = _initData.logger as LoggerAdminLogger;
if (logger != null)
{
logger.destroy();
}
loggerAdminLogger.destroy();
}

//
Expand Down Expand Up @@ -1230,12 +1227,9 @@ public void destroy()
Monitor.PulseAll(_mutex);
}

if (_initData.logger is FileLoggerI fileLogger)
{
Ice.FileLoggerI logger = _initData.logger as Ice.FileLoggerI;
if (logger != null)
{
logger.destroy();
}
fileLogger.destroy();
}
}

Expand Down
7 changes: 3 additions & 4 deletions csharp/src/Ice/Internal/LoggerAdminLoggerI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Ice.Internal;

internal interface LoggerAdminLogger : Ice.Logger
internal interface LoggerAdminLogger : Logger
{
Ice.Object getFacet();

Expand Down Expand Up @@ -69,10 +69,9 @@ public void destroy()
Monitor.PulseAll(_mutex);
}

Ice.FileLoggerI fileLoger = _localLogger as Ice.FileLoggerI;
if (fileLoger != null)
if (_localLogger is FileLoggerI fileLogger)
{
fileLoger.destroy();
fileLogger.destroy();
}
}

Expand Down
2 changes: 1 addition & 1 deletion csharp/src/Ice/Internal/ObjectAdapterFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public Ice.ObjectAdapter findObjectAdapter(Reference reference)
return adapter;
}
}
catch (Ice.ObjectAdapterDeactivatedException)
catch (Ice.ObjectAdapterDestroyedException)
{
// Ignore.
}
Expand Down
1 change: 1 addition & 0 deletions csharp/src/Ice/Internal/OutgoingAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,7 @@ private int checkRetryAfterException(Ice.LocalException ex)
// or connection is closed by the application.
if (ex is CommunicatorDestroyedException ||
ex is ObjectAdapterDeactivatedException ||
ex is ObjectAdapterDestroyedException ||
(ex is ConnectionAbortedException connectionAbortedException &&
connectionAbortedException.closedByApplication) ||
(ex is ConnectionClosedException connectionClosedException &&
Expand Down
Loading

0 comments on commit 66dd217

Please sign in to comment.