Why ever pass by value?
What is the benefit of ever passing by value using RMI? Wouldn't you always be better off passing by reference? I know there are difficulties (such as the remote object must implement interface Remote) but there are workarounds for that.
So again, why would you *ever* want to pass by value?
Thank you,
Gili
[333 byte] By [
cowwoca] at [2007-10-3 4:33:23]

Hmm, I read at http://jdj.sys-con.com/read/35848.htm that pass-by-value helps scalability because the server doesn't have to keep instances around on its end if they are unlikely to be shared by clients.
Is there a way to cause Remote objects to be passed by value? That is, I want to wrap RMI so the default is pass by reference and if the client explicitly requests it, it can pass by value.
Any ideas?
Thanks,
Gili
Hi Gili,
It is ironic that while Java passes local objects by reference; which is what most people want, by default it passes remote objects by value. One way to handle this would be to make a utility class with two methods, so you could do something like this:return Utility.byValue(x);
orreturn Utility.byReference(x);
As least then it is explicit in the code what your intent is. I imagine you can very easily guess the implementation of these two methods.
Happy hacking,
John
cajoa at 2007-7-14 22:36:59 >

> It is ironic that while Java passes local objects by
> reference; which is what most people want, by default
> it passes remote objects by value.
John, this is completely back to front. By default Java passes object references by value. In RMI it passes entire objects by value (via Serialization) unless the object is remote, in which case it is once again (remote) reference by value.
@OP: Access to a remote object by value is a contradiction in terms.
ejpa at 2007-7-14 22:36:59 >

Hi Esmond,
Perhaps we should start a wikipedia topic on this one. I think too few people know assembly language programming anymore.
What we are both saying is absolutely correct; however we are saying two completely different things.
I said Java passes objects by reference.
You said Java passes object references by value.
I do not disagree. However, in the context of the original question about the object itself above: one way gets each its own object, the other, all share the same object.
This is a huge difference; and people really need to understand it.
John
cajoa at 2007-7-14 22:36:59 >

John,
What about the article I linked to? http://jdj.sys-con.com/read/35848.htm
They seem to imply that pass-by-value is default is a good thing in that it allows you to scale your servers much better, and now that I think about it, they're probably right.
What I mean is, if your client-server communicate infrequently during a long session then pass-by-value probably makes sense but if you communicate frequently over short sessions then pass-by-reference is probably preferred. My application probably falls in category 1 so I'm trying to get pass-by-value working with automatic initialization of lazy-collections.
Gili
Gili,
As you are probably aware by now, using cajo semantics, the client code is unaffected by whether the object is returned by reference, or by value.
This creates an interesting alternative scenario:
A server can initially return objects by value, and if it notices more interactions with certain clients, it can shift on the fly into returning to them by reference.
That could be pretty cool.
John
PS It is also quite useful sometimes to return an object by value, which has references to remote objects on the server, that it manipulates. This is what is done in the [url=http://wiki.java.net/bin/view/Communications/ProxyUsage]graphical proxy,[/url] for instance.
cajoa at 2007-7-14 22:36:59 >

John,
It wouldn't be so simple to move from pass-by-value to pass-by-reference because in its current implementation pass-by-value will not allow the modification of method arguments. I am wondering whether it is possible to design a pass-by-value mode that is smart enough to pass back modifications to the method arguments.
Gili
Gili,
If I understand what you are designing; I think a hybrid reference/value object could be just the ticket.
The part arriving by value could evaluate invocations by the client, and when warranted, convey them back to the server, via its internal reference. It is a very powerful concept; it minimises server workload, while at the same time, maximises overall system performance.
John
cajoa at 2007-7-14 22:37:00 >
