activator implementation
Matthew Newhook
matthew_newhook@stratos.ca
Thu, 26 Jun 1997 16:59:54 -0230
Hi,
What follows is an implementation of activators. This provides the
ability for on-demand loading of objects. What we at Stratos use
this for is for is on-demand loading of objects from a message
database. The objects are then unloaded after some period of
inactivity.
This implementation adds three methods.
omniORB::register_activator(Omni_Activator* activator)
omniORB::unregister_activator(Omni_Activator* activator)
CORBA::Object_ptr BOA::make_object(const omniObjectKey& k,
const char* type_id)
This may not be the most stable of code, I wrote it yesterday
and have been testing it for most of the day. It appears to work.
Any questions send me some mail.
These files are in include/omniORB2:
RCS file: RCS/CORBA.h,v
retrieving revision 1.1
diff -r1.1 CORBA.h
868a863,866
> Object_ptr make_object(const omniObjectKey& k, const char* type_id);
> // omniORB2 specific. Create an proxy that refers to a local object
> // with the specified key, and the specified type_id.
>
RCS file: RCS/omniInternal.h,v
retrieving revision 1.1
diff -r1.1 omniInternal.h
74a75,76
> class Omni_Activator;
>
129a132
> static omniObject *locateObjectInternal(omniObjectKey &k);
239c242,243
< protected:
---
> //protected:
> public:
322a327
> friend omniObject *omni::locateObjectInternal(omniObjectKey &k);
RCS file: RCS/omniORB.h,v
retrieving revision 1.1
diff -r1.1 omniORB.h
42a43,44
> class Omni_Activator;
>
172a175,180
> // on demand object activation.
>
> static void register_activator(Omni_Activator* activator);
> static void unregister_activator(Omni_Activator* activator);
> static _CORBA_Boolean activate(omniObjectKey &k);
>
174a183,184
> static omni_mutex activatorLock;
> static Omni_Activator* activatorHead;
175a186,195
> };
>
> class Omni_Activator
> {
> public:
> virtual ~Omni_Activator() = 0;
> virtual _CORBA_Boolean activate(const omniObjectKey& key) = 0;
> private:
> friend class omniORB;
> Omni_Activator* pd_next;
in src/lib/omniORB2
RCS file: RCS/corbaBoa.cc,v
retrieving revision 1.1
diff -r1.1 corbaBoa.cc
161a162,202
> Object_ptr
> CORBA::
> BOA::make_object(const omniObjectKey& k, const char* type_id)
> {
> IOP::TaggedProfileList * p = 0;
> omniObject* omniObj = 0;
> Object_ptr o = 0;
> try
> {
> Rope *r = 0;
> {
> Rope_iterator next(&Anchor::incomingAnchor);
> r = next();
> }
> if (r == 0)
> {
> throw CORBA::INTERNAL(0,CORBA::COMPLETED_NO);
> }
> p = new IOP::TaggedProfileList(1);
> if (p == 0)
> {
> throw CORBA::NO_MEMORY(0,CORBA::COMPLETED_NO);
> }
> p->length(1);
> r->iopProfile((CORBA::Char *)&k,
> sizeof(omniObjectKey),
> ((IOP::TaggedProfileList &) *p)[0]);
> omniObj = omni::createObjRef(type_id, type_id, p, 0);
> delete p;
> o = new Object();
> o->PR_setobj(omniObj);
> }
> catch (...)
> {
> delete p;
> delete omniObj;
> delete o;
> throw;
> }
> return o;
> }
RCS file: RCS/objectRef.cc,v
retrieving revision 1.1
diff -r1.1 objectRef.cc
279c279
< omni::locateObject(omniObjectKey &k)
---
> omni::locateObjectInternal(omniObjectKey &k)
282,287c282,286
< omniObject **p = &omniObject::localObjectTable[omniORB::hash(k)];
< while (*p) {
< if ((*p)->pd_objkey.native == k) {
< (*p)->setRefCount((*p)->getRefCount()+1);
< omniObject::objectTableLock.unlock();
< return *p;
---
> omniObject *p = omniObject::localObjectTable[omniORB::hash(k)];
> while (p) {
> if (p->pd_objkey.native == k) {
> p->setRefCount(p->getRefCount()+1);
> break;
289c288
< p = &((*p)->pd_next);
---
> p = p->pd_next;
291a291,311
> return p;
> }
>
> omniObject *
> omni::locateObject(omniObjectKey &k)
> {
> omniObject* obj = locateObjectInternal(k);
> if (obj != 0)
> {
> return obj;
> }
>
> if (omniORB::activate(k))
> {
> obj = locateObjectInternal(k);
> if (obj != 0)
> {
> return obj;
> }
> }
>
RCS file: RCS/orb.cc,v
retrieving revision 1.1
diff -r1.1 orb.cc
871a872,926
>
> /*static*/ void
> omniORB::register_activator(Omni_Activator* activator)
> {
> activatorLock.lock();
>
> activator->pd_next = activatorHead;
> activatorHead = activator;
>
> activatorLock.unlock();
> }
>
> /*static*/ void
> omniORB::unregister_activator(Omni_Activator* activator)
> {
> int found = 0;
>
> activatorLock.lock();
> Omni_Activator** curr = &activatorHead;
> while (*curr != 0)
> {
> if ((*curr) == activator)
> {
> *curr = (*curr)->pd_next;
> found = 1;
> break;
> }
> curr = &(*curr)->pd_next;
> }
> activatorLock.unlock();
>
> if (!found && omniORB::traceLevel > 0)
> {
> cerr << "Cannot find activator in activator list." << endl;
> }
> }
>
> /*static*/ CORBA::Boolean
> omniORB::activate(omniObjectKey &k)
> {
> activatorLock.lock();
> Omni_Activator* curr = activatorHead;
> while (curr != 0)
> {
> if (curr->activate(k))
> break;
> curr = curr->pd_next;
> }
> activatorLock.unlock();
> return curr != 0;
> }
>
> Omni_Activator::~Omni_Activator()
> {
> }
RCS file: RCS/unshared.cc,v
retrieving revision 1.1
diff -r1.1 unshared.cc
61a62,64
> omni_mutex omniORB::activatorLock;
> Omni_Activator* omniORB::activatorHead = 0;
>
Matthew
--
Matthew Newhook. matthew_newhook@stratos.ca, http://www.engr.mun.ca/~matthew
Software Designer, Stratos Network Research.
w: (709) 364-5950, h: (709)-745-4346