This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes ClientID Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "ClientID" Watch "ClientID" New topic
Author

ClientID

Valeri Mikhailov
Greenhorn

Joined: Oct 18, 2002
Posts: 15
Can i use the Data object's hashCode as ClientID?
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

The best solution that we all know of to accurately track clients is through the Connection Object solution.
Data class has only one instance so therefore every client then would have the same HashCode and your theory won't work.
Do a search for Connection Object on this forum and you will find plenty to read.
Mark


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

Joined: Aug 20, 2002
Posts: 7
Don't try to make the project harder than what is described. If designed in a simplistic way you should not need a client id.
It is very easy to get caught up in the details or lack of details in the directions.


Thanks,<br />Dan
Valeri Mikhailov
Greenhorn

Joined: Oct 18, 2002
Posts: 15
My factory creates the unique RemoteClient that creates LockManager that creates Data. Data is unique. Am I right?
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

I don't think it's the LockManager's responsibilty to create instance(s) of the Data class.
Mark
Valeri Mikhailov
Greenhorn

Joined: Oct 18, 2002
Posts: 15
-------------------------------------------------
I don't think it's the LockManager's responsibilty to create instance(s) of the Data class.
--------------------------------------------------
I follow Sun Certification Developer Book: My LockManager is DatabaseAdapter implementing DBClient interface. Lock () and unlock () methods in Data class. Each client has unique Data object. Why it is no good?
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937

I follow Sun Certification Developer Book: My LockManager is DatabaseAdapter implementing DBClient interface. Lock () and unlock () methods in Data class. Each client has unique Data object. Why it is no good?

Well, there are different designs, of course. But what makes sense is a LockManager whose responsibility is just that, -- lock/unlock records. I think that's what Mark is implying, and I completely agree with that. And if you think about it, the cleanest design is that LockManager should not even know anything about Data (or any other class, for that matter). All it needs to know is the identity of the client who is requesting a lock/unlock for a given record number. That way, LockManager is nicely decoupled from everything else in the system.
Eugene.
[ December 11, 2002: Message edited by: Eugene Kononov ]
Jeff Shen
Ranch Hand

Joined: Sep 04, 2002
Posts: 31
The problem is that even you have the ConnectionFactory which implements UnicastRemoteObject, Remote interface and has a Data Instance, you still don't have unique clientID.
I have tested from two computers to connect the RMI server and do booking flight. It seems only one Remote object created for the two different clients.
I really confused how the RMI manage the threads.
Jeff
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937

The problem is that even you have the ConnectionFactory which implements UnicastRemoteObject, Remote interface and has a Data Instance, you still don't have unique clientID.

Your client should request a remote object (presumably by calling a method on a factory object), and the factory should return a new remote object to that client.
Eugene.
[ December 11, 2002: Message edited by: Eugene Kononov ]
Jeff Shen
Ranch Hand

Joined: Sep 04, 2002
Posts: 31
Thanks Eugene
What I have done on the server is as following
try {
Naming.rebind("//localhost:" + serverPort + "/FBNSystem", data);
} catch (RemoteException remoteException) {
System.err.println(
"Failure during Name registration: " +
remoteException);
} catch (MalformedURLException malformedException) {
System.err.println(
"Failure during Name registration: " +
malformedException);
}
What I have done on the client is this
try{
data = (DataInterface)Naming.lookup(
"rmi://" + serverName + ":" + serverPort +
"/FBNSystem");
} catch
etc..
It works fine, I just can't get distingush ClinetID
please advivce what should be done.
Jeff
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

What you have is, you are requesting the one object that is in the registry, and that alone, so yes every client has the exact same object.
But what the Connection Object solution does is as follows.
You do a lookup and get the one object that is in the registry. This class is the ConnectionFactory object, when the client receives this class it calls a method called getConnection(), this returns a new Connection object to each and every user.
The ConnectionFactory has a reference to the one Data class instance and passes this reference to the new Connection object.
Now here each Connection object is unique to each client, and resides on the server. The Connection object itself is the unique client ID.
Does this make sense?
Mark
Valeri Mikhailov
Greenhorn

Joined: Oct 18, 2002
Posts: 15
Is the Connection object a RemoteClient?
Valeri
Valeri Mikhailov
Greenhorn

Joined: Oct 18, 2002
Posts: 15
Who can explain me, why my design is not good. It works well on my computer.
I follow Sun Certification Developer Book: My LockManager is DatabaseAdapter implementing DBClient interface. Lock () and unlock () methods in Data class.My factory creates the unique RemoteClient that creates LockManager that creates Data. Data is unique. Each client has unique Data object. Why it is no good?
Jeff Shen
Ranch Hand

Joined: Sep 04, 2002
Posts: 31
Thanks Mark
You mention the connection object, is it a instance of Data.
Jeff
Jeff Shen
Ranch Hand

Joined: Sep 04, 2002
Posts: 31
Thanks Mark
I got the idea, I just don't understand what do you mean by the following.
----------------------------------------
The ConnectionFactory has a reference to the one Data class instance and passes this reference to the new Connection object.
---------------------------------------
Jeff
Jeff Shen
Ranch Hand

Joined: Sep 04, 2002
Posts: 31
I think now i got it.
Should i do as following on the server side
Public class ConnectionFactory extends UnicastRemoteObject implements Remote
private DataInterface data;
...
public DataInterface getConnection() throws IOException, RemoteException, DatabaseException{
data = new RemoteData(databaseName); return (DataInterface)data;
}
Now the reference of data is the clientID, which can be used for lock/unlock the record
thanks
Jeff
Charles Dupin
Ranch Hand

Joined: Oct 18, 2002
Posts: 94
What is the point of getting a new instance of the connection object for each different client. If all the clients call the same object in registry and the locking and synchronisation are well done, is this a fault?
Can we get penalized with the design 'single object', is it worse than the design with the connection factory.
Thanks for your explanations.
Charles.


Charles.<br />(SCJD2)
Jeff Shen
Ranch Hand

Joined: Sep 04, 2002
Posts: 31
Because to lock/unlock record according to the unique clientID is part of assignment requirement and also if you implement Unreferenced interface you can clear up the lock when the object is unreferenced.
hope this explains
Jeff
Charles Dupin
Ranch Hand

Joined: Oct 18, 2002
Posts: 94
Well, there is absolutely no mention of locking with client ID in my assignement. I dont use Unreferenced.unreferenced as I dont use a connection factory. I use a timer to clear the forgotten locks in the hashtables and set a java.rmi.server.UID to each transaction, use it for locking and return it as confirmation number.
My question was about poor design considerations or not in case I do not use a client factory.
Charles.
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Originally posted by Charles Dupin:
Well, there is absolutely no mention of locking with client ID in my assignement. [...]
Ah, but there is. You just didn't recognise it as such. Read very carefully the supplied javadoc for Data.unlock(int).
- Peter
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

return (DataInterface)data;

You don't have to cast this variable because it is already of DataInterface type.
But otherwise that looks good Jeff.
Mark
Charles Dupin
Ranch Hand

Joined: Oct 18, 2002
Posts: 94
/**
* Unlock the requested record. Ignored if the caller does not have
* a current lock on the requested record.
*/

OK Peter, Thanks very much, at least its clear now.
(In fact it depends on the meaning of the word caller, in my mind the caller was the calling method, but my english is far from perfect.
If someone disagrees with that, lets keep the discusion opened. What is the meaning of the word caller?)
Charles
[ December 12, 2002: Message edited by: Charles Dupin ]
[ December 12, 2002: Message edited by: Charles Dupin ]
Jeff Shen
Ranch Hand

Joined: Sep 04, 2002
Posts: 31
When I try to call getConnection method after the ConnectionFactory bound on the Clinet, I keep get following error message
java.rmi.UnmarshalException: error unmarshalling return; nested exception is:
java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: suncertify.server.RemoteData
I don't know what is wrong, can you help me.
Jeff
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Originally posted by Charles Dupin:
In fact it depends on the meaning of the word caller [...] What is the meaning of the word caller?
Giving precise meaning to the word "caller" is actually part of your design process. But, as I read it, whatever your implementation is, each FBN client application must be a distinct "caller".
If you'd use the per-client Connection pattern advocated by many in this group, then you identify a "caller" with the Connection object. In theory, an application can acquire multiple Connection objects and impersonate more than one "caller" (as in fact you can do with an ordinary JDBC database).
Others use the client's IP to identify it. In that case, the "caller" is the machine. I'm not advocating this method, by the way; in the Unix world, it would be entirely possible to run multiple FBN clients on the same server, and also NAT firewalls routinely map hundreds of machines to one single IP.
- Peter
[ December 13, 2002: Message edited by: Peter den Haan ]
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Originally posted by Jeff Shen:
When I try to call getConnection method after the ConnectionFactory bound on the Clinet, I keep get following error message [...]
The message complains that your RemoteData is not Serializable. The very fact that RMI tries to serialize RemoteData means that it is not a true remote object.
Either extend UnicastRemoteObject (recommended), or use UnicastRemoteObject.exportObject() to export your RemoteData. If you choose the second option then read the directions inside the javadoc for UnicastRemoteObject.
- Peter
Charles Dupin
Ranch Hand

Joined: Oct 18, 2002
Posts: 94
Ok Peter,
I have now implemented the Connection Factory. The connection object can be used for the caller ID, but what exactly is to be used?
  • RemoteObject
  • RemoteObject.ref
  • RemoteObject.hashCode()
  • RemoteObject.ref.hashCode()

  • Thanks,
    Charles.
    Peter den Haan
    author
    Ranch Hand

    Joined: Apr 20, 2000
    Posts: 3252
    Originally posted by Charles Dupin:
    The connection object can be used for the caller ID, but what exactly is to be used?
    Keep it simple! As you will probably be using the Connection as the key in a HashMap, you will be using Connection.equals() and Connection.hashCode(). The UnicastRemoteObject implementation of these methods will do just fine (in this case, even the default implementations provided in java.lang.Object would have been fine: you will be storing a local reference to these objects in the HashMap, so you don't need any of the logic in UnicastRemoteObject that ensures that two remote references are equal if they refer to the same object).
    - Peter
    Jeff Shen
    Ranch Hand

    Joined: Sep 04, 2002
    Posts: 31
    Thanks Peter
    That was exactly my problem, Now i feel very comfortable with remote Object.
    So far I'm almost done the project and plan to submit at weekend.
    Jeff
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: ClientID
     
    Similar Threads
    How to produce the clientID?
    RMI Server and clientID
    Regular expression
    JMS Durable Subscriber Example
    lock and unlock