Hi,
My question is regarding stateless session beans only. The application should be deployed on any application server, so Im trying to stick to the SPEC.
Im using delegate pattern to access EJBs, in the constructor I call service locator to get the home interface and save it as private field in the delegate class. Each business method creates the remote interface home.create() and invoke the business method.
1. Can I save the remote interface as private field in the class instead of the home? in the constructor I will call service locator and directly create the remote object. in this case I dont need to create the remote object each method invocation.
I think this should not be problem since we talk about stateless beans and the fact that same home create same remote interface each create invocation (according to EJB 2 spec).
And this should not defeat pooling cause the application server pools the bean instances and not the EJBObjects
2. If section 1 is correct, is it good idea to cache remote interfaces in service locator?
3. I'm working with local interface too (EJBLocalObject) is the same as interface or it needs special treatment?
Thanks in advance
-
Remote EJBObject for stateless session beans (4 messages)
- Posted by: Johny Abdallah
- Posted on: August 17 2004 09:46 EDT
Threaded Messages (4)
- Remote EJBObject for stateless session beans by Bhupesh Kokate on August 17 2004 12:43 EDT
- Remote EJBObject for stateless session beans by Tomas Karlsson on August 17 2004 14:55 EDT
- Remote EJBObject for stateless session beans by Johny Abdallah on August 30 2004 02:32 EDT
- Remote EJBObject for stateless session beans by Balaji Varadarajan on December 31 2004 10:53 EST
-
Remote EJBObject for stateless session beans[ Go to top ]
- Posted by: Bhupesh Kokate
- Posted on: August 17 2004 12:43 EDT
- in response to Johny Abdallah
You can always cache ur remote interface instead of home interface and it doesnt make differece with local interface.Hi,My question is regarding stateless session beans only. The application should be deployed on any application server, so Im trying to stick to the SPEC.Im using delegate pattern to access EJBs, in the constructor I call service locator to get the home interface and save it as private field in the delegate class. Each business method creates the remote interface home.create() and invoke the business method.1. Can I save the remote interface as private field in the class instead of the home? in the constructor I will call service locator and directly create the remote object. in this case I dont need to create the remote object each method invocation.I think this should not be problem since we talk about stateless beans and the fact that same home create same remote interface each create invocation (according to EJB 2 spec).And this should not defeat pooling cause the application server pools the bean instances and not the EJBObjects2. If section 1 is correct, is it good idea to cache remote interfaces in service locator?3. I'm working with local interface too (EJBLocalObject) is the same as interface or it needs special treatment?Thanks in advance
-
Remote EJBObject for stateless session beans[ Go to top ]
- Posted by: Tomas Karlsson
- Posted on: August 17 2004 14:55 EDT
- in response to Johny Abdallah
Hi!
From what I can see, this should work as long as you have stateless beans. At least that's my interpretation of section 7.5.8 in the EJB 2.1 specification. (I am referring to the "Proposed Final Draft" since that is the one I have on the disk now, but I don´t expect such a basic thing to change in such late stage of the specification writing.)
/Tomas -
Remote EJBObject for stateless session beans[ Go to top ]
- Posted by: Johny Abdallah
- Posted on: August 30 2004 02:32 EDT
- in response to Johny Abdallah
Thank you guys for your replies, I still have one open issue. According to the spec EJB 2.0 final release section 6.9.2:
"All session objects of the same stateless session bean within the same home have the same object identity, which is assigned by the container. If a stateless session bean is deployed multiple times (each deployment results in the creation of a distinct home), session objects from different homes will have a different identity."
FooHome fooHome = ...; // obtain home of a stateless session bean
Foo foo1 = fooHome.create();
Foo foo2 = fooHome.create();
if (foo1.isIdentical(foo1)) {// this test returns true
...
}
if (foo1.isIdentical(foo2)) {// this test returns true
...
}
Does that mean that we have same instance, or doest it access same bean instance?
what will happened if I cache the remote interface and two different threads invokes its methods in the same time? doest they use different bean instance or they may access the same one (which will lead to throwing exception by application server)
Thanks -
Remote EJBObject for stateless session beans[ Go to top ]
- Posted by: Balaji Varadarajan
- Posted on: December 31 2004 10:53 EST
- in response to Johny Abdallah
Does that mean that we have same instance, or doest it access same bean instance?
For stateless beans, the actual bean is associated only during business method call. So on doing isIdentical(), there are no real comparisons of 2 stateless session beans. But, the client can assume that it is comparing 2 EJBObject instances (although the Container can implement it in any fashion). For Stateless it would be just comparing their EJBHome.
what will happened if I cache the remote interface and two different threads invokes its methods in the same time? doest they use different bean instance or they may access the same one (which will lead to throwing exception by application server)
It should lead to throwing java.rmi.RemoteException ( if remote) or javax.ejb.EJBException (if local). A session object is intended to support only a single client. ( Pg 101 - EJB Spec).