[omniORB] Sequences and Java Client

David Riddoch djr@uk.research.att.com
Fri, 12 Feb 1999 09:23:16 +0000 (GMT)


Hi Armen,

To destroy an object in the BOA, you have to call BOA::_dispose() for that
particular object. So you have two choices:

 * call Factory::unload() for each echo object (as well as the EchoList
   object)

 * have the EchoList object hold on to the references to the Echo objects,
   and dispose of them in its destructor.

David


On Thu, 11 Feb 1999, Armen Yampolsky wrote:

> My apologies for rejuvinating an old thread, but I am having questions
> regarding the proper way to handle sequences of objects. My issues stem
> from the fact that my client is in Java (viz., Sun's ORB impl), so I can
> not call delete on the sequence from Java. Instead, I am resorting to
> using an unload(CORBA::Object *obj) method in my factory. I want this
> simple method to correctly release all resources associated with the
> object in the argument, including any objects which *it* may have
> instantiated and copied into a sequence.
> 
> I am attaching a fragment of code depicting what I am doing. I would
> love it if someone could clarify the situation for me. TIA!
> 
> 
> IDL:
> ==============
> interface Echo
> {
>     void setMessage(in string message);
>     string getMessage();
> };
> 
> interface EchoList
> {
>     typedef sequence<Echo> Echoseq;
>     Echoseq getEchos();
> };
> 
> interface Factory
> {
>     EchoList load();
>     void unload(CORBA::Object obj);
> };
> 
> 
> Server:
> =================
> Echoseq* EchoList_i::getEchos()
> {
>  CORBA::Long size = 3;
>  Echoseq* seq = new Echoseq();  //instantiate sequence on the heap
> 
>  static char *value_list[] =
>  {
>   "Hello",
>   "Hi There",
>   "Hi Again"
>  };
> 
>  seq->length(size);
> 
>  for (int i = 0; i < size; i++)
>  {
>   Echo_i *echo = new Echo_i();
>   echo->_obj_is_ready(_boa());    //I export it to the BOA straightaway
>   echo->setMessage(CORBA::string_dup(value_list[i]));
> 
>   (*seq)[i] = echo->_this();
>  }
> 
> return seq;
> }
> 
> 
> EchoList_ptr Factory_i::load()
> {
>  EchoList_i *list = new EchoList_i();
>  list->_obj_is_ready(_boa());
>  EchoList_ptr list_ptr = list->_this();
>  return list_ptr;
> }
> 
> void Factory_i::unload(CORBA::Object *obj)
> {
>  _boa()->dispose(obj);    //this should call everyone's destructor, no?
> }
> 
> 
> 
> Client (Java):
> =========================
> org.omg.CORBA.Object factory_obj =
> MyNameResolvingClass.getFactoryFromNameService();
> Factory factory = FactoryHelper.narrow(factory_obj);
> EchoList list = EchoListHelper.narrow(factory.load());
> Echo[] echos = list.getEchos();
> for (int i = 0; i<echos.length; i++)
> {
>     System.err.println(echos[i].getMessage());
> }
> 
> //Now I want the server to release all resources associated with the
> EchoList,
> //but the 3 Echo destructors are never called!
> factory.unload(list);
> 
> =========================
> END
> =========================
> 
> 
> 
> --
> Armen Yampolsky
> Axiom Software Labs
> New York
> 
> 
> 
> 
>