wood burning stoves 2.0*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes How to bind an object instanciated from an extended class ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "How to bind an object instanciated from an extended class ?" Watch "How to bind an object instanciated from an extended class ?" New topic
Author

How to bind an object instanciated from an extended class ?

bru pe
Greenhorn

Joined: Jan 23, 2002
Posts: 11
how can I bind my RemoteDataAccess?
this one must extend the UnicastRemoteObject to be bound to the rmiregistry AND extend the Data class as described in the submission requirement...
Can anyone that have extended the Data class to implement the locking methods, explain to me how to bind ?
A bit explaination on my system:
Each Client call first a getConnection() method that create a RemoteDataAccess object and bind it to the registry.The RemoteDataAccess class implement Runnable to be sure ThreadSafe.Then, the getConnection() method send the reference of the RemoteDataAccess object.The client has just to connect to this Object to call any methods.Each client has his own rmi binded object.
Is this a good minded solution or not?
Bruno
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Your RemoteDataAccess class just needs to extend Remote, you do not need to bind it into the registry at all.
Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
bru pe
Greenhorn

Joined: Jan 23, 2002
Posts: 11
Mark,
my RemoteDataAccess is not an interface...
As described in the Java tutorial, the interface must extend Remote an the binded classes must extends UnicastRemoteObject and implement this interface
NB: RemoteDataAccess class is on the Server side and not on the Client.Maybe should I rename it as DataServer to be more right in the context.
If I don't bind this class to the Registry, how can the clients call any methods of the "DataServer" class
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

OK, so your class is not the implementation of your DataAccess interface then. This is your actual Connection/Server engine that each client needs to get and calls a method on it called GetConnection.
In your server startup class you will using the RMI Naming classes to call rebind() to bind the object. Use rebind, because it will overwrite the object if it already exsits, rather than having to unbind the object then bind again to replace with the new one

Mark
bru pe
Greenhorn

Joined: Jan 23, 2002
Posts: 11
Mark,
All right,I've renamed my classes and now I'll explain the entire Server system:

RemoteDataAccesInterface extend Remote - interface that contain all the Data methods and the lock and unlock methods declaration.
Data - give the methods to acces the db.db file.just as given from the assignement.
DataServer extend Data(,UnicastRemoteObject) implement Runnable,RemoteDataAccessInterface - just the implementation of the lock and unlock methods. My problem is there !! I need to extend the Data class AND the UnicastRemot...
ConnectionFactoryInterface extend Remote - interface which contain the getConnection() method
ConnectionFactory extend UnicastRemoteObject implement ConnectionFactoryInterface - the getConnectin is implemented . When a client call this method : creation of a DataServer object,bind it to the registry and return the name of the object bound to the client. So the Client have to make a connection to the object created. Then each Client own his own DataServer Object in his own Thread.
LockMgr - a "static" map that contain the records number and their state (Locked - Unlocked)
to make the things more clear for me, can you answer this short questions:
1)How many object are bound in your rmiregistry?
I expect you have one ConnectionFactory object( to get a reference to the DataAcces objects) and the same number of DataAccess object than the number of client which are connected
2)Did I miss something in my Server Design?
3)How many "aspirin" have you eat since the beginning of your assignement?
Thank you so much for the advice
Bruno
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Ok here's the 911.
There is only ever one object bound to RMI, that is your DataServer, which should only have one method. GetConnection() It returns a DataAccessRemote object which is only a Remote object, it does not extend Unicast...
when the client calls get connection it returns a new instance of DataAccessRemote, however it will be running on the Server. Meaning there will be one DataAccessRemote per client running.
In your DataServer, you should have an instance of the Data class.
DataServer should not extend the Data Class.
When your DataServer creates an instance of DataAccessRemote, you pass a reference to the Data class reference that is in your DataServer. There for each DataAccessRemote has a reference to the one and only one Data class instance.
Hope that helps.
Mark
bru pe
Greenhorn

Joined: Jan 23, 2002
Posts: 11
wow!!! ...my rescuer...
Thank you so much!
I stay with a doubt:
in the submission ,they said:
"Part of your assignement will be to enhance th Data class.You may do this by modification or subclassing. This last word doesn't mean that I should extend the Data class?
more clear:
subclassing = inheritance or composition?
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

This last word doesn't mean that I should extend the Data class?

Maybe maybe not.
This is a tough call, because I only modified the data class, meaning I went into the data.java file and changed the stuff directly, instead of extending and overriding. But it really depends on if the "New" data class that you will creat, is it really a new class, or jsut some stuff that should have been there in the first place.
Good Luck
Mark
bru pe
Greenhorn

Joined: Jan 23, 2002
Posts: 11
Yes I got it.
Bruno Vs the FBN project : 1-0
with the good design, my cleared RMI skills and after a long working night, my server is all functional
Thank you Mark.
jefferson p
Greenhorn

Joined: Mar 06, 2002
Posts: 10
Hello,

There is only ever one object bound to RMI, that is your DataServer, which should only have one method. GetConnection() It returns a DataAccessRemote object which is only a Remote object, it does not extend Unicast...

I've messed with this for several days now... How can you return a DataAccessRemote object which "does not extend Unicast..." if it wraps the Data object (which is non-serializable)???
My version works with only the DataServer bound to the registry and both the DataServer and DataAccessRemote object extending UnicastRemoteObject (or if just the DataServer extends it and the DataAccessRemote is exported with the UnicastRemoteObject.export() method).
If the DataAccessRemote object does not extend UnicastRemoteObject than I get the "non-serializable" errors, which I would expect, since it then tries to send the Data object (which is non-serializable) over the wire.
I also have to have 2 stubs - one for the DataServer and one for the DataAccessRemote class - is this right??
Thank you,
Jeff
Travis Zimmerman
Greenhorn

Joined: Mar 06, 2002
Posts: 27
In order to send the RemoteDataClass across the network it either needs to extend UnicastRemoteObject, implement Remote or implement Serializable(Not really messed with this yet.). I have a base interface DataAccessInterface. I have a RemoteDataInterface which extends DataInterface and Remote. The RemoteDataInterface is merely a mixin. Now the RemoteData class, in which has all of the calls to the Data file, implements the RemoteDataInterface. The DataServer( ConnectionFactory ) can send this object through rmi to the client.
Hope that makes sense.
Travis Zimmerman
jefferson p
Greenhorn

Joined: Mar 06, 2002
Posts: 10
Thanks for the quick response, Travis,
I can't seem to get it to work without the export.
My RemoteData class has a reference to Data which is set in the constructor...

I can't figure it out... The data is somehow being sent across the wire and puking since it's not serializable... Aaaaghh!
Thanks,
Jeff
Krishna Varma Adluru
Ranch Hand

Joined: Nov 24, 2001
Posts: 55
Hi jefferson,
I am also experiencing the SAME problem ...
I also extended UnicastRemoteObject in both cases:
1) RemoteDataAccess and 2)DataServer.
Otherwise, it gives "Serialization errors" ...
But, Mark Spritzler argues that we need to extend
UnicastRemoteObject only in the case of DataServer and not with RemoteDataAccess.
But, I could not get it work ... It's throwing
serialization errors ...
Is there someone who went through this phase and
made it work without extending UnicastRemoteobject
Please help us(Jefferson and Myself) out ...
Thanks,
Regards,
Krishna Varma Adluru
Travis Zimmerman
Greenhorn

Joined: Mar 06, 2002
Posts: 27
Ok, I must have misunderstood/misspoke. Everyone ends up using close to the same names so it gets a little confusing.
Here is how I have set mine up:
public interface DataInterface
public interface RemoteDataInterface extends Remote, DataInterface
public class DataServer extends UnicastRemoteObject implements RemoteDataInterface, Unreferenced
-- This is my class that connects to the db. It is where I validate locking/unlocking and the object that is sent to the client. This class is not bound to the registry.
class ConnectionFactory extends UnicastRemoteObject implements ConnectionFactoryInterface
-- This is the class that is bound to the registry ( and I believe what you call the DataServer ). This class creates a new DataServer object and passes it to the client. through the following function call:
public DataInterface getConnection() throws RemoteException
I hope that clears it up for you both.
Travis
Travis Zimmerman
Greenhorn

Joined: Mar 06, 2002
Posts: 27
I believe Mark's comments are in reference to what I call RemoteDataInterface. I belive bru was using a class instead of an interface here. This interface should not extend Unicast.., it should extend Remote and RemoteDataInterface.

Travis
[ March 15, 2002: Message edited by: Travis Zimmerman ]
jefferson p
Greenhorn

Joined: Mar 06, 2002
Posts: 10
Thanks!
Krishna Varma Adluru
Ranch Hand

Joined: Nov 24, 2001
Posts: 55
Travis,
Thank You very much ...This is exactly what
I did and it works .... But, Mark's comments
were in regard to "DataServer" in your case.
Anyway, Thanks a lot ..
Regards,
Krishna
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

The RemoteConnection object extends Remote, that is all it needs to do to download, becuase it is like RMI in that the client only uses a stub(Adapter Pattern) to make the calls to the object. The RemoteConnection object does not get downloaded to the client. This seems to be what I am hearing is happening when you get Serialization errors with the data class.
Mark
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: How to bind an object instanciated from an extended class ?
 
Similar Threads
Question about Connection Object
posting again...pl help
Question about ConnectionFactory implementation
dumb qn: Classes stored in Remote client
Basic Model Layout, Doubts on LockManager