This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes How to create unique Client ID 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 create unique Client ID" Watch "How to create unique Client ID" New topic
Author

How to create unique Client ID

Sri Addanki
Ranch Hand

Joined: Apr 27, 2001
Posts: 195
Hi,
I would like to create Connection factory objects. Here's my design. Please let me know if this is the right way?
------------------------------------------------
DATA...defines...criteriaFind()
LOCKMANAGER( also called MultiUserData)...extends...DATA
DATAINTERFACE .... has all method signatures...It does NOT extend Remote
REMOTEINTERFACE.. extends... DATAINTERFACE, REMOTE
RMISERVER... implements... REMOTEINTERFACE...extends...UNICASTREMOTEOBJECT
This RMISERVER is bound to registry.
DATAACCESSREMOTE...extends...UNICASTREMOTEOBJECT...implements...REMOTEINTERFACE
DATACLIENTFACTORY.............has lookup() for remote factory methods. And has createlocal Connection methods.
-----------------------------------------------
Now to create unique client-id, i have getConnection() method in RMISERVER which returns new DATAACCESSREMOTE like this:
public DataInterface getConnection() throws RemoteException, IOException
{
dataAccessRemote = new DataAccessRemote(lockManager);
return dataAccessRemote;
}
-------------------------------------------
where lockManager is created from RMISERVER Constructor like this:
private final LockManager lockManager;
public RMIServer(String dbName) throws RemoteException, IOException
{
lockManager = new LockManager(dbName);
}
-----------------------------------------
Also ALL the methods in RMISERVER redirect the call to DATAACCESSREMOTE class like this:
public int getRecordCount() throws RemoteException
{
return dataAccessRemote.getRecordCount();
}
-------------------------------------------------
And in DATAACCESSREMOTE class methods are like this:
public int getRecordCount() throws RemoteException
{
return lockManager.getRecordCount();
}
--------------------------------------------------
LOCKMANAGER class is subclass of DATA and has only lock/unlock methods.
-------------------------------------------------
1.My question is do RMISERVER and DATAACCESSREMOTE both implement REMOTEINTERFACE?
2.Will REMOTEINTERFACE have getConnection() method signature?
3.Because DATAACCESSREMOTE implements REMOTEINTERFACE, should DATAACCESSREMOTE also have getConnection() method implemented?
If so, how?
4. In DATACLIENTFACTORY i have:
if(serverName.startsWith("rmi://"))
remoteInterface = (RemoteInterface)Naming.lookup(serverName);
else
remoteInterface = (RemoteInterface)Naming.lookup("rmi://"+serverName);
myServer_ = remoteInterface.getConnection();
where myServer_ is of type DATAINTERFACE.( It doesnot extend Remote.)
--------------------------------------------------
thanks,
sri
[ December 27, 2002: Message edited by: Sri Addanki ]
[ December 27, 2002: Message edited by: Sri Addanki ]
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937
I wish you could use the "code" inserts and lighten up on your usage of dots and caps, -- I don't think you can follow your own post.
Eugene.
John Lee
Ranch Hand

Joined: Aug 05, 2001
Posts: 2545
If you are talking about unique Client ID for coustomer, you perhaps have to have a db file to register them.
walid aly
Ranch Hand

Joined: Nov 06, 2002
Posts: 38
a freiend of mine (Jacob ) helped me before
this is what he send me ,
"if you want to implement a factory,the data server class which extends UnicastRemoteObject needn't be bound to the registry. Instead, create one more class named ConnectionManager or so which extends UnicastRemoteObject and should also have a Remote interface of its own. Bind this ConnectionManager to the registry. This instance will be looked up by clients. A call like getInstance() on the ConnectionManager returns data server class which u have already created. In this case each call to the ConnectionManager's getInstance() returns a new remote data instance to the client.
But as you have already noticed, we should have only one local data object. So classes should be designed in such a way that all the remote instances refer to the same local data object. So the method body of ConnectionManager's getInstance() should be somewhat like,
public RemoteDataInterface getInstance(){
return new RemoteDataObject(localObject);
}
So, for each invocation, a new Remote object will be created, but all of them refer to the same local data object. Hope you understood the idea. "
walid
Rajesh So
Ranch Hand

Joined: Oct 08, 2002
Posts: 136

REMOTEINTERFACE.. extends... DATAINTERFACE, REMOTE

Did you mean extending 2 interfaces?
Sri Addanki
Ranch Hand

Joined: Apr 27, 2001
Posts: 195
Thanks Walid, I think i got it now.
When i do Naming.lookup on the RmiServerFactory,(which is bound to registry) i think its not finding the stub, because it gives ClassCast Exception.
But when i do a rmi://localhost/ lookup on the same RmiServerFactory class, then its working.
Can someone please help me with this ClassCast Exception ?
My RmiServerFactory class extends UnicastRemoteObject and implements RemoteInterfaceFactory
thanks,
sri
Originally posted by Rajesh Rajesh:

Did you mean extending 2 interfaces?

Yes, Rajesh, an interface can extend any number of interfaces.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to create unique Client ID
 
Similar Threads
Locking/Unlocking, -- Am I Done Or I Don't Understand Requirements?
confused with my design,thanks for you comment
Initial design review
DataAccessRemote Beta 1.4
Map or Hashtable