RE: Maintaining state: EJB question

2000-06-02 Thread Will Wood

Certainly if you don't care about persistence.  The reference I was showing
was a singleton that had a hash for maintaining home interface contexts.  In
this case
if the EJB was passivated and re-activated at some point, re-creating the
InitialContext and the Hash wouldn't represent too much overhead.  The EJB
exists just to serve other EJB's and to provide a convienience for them.

We've been exploring Orion for some time, as well as Inprise App Server.
IAS passivation and activation work on non-transient/static members so the
container is essentially handling the work for us.  If I take off the
transient qualifiers (except for the Naming Context) passivation and
activation work fine in IAS.

I'm just getting to scoping out how Orion does with both transient
passivation examples as well as non-transient passivation examples.  In this
case I'm relying on how Orion handles this.  If I truely care about
persistence, then a persistence model is required other than what the
container provides for passivation and activation.  It really boils down to
what your design requires.  Using BMP, I could use a DB, an RMI connection
to some passivation object or to a file (Yes "Not recommended" by the spec
and mixed support depending upon EJB container and Security Properties).
The net-net is to use Entity Beans I don't have to use a DBMS nor
persistence.

-Original Message-
From: Jens Stutte [mailto:[EMAIL PROTECTED]]
Sent: Friday, June 02, 2000 11:18 AM
To: 'Will Wood'
Cc: '[EMAIL PROTECTED]'
Subject: AW: Maintaining state: EJB question


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

AW: Maintaining state: EJB question

2000-06-02 Thread Jens Stutte

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.





RE: Maintaining state: EJB question

2000-06-02 Thread Will Wood

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.





Maintaining state: EJB question

2000-06-02 Thread Pedro Garcia Lopez

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.