Skip to content

Commit

Permalink
Add default object adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardnormier committed Oct 16, 2024
1 parent c7d1db6 commit 2212641
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 21 deletions.
27 changes: 25 additions & 2 deletions js/src/Ice/Communicator.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,34 @@ declare module "ice" {
*/
createObjectAdapterWithEndpoints(name: string, endpoints: string): Promise<Ice.ObjectAdapter>;

/**
* 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}.
*
* @returns The object adapter associated by default with new outgoing connections.
*
* @see {@link Connection#getAdapter}
* @see {@link setDefaultObjectAdapter}
*/
getDefaultObjectAdapter(): Ice.ObjectAdapter | null;

/**
* Sets the object adapter that is associated by default with new outgoing connections created by this
* communicator. This method has no effect on existing connections.
*
* @param adapter - The object adapter to associate by default with new outgoing connections.
*
* @see {@link Connection#setAdapter}
* @see {@link getDefaultObjectAdapter}
*/
setDefaultObjectAdapter(adapter: Ice.ObjectAdapter | null): void;

/**
* Creates a new object adapter with a router.
*
* This operation creates a routed object adapter. If the `name` parameter is an empty string, a UUID will be
* generated and used as the object adapter name.
* This operation creates a routed object adapter. If the `name` parameter is an empty string, a UUID will
* be generated and used as the object adapter name.
*
* @param name - The object adapter name.
* @param router - The router to associate with the object adapter.
Expand Down
8 changes: 8 additions & 0 deletions js/src/Ice/Communicator.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ export class Communicator {
return promise;
}

getDefaultObjectAdapter() {
this._instance.outgoingConnectionFactory().getDefaultObjectAdapter();
}

setDefaultObjectAdapter(adapter) {
this._instance.outgoingConnectionFactory().setDefaultObjectAdapter(adapter);
}

getValueFactoryManager() {
return this._instance.initializationData().valueFactoryManager;
}
Expand Down
4 changes: 2 additions & 2 deletions js/src/Ice/ConnectionI.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ function scheduleCloseTimeout(connection) {
}

export class ConnectionI {
constructor(communicator, instance, transceiver, endpoint, removeFromFactory, options) {
constructor(communicator, instance, transceiver, endpoint, adapter, removeFromFactory, options) {
this._communicator = communicator;
this._instance = instance;
this._desc = transceiver.toString();
this._type = transceiver.type();
this._endpoint = endpoint;
this._adapter = null;
this._adapter = adapter;
this._removeFromFactory = removeFromFactory;

this._connectTimeout = options.connectTimeout * 1000; // Seconds to milliseconds
Expand Down
9 changes: 9 additions & 0 deletions js/src/Ice/ObjectAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,16 @@ export class ObjectAdapter {
destroy() {
if (!this._isDestroyed) {
this._isDestroyed = true;

if (this._routerInfo !== null) {
// Remove entry from the router manager.
this._instance.routerManager().erase(this._routerInfo.getRouter());

// Clear this object adapter with the router.
this._routerInfo.setAdapter(null);
}
this._instance.outgoingConnectionFactory().removeAdapter(this);

this._servantManager.destroy();
this._objectAdapterFactory.removeObjectAdapter(this);
this._publishedEndpoints = [];
Expand Down
11 changes: 11 additions & 0 deletions js/src/Ice/OutgoingConnectionFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export class OutgoingConnectionFactory {
this._communicator = communicator;
this._instance = instance;
this._destroyed = false;
this._defaultObjectAdapter = null;
this._connectionOptions = instance.clientConnectionOptions;

this._connectionsByEndpoint = new ConnectionListMap(); // map<EndpointI, Array<Ice.ConnectionI>>
Expand All @@ -35,6 +36,7 @@ export class OutgoingConnectionFactory {

this._destroyed = true;
this._communicator = null;
this._defaultObjectAdapter = null;
this.checkFinished();
}

Expand Down Expand Up @@ -132,6 +134,14 @@ export class OutgoingConnectionFactory {
}
}

getDefaultObjectAdapter() {
return this._defaultObjectAdapter;
}

setDefaultObjectAdapter(adapter) {
this._defaultObjectAdapter = adapter;
}

findConnectionByEndpoint(endpoints) {
if (this._destroyed) {
throw new CommunicatorDestroyedException();
Expand Down Expand Up @@ -251,6 +261,7 @@ export class OutgoingConnectionFactory {
this._instance,
transceiver,
endpoint.changeCompress(false).changeTimeout(-1),
this._defaultObjectAdapter,
connection => this.removeConnection(connection),
this._connectionOptions,
);
Expand Down
22 changes: 7 additions & 15 deletions js/src/Ice/RouterManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Copyright (c) ZeroC, Inc. All rights reserved.
//

import { Debug } from "./Debug.js";
import { HashMap } from "./HashMap.js";
import { Ice as Ice_Router } from "./Router.js";
const { RouterPrx } = Ice_Router;
Expand All @@ -23,15 +24,13 @@ export class RouterManager {
// Returns router info for a given router. Automatically creates
// the router info if it doesn't exist yet.
//
find(rtr) {
if (rtr === null) {
find(router) {
if (router === null) {
return null;
}

//
// The router cannot be routed.
//
const router = RouterPrx.uncheckedCast(rtr.ice_router(null));
router = RouterPrx.uncheckedCast(router.ice_router(null));

let info = this._table.get(router);
if (info === undefined) {
Expand All @@ -42,15 +41,8 @@ export class RouterManager {
return info;
}

erase(rtr) {
let info = null;
if (rtr !== null) {
// The router cannot be routed.
const router = RouterPrx.uncheckedCast(rtr.ice_router(null));

info = this._table.get(router);
this._table.delete(router);
}
return info;
erase(router) {
Debug.assert(router.ice_getRouter() == null); // The router cannot be routed.
this._table.delete(router);
}
}
26 changes: 24 additions & 2 deletions js/test/Ice/adapterDeactivation/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,31 @@ export class Client extends TestHelper {
test(obj!.ice_getConnection() !== null);
{
out.write("testing object adapter with bi-dir connection... ");

test(communicator.getDefaultObjectAdapter() === null);
test(obj.ice_getCachedConnection().getAdapter() === null);

const adapter = await communicator.createObjectAdapter("");
(await obj!.ice_getConnection()).setAdapter(adapter);
(await obj!.ice_getConnection()).setAdapter(null);

communicator.setDefaultObjectAdapter(adapter);
test(communicator.getDefaultObjectAdapter() === adapter);

// create new connection
await obj.ice_getCachedConnection().close();
await obj.ice_ping();

test(obj.ice_getCachedConnection().getAdapter() === adapter);
communicator.setDefaultObjectAdapter(null);

// create new connection
await obj.ice_getCachedConnection().close();
await 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 {
(await obj!.ice_getConnection()).setAdapter(adapter);
Expand Down

0 comments on commit 2212641

Please sign in to comment.