This works? And what, if the server decides to unload this bean, e.g.
passivate it? The variable data may be lost, if for some reason the next
time will be instanciated another instance from the pool, i fear. For my
opinion, this is not covered by the spec, though maybe it works with some or
even all known application servers. Or is ther something special you do in
the ejbActivate function i missed?

The aproach of Pedro has the same problem, since holding a reference to an
entity  bean does not imply neccessarily a loaded and instanciated bean on
the server side (i must admit, that i'm not sure on this, but at least this
could be vendor dependent, i think).

But what about registering directly a class that holds the value(s) in the
nameserver? For the runtime of the JNDI server (and that seems to be the
goal, after all ;-) this should work, though you'll have to take care of
synchronization of your vars etc. yourself in the case of multiple clients
or even clustered servers (sic). Probably that's not the way intended by the
j2ee designers, but it could work (i did not try it, i want to use "real"
beans for similar things....).

Jens Stutte


-----Urspr�ngliche Nachricht-----
Von: Will Wood [mailto:[EMAIL PROTECTED]]
Gesendet am: Freitag, 2. Juni 2000 17:17
An: Orion-Interest
Betreff: RE: Maintaining state: EJB question

I think what you're trying to do is a singleton.  In that case, use BMP
and always return the same key, i.e., "".  I use this for holding Home
Interface
Contexts for EJB's that other EJB's use.

public class HomeBrokerEJB implements EntityBean
{
    transient Hashtable table_;
    transient EntityContext context_;
    transient Context namingContext_;

    public String ejbCreate(String key)
    {
        return "";
    }

    public String ejbFindByPrimaryKey(String key)
        throws RemoteException, FinderException
    {
        try
        {

            if(namingContext_ == null)
                ejbActivate();
        } catch (Exception e)
        {
            throw new RemoteException("Unable to create singleton.", e);
        }
        return "";
    }
...
}


-----Original Message-----
From: Pedro Garcia Lopez [mailto:[EMAIL PROTECTED]]
Sent: Friday, June 02, 2000 7:34 AM
To: Orion-Interest
Subject: Maintaining state: EJB question


Hi,

In order to maintain state for multiple clients the EJB specification
recommends the use of Entity Beans.
So you need to use a database even if you want to maintain state that is
not persistent.

I have found a solution that I do not know if it is correct:
I use a Session Bean.
I the ejbCreateMethod of the Session BEan I do this:

  public void ejbCreate(String name)
  {

   this.name = name;
   users = new HashMap();
  try{
   EJBObject ref = context.getEJBObject();
   Context initial = new InitialContext();

  initial.bind(name,ref);
  }catch (javax.naming.NamingException ex){
   ex.printStackTrace();
  }
   }


and then, applicatrion clients can use JNDI to connect to the Session
Bean reference. You can thus maintains state for multiple clients using
a Session Bean.

Is this a bad trick ?

Some guy told me that this is dangerous due to activation and
passivation, but I think that documentation says that getEjbObject gives
you a handle that persists acrosts passivations states.

Let me know your comments.

In CORBA the Naming service is also used for locating references to
specific instance of remote objects.
In the EJB model I have seen that JNDI is used for locaintg factory
objects (Home).

Is this approach correct ?
can JNDI also be used for locating specific instances ?

Thank you in advance.


Reply via email to