aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes serialization Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "serialization" Watch "serialization" New topic
Author

serialization

Kalpesh Soni
Ranch Hand

Joined: Jan 02, 2001
Posts: 312
I am really confused
In EJB 2.0 we use local home and local interface If we are sure that the client and ejb are in the same process space.
Correct me if I am making any mistake
But I have observed that weblogic 7.0 finds it out itself whether call made is for the same process space and if so , does not marshal/unmarshal parameters /return objects of a method.
Is this expected behaviour?
Help me Ted !


Test 094, IBM WID 6.0 cert
SCJP 1.2
SCBCD 1.3 Beta
SCWCD 1.4 Beta
SCMAD Beta
SCDJWS Beta

KS
Kyle Brown
author
Ranch Hand

Joined: Aug 10, 2001
Posts: 3892
    
    5
The difference between local and remote interfaces is one of semantics -- the difference between pass-by-reference (local) and pass-by-value (remote). Most app server vendors do various optimizations to make remote calls inside the same JVM faster by avoiding network calls, but they must preserve the pass-by-value semantics to be compliant with the J2EE spec. In fact, I believe Weblogic has a special software "Switch" that must be thrown to treat remote calls within the JVM as pass-by-reference (e.g. avoiding marshalling/unmarshalling). I know that WebSphere does, for instance.
Kyle


Kyle Brown, Author of Persistence in the Enterprise and Enterprise Java Programming with IBM Websphere, 2nd Edition
See my homepage at http://www.kyle-brown.com/ for other WebSphere information.
Chris Mathews
Ranch Hand

Joined: Jul 18, 2001
Posts: 2712
The default behavior of WebLogic 7.0 is to enable call by reference for EJB calls made within the same JVM.
This behavior can be disabled by setting the <enable-call-by-reference> tag in your ejb's weblogic-ejb-jar.xml to false.
rastin purr
Ranch Hand

Joined: Jul 20, 2002
Posts: 73
Dear Kyle,
Sorry, can you please explains what you mean when you said that local and remote references are like pass-by-reference and pass-by-value respectively.
When we lookup a local interface, is it not a copy of the reference being obtained?
When we lookup a remote interface, is it not a copy of the stub being obtained? What is the handle necessity in this case? Is it that by using a handle a robust kind of stub is obtained?
What about when passing parameters in a business method in an ejb? The parameters have to meet the RMI-IIOP requirements by being either primitive, serializable or remote (some how implements Remote interface) is that true? Please correct me if I am wrong. Thanks
Any advice, comments are very much welcomed.
Thanks again
Ras
Chris Mathews
Ranch Hand

Joined: Jul 18, 2001
Posts: 2712
When we talk about pass by reference and pass by value it is the parameters that we are referring to.
The EJB 1.1 specification required that all parameters be passed by value, meaning the parameters are serialized passed across the wire and then unserialized at the other end. This process is usually referred to as marshaling and, as you can imagine, this process tends to be a bit costly especially for intra-JVMs calls where it is not strictly necessary.
The EJB 2.0 specification added local interfaces into the mix which allow intra-JVM calls to use the much more efficient pass by reference approach and bypass the network call. Pass by reference merely passes the reference(duh) or memory location of the object to eliminate the cost of marshaling data unnecessary. Of course to use local interfaces the client must be co-located in the same JVM as the ejb in question. Before EJB 2.0 most EJB containers supplied optimizations that allowed pass by reference even though it was not supported by the spec.
Yes you still want the parameters that are being passed to be Serializable even if you are strictly using local interfaces, though it is not required. That way if you need remoteability in the future it will be an easy change.
You must also design your ejbs with the knowlegde of the potential sharing of objects that pass through the local interfaces.
[ October 19, 2002: Message edited by: Chris Mathews ]
rastin purr
Ranch Hand

Joined: Jul 20, 2002
Posts: 73
Dear Chris,
Thanks for the reply.
When you say that "You must also design your ejbs with the knowlegde of the potential sharing of objects that pass through the local interfaces. "

Do you mean the local interfaces passed should not be modified as it would be reflected on others accessing it. If modification is needed, some means of synchronization is needed. Is that what you mean? Thanks Chris
Ras
Dave Landers
Ranch Hand

Joined: Jul 24, 2002
Posts: 401
If you pass an argument to an EJB, that EJB really should not try to modify the passed Object.
For example, say you have an EJB with something like this on its interface:
public void doSomething( Point p );
Now, if this is on a Local interface, then the actual Point object reference will be passed. If it is on a Remote, then the point will be serialized and the EJB will get a copy (unless the appserver optimizes that to a pass-by-reference).
The EJB really should not be modifying the point. That is, it should not do anything like:
public void doSomething(Point p) {
p.x = 42;
}
This is legal java code, and is also legal in an EJB. But might cause problems. First, if the client calls this via a remote interface, the spec assures them that their point won't be changed (because the ejb gets a marshaled copy). However, if the appserver optimizes this to a pass-by-reference in some cases, it could lead to unexpected (and/or inconsistent) behavior. The user of the code might be surprised to find their object changed. Also, things would work differently when calling the EJB from within the JVM and from outside the server. Even without the pass-by-reference remote optimization, if you someday added a local interface to that method the behavior would be different. So I try to avoid modifying arguments passed to an EJB.
If you really need to do it, I suggest you really document what's going on and why.
rastin purr
Ranch Hand

Joined: Jul 20, 2002
Posts: 73
Thanks Dave,
I read from the ejb2.0 specs that parameters passed to EJB should be serializable. Should it obey the RMI-IIOP rule? If so then it could be primitive, serializable or implementing remote. Is that true?
If a local reference pass in a primtive type, is it going to obey normal java rule such that the primitive type is passed by value?
In the CMR of CMP Entity Beans, only local interface should be used and the examples in books suggest that we use the get and set local reference method to modified the relationship like adding and removing from the collection in a one to many relationship, say for example. Is this the safe way? Cause Dave suggest not modifying the passed value.
Thanks a lot
Rastin
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: serialization