Forums Register Login

Problems about using Factory pattern to implement RMI

+Pie Number of slices to send: Send
I implemented the factory pattern as these:
1. The FactoryImpl is registered with the rmiregistry
2. The client requests a reference to a Factory
3. The rmiregistry returns a remote reference to a FactoryImpl
4. The client invokes a remote method on the FactoryImpl to obtain a remote reference to a ProductImpl
5. The FactoryImpl returns a remote reference to an existing ProductImpl.
6. The client invokes a remote method on the ProductImpl to run a testing object's method on the server side.
Note: the FactoryImpl and the ProductImpl are remote objects. My enviroment is : Windows2000, single PC, use file url, server and client
run in two seperated DOS_like windows.
But above cann' work. If I modify the ProductImpl and the test object to implements Serializable, then it work! But the ProductImpl just works on client side instead of server side! I know the reason: the copy instead of remote reference of the two object be passed !
Problems are:
1. Must ProductImpl extend UnicastRemoteObject like FactoryImpl does?
2. Myst ProductImpl implements Serializable?
3. How should I modify it to make it work correctly?
[ October 08, 2002: Message edited by: HiBob Chu ]
+Pie Number of slices to send: Send
Hi,
my design is some wha similar to yours ..
from the client side they ge a connection to the server when the connet to it .. using that they have to get a table(which wraps the data and the lock manager associated with it) in your case its product impl ..
and i have extended UnicastRemoteObject for both
other wise rmi system will complain that it can not marshal your file pointer
again it shuld implement Serializable ..

hope this helps,
cheers,
parthi.
+Pie Number of slices to send: Send
Hi parthiban :
I modifed the ProductImpl to extend UnicastRemoteObject,stilly the client cann't work. The exception is :
"
Client exception: suncertify.db.ProductImpl_Stub
java.lang.ClassCastException:
suncertify.db.ProductImpl_Stub at
suncertify.server.FactroyImpl_Stub.getConnect
(Unknown Source)
at suncertify.client.Client.init(Client.java:41)
at suncertify.client.Client.clientRun(Client.java:63)
at suncertify.client.Client.main(Client.java:68)
"
I want to get such result:
On the server side , there are a test object, it can create a new thread and print "Hello World" on the server side. The ProductImpl contain a reference of the test object.A remote mothod of ProductImpl call the method of test object to print "Hello World" on the server side. So when client call the remote method of ProductImpl, "Hello world" will appear on server side, isn't it?
Now, if I make ProductImpl entend UnicastRemoteObject, it cann't work, else when make ProductImpl only implement Serializable, it works, but the "Hello World" appeared on client side, I think this is not right.
So , how can I make ProductImpl which extend UnicastRemoteObject work?
+Pie Number of slices to send: Send
hi,
hmm lets do this step by step ...
FactoryInterface factory = (FactoryInterface)java.rmi.Naming.lookup(lookUpString);
when you do a look up what you get is the stub class which implements ConnectionInterface lets assume that it is connection_stub when you cast it to the interface it implements you wont get a class cast exception if u cast it to the class you will get a ClassCastException now you have the connection in you case the factory which can produce procutionimpl objects .. this extends UnicastRemoteObject and this procutionimpl wuld have also implemented a interface .. when you do method call on the factory and get a production implementation you shuld do like this
factory(the remote object which i got from the look up)
factory.getPrdImpl();
this will again give you a stub not the real object cos this class is again a remote object
so do it as
PrdInterface prd = factory.getprdImpl();
now you dont get the class cast exception cos the stub can be casted to the interface it implemements..
hope this helps.
cheers,
parthi.
now i have to pray that big guys here dun smack me cos am going to much in detail
+Pie Number of slices to send: Send
Hi parthiban:
I retried it as you said, it's successful! You do give me great help.
Also, I think I have learn a lot from the exam of SCJD. Thank you very much!
[ October 09, 2002: Message edited by: HiBob Chu ]
I do some of my very best work in water. Like this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 706 times.
Similar Threads
Problems about using Factory pattern to implement RMI
All of URLy Bird 1.1.3 how to use the same GUI and Data in alone or netword client
Problems about using Factory pattern to implement RMI
NX: RMI and Mutlithreading
NX: Connection Factory for RMI
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 07:48:16.