Home Help Center

Question about objectAdapter

OrNotOrNot Member Bin.LiOrganization: GE HealthcareProject: Enterprise solution
hi,
In my scenario, one client have to connect to different servers dynamically and each connection is bidir.
Here is my codes:

/* The proxies to _server1 and server2 are dynamically * gotten .
*/

_objectAdapter1=_communicator.createObjectAdapter ("adapter1");
Ice.Identity ident;
ident.name ="OrNot";
ident.category = "";
_objectAdapter1.add(new CallbackI(), ident);
_objectAdapter1.activate();
_server1.ice_connection().setAdapter(_objectAdapter1);
_server1.setCallback(ident);




_objectAdapter2=_communicator.createObjectAdapter ("adapter2");
Ice.Identity ident;
ident.name ="OrNot";
ident.category = "";
_objectAdapter2.add(new CallbackI(), ident);
_objectAdapter2.activate();
_server2.ice_connection().setAdapter(_objectAdapter2);
_server2.setCallback(ident);


/*
* Later, all the stuffs are not needed any longer and
* should be released then.
*/
_server1.removeCallback(ident);
_server1.ice_connection().close(false);
_objectAdapter1.deactive();
_objectAdapter1.remove(ident);

_server2.removeCallback(ident);
_server2.ice_connection().close(false);
_objectAdapter2.deactive();
_objectAdapter2.remove(ident);



My question is:
1) Is it correct so far as to what I did? Any advice to imporve it?

2) Since I can not find a method like this:
_communicator.removeAdapter("adapter1");

does it mean that the objectAdapters will not be erased from the hashtable until the communicator is shutdowned?

If so, in my scenario, if will it result in that the items of the hashtable will be cumulated and may lead to the memory is exhausted one day because all my dynamical connections to the servers may be random ?
How do I release a objectAdapter which are useless any more?
Sorry,maybe I misunderstand something and my worries are not necessary but hope getting a clarify.


Thanks in advance.

OrNot

Comments

  • bernardbernard Jupiter, FLAdministrators, ZeroC Staff Bernard NormierOrganization: ZeroC, Inc.Project: Ice ZeroC Staff
    To cleanup an object adapter, you need to deactivate this adapter and "wait for deactivate" this adapter:

    e.g.:
    _adapter->deactivate();
    _adapter->waitForDeactivate();

    If you're also shutting down or destroying your communicator, you don't need to worry about these calls: _communicator->deactivate() deactivates all object adapters, _communicator->waitForShutdown() waits for the deactivation of all object adapters; _communicator->destroy() do all this as well if it wasn't done previously.

    Bernard
  • OrNotOrNot Member Bin.LiOrganization: GE HealthcareProject: Enterprise solution
    Thank you,Bernard.

    When an objectAdapter was created, the hashtable in the objectAdapterFactory will increase one item and keep this adapter :

    adapter = new Ice.ObjectAdapterI(_instance, _communicator, name);
    _adapters[name] = adapter;


    When I don't need this adapter any longer and release all the stuffs by deactiving and waitfordeactiving , how will the hashtable change? I mean, if the hashtable will automatically erase the item relative to that adapter?
    I noticed that in the method objectAdapterFactory.waitForShutdown() , there is a line :
    _adapters=null;

    If is this the only chance to erase an adapter?



    OrNOt
  • marcmarc FloridaAdministrators, ZeroC Staff Marc LaukienOrganization: ZeroC, Inc.Project: The Internet Communications Engine ZeroC Staff
    Adapters can be deactivated, but not removed from a communicator. Why do you create so many adapters in the first place? A more typical scenario is that your create only a few adapters (in most cases just one) and use these until you destroy your communicator.
  • OrNotOrNot Member Bin.LiOrganization: GE HealthcareProject: Enterprise solution
    hi,Marc,
    In my scenario, one client has to connect to different servers dynamically at the same time and each connection is bidir. I now have a new solution but not very sure , could you please clarify it for me?

    _objectAdapter=_communicator.createObjectAdapter ("adapter");
    Ice.Identity ident;
    ident.name ="OrNot";
    ident.category = "";
    _objectAdapter.add(new CallbackI(), ident);
    _objectAdapter.activate();
    _server1.ice_connection().setAdapter(_objectAdapter);
    _server1.setCallback(ident);


    Ice.Identity ident;
    ident.name ="OrNot";
    ident.category = "";
    _server2.ice_connection().setAdapter(_objectAdapter);
    _server2.setCallback(ident);


    Since the ICE run time is thread safe , then what I should do is to guarantee to the thread safe of the callbackI.

    Any help is appreciated.

    OrNot




    OrNot
  • marcmarc FloridaAdministrators, ZeroC Staff Marc LaukienOrganization: ZeroC, Inc.Project: The Internet Communications Engine ZeroC Staff
    The solution is correct. Just set the OA for each connection that is established from the client to a server. There is no need for more than one object adapter.

    You might want to increase the number of threads in the client-side thread pool, because callbacks that arrive over an outgoing connection are dispatched by the client-side thread pool, and not the server-side thread pool or per-OA thread pool. The default is just one thread.
  • OrNotOrNot Member Bin.LiOrganization: GE HealthcareProject: Enterprise solution
    Thank you ,Marc. ICE is really good.
    Last question:
    If I did not need a connection to one server, I just simply do : _server1.ice_connection().close(false);
    This will not affect other connections and the OA, will this?

    OrNot
  • marcmarc FloridaAdministrators, ZeroC Staff Marc LaukienOrganization: ZeroC, Inc.Project: The Internet Communications Engine ZeroC Staff
    This is correct.
Sign In or Register to comment.