Meaningless Drivel is fun!
The moose likes Distributed Java and the fly likes passing value in constructor Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "passing value in constructor" Watch "passing value in constructor" New topic

passing value in constructor

Neel Chow
Ranch Hand

Joined: Jan 10, 2005
Posts: 55
I have a rmi server whose implemetation is like this.
public class query extends UnicastRemoteObject implements QueryInf
public query(String schema,String[] select,String from, String where)

My question is from the client program how can I pass the value to the query constructor?
Nathan Pruett

Joined: Oct 18, 2000
Posts: 4121

Sorry, but you can't call a constructor from a remote client - the server is created on the server machine and already running, it doesn't get created by the client. And besides, only remote methods can be called from the client, and the constructor can't be a remote method.

There are a couple of ways around this though. One way is that you could make a remote method to "set up" the parameters that the user is supposed to call before other methods get called. Another (and better) choice is make your server a "query factory" that the client calls methods on and passes parameters to in order to get a reference to a "query" back. The "query" could be serializable and be sent to the client, or it could be another Remote class, in which case the stub gets sent to the client as a reference.

Write once, run anywhere, because there's nowhere to hide! - /. A.C.
I agree. Here's the link:
subject: passing value in constructor
jQuery in Action, 3rd edition