REPOST: Using a class as a Singleton in Conjunction with AXIS

  • Thread starter christian.bongiorno
  • Start date
C

christian.bongiorno

So, I am trying to use a class as a Singleton inside AXIS. The
deployment descriptor has a scope qualifier for "application" which,
per documentation will accomplish this.

However, the class needs to also be able to work as an internal API to
other classes. So, what I have done is to use a lazy instantiation of
the class along with a singleton. I will paste the code. Essentially I
check to see if the AXIS loader is present in the class path, if it is,
then I also check to see who the caller is of my constructor. If it's
AXIS, I allow construction and set my singleton instance to 'this'.

The problem is if the loader class is present, even if it isn't used,
the "getInstance()" method or even the constructor cannot be called
until after AXIS has called it (which, if the class is just in the path
can never happen). Someone may actually need a class that's in the same
jar as the loader for something else they are doing -- then it's game
over.

What I would LOVE is to have AXIS actually use the "getInstance()"
method like everyone else.

Here is the code. To protect my ass certain pieces are ommited, but you
get the idea -- would appreciate some ideas.

Christian

-----------------------------

public static SomeClass getInstance() {
if (ourInstance == null)
ourInstance = new DaveUniqueIdGenerator();

return ourInstance;
}

public SomeClass () {
// if this class has already been loaded then throw an
exception -- singleton only
if (ourInstance != null)
throw new RuntimeException("The Id generate has already
been loaded");
else {
// if the axis loader actually is part of this operating
env, then it's POSSIBLE
// that AXIS is trying to invoke this constructor and
that's ok.
if(inAxisEnv) {
// if AXIS is trying to summon us, then all is well.
Let it use this constructor -- but only once
if(isAxisCalling())
ourInstance = this;
else // if we're in an AXIS env, then AXIS must load us
first
throw new RuntimeException("When running in an AXIS
env AXIS must first summon this service");
}
else // if AXIS is not part of our env, then clearly this
class is operating standalone and thus
ourInstance = this;// we can allow construction to our
caller regardless of who it is.
}

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top