wood burning stoves 2.0*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Connection Manager Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Connection Manager" Watch "Connection Manager" New topic
Author

Connection Manager

Siddharth Mehrotra
Ranch Hand

Joined: Aug 21, 2001
Posts: 185
hi,
i have been reading a lot about connection manager on this board.
can anyone explain me why is there a need of connection manager.
if i bind the remoteImp of data class with the rmi registry. everone will be able to share the object.
and if i plan to use a lockManager for maintaining the lock records, then even there , there should be only one object of lock manager that muct be used by the remoteData class.
so whats the need of a connection manager


SCJP, SCJD.
Rowan Brownlee
Ranch Hand

Joined: Aug 07, 2000
Posts: 97
At this stage, I have a ConnectionFactory to provide Connections to clients. The ConnectionFactory is bound to the RMIRegistry. Each Connection is a remote object, and provides a link to my Server, which itself contains the shared database (and a link to a LockManager). My clients call search/book etc on their Connection, and the Connection passes the info onto the Server.
My Connections implement the RMI Unreferenced interface. This provides an easy way to tidy up stale locks. Eg. My client may collapse and leave a record locked in LockManager. By having Connection implement Unreferenced, I can include an instruction in the unreferenced method to unlock all records locked by this Connection.
From Pitt and McNiff's Remote Method Invocation Guide p.75
"The java.rmi.sserver.Unreferenced interface provides a mechanism for notifying a server object when no further remote clients have remote stubs for it. ... The unreferenced method is a callback invoked by the RMI system and when the DGC subsystem has determined that the number of remote clients of the object has fallen to zero"
Here's a link to some associated info on the Factory pattern and RMI.
http://java.sun.com/products/jdk/1.2/docs/guide/rmi/Factory.html
cheerio
rowan
Originally posted by Siddharth Mehrotra:
hi,
i have been reading a lot about connection manager on this board.
can anyone explain me why is there a need of connection manager.
if i bind the remoteImp of data class with the rmi registry. everone will be able to share the object.
and if i plan to use a lockManager for maintaining the lock records, then even there , there should be only one object of lock manager that muct be used by the remoteData class.
so whats the need of a connection manager
Karthik Guru
Ranch Hand

Joined: Mar 06, 2001
Posts: 1209
hi Rowan,
Thanks for pointing out the usefulness of the unreferenced intereface. This one is a nice feature i was'nt aware of.
Unfortunately i did'nt use it when i did my SDCD (some 7 months back!)
anyway i have a question for you.
I remember that i had implemented forced unlocking after a timeout.
I understand that in your case if the client crashes, you can take appropriate action and release the lock.
Did u have a forced unlock by any chance?
Do you think anything can be done, if the client chose to ignore the "lock-read-modify-unlock" sequence (ie ignored the unlock ("just a wierd possibility")).
How did you do client identification?
is your identification based on the passing objects between client and server?
OR did you implement Callbacks?
thanks!
Siddharth Mehrotra
Ranch Hand

Joined: Aug 21, 2001
Posts: 185
hi Rowan
well i was just looking at the unreference interface.
as per whats there in the docs , does that mean that the server will call the method once there are no more references to the remote object. So in that method i can make a call to remove the lock if that client had any on the databse.
I'll be trying this in a short while, but thought of posting the same.
adding on to it
supose i have the following files where do i have to implement the unrefrenced interface so that i can get accesss to that method
1>public interface CountRMI extends java.rmi.Remote, java.io.Serializable
(this has te business methods)
2>public class CountRMIClient
(this has just the call to lookup to get the remote object, i dont think there is going to be that unreferenced stuff here)
3>public class CountRMIImpl extends UnicastRemoteObject implements CountRMI
(this call implements the interface and has the body for the methods.)
4>public class CountRMIServer
( this is the place where i bind the object with the rmiregistry)
can u explain me how that unreference stuff happens in details, to the fact that which class is supposed to implememnt the interface, and so accordingly where the call will be.
[ March 19, 2002: Message edited by: Siddharth Mehrotra ]
Rowan Brownlee
Ranch Hand

Joined: Aug 07, 2000
Posts: 97
Hi Karthik,
Yes, unreferenced is an interesting feature alrighty - I heard about it while trawling the archives.
I'm still writing my project. I haven't used a forced timeout, but I suppose my use of unreferenced sort of does that anyway. I think the default time period is 15 minutes. Then unreferenced is called (and my implementation unlocks all outstanding locks applied by this Connection).
As for a rogue client trying to get around the lock/unlock sequence - that's one of the things I'm looking at by using Connections. (That's a good question about ignoring unlock - will have to have a think about that.)
In terms of identification, each client gets a unique Connection - which in itself can be used for identification. At this stage, I'm not needing to identify clients to control locks (though I'm yet to fully test this).
cheerio
rowan

Originally posted by karthik Guru:
hi Rowan,
Thanks for pointing out the usefulness of the unreferenced intereface. This one is a nice feature i was'nt aware of.
Unfortunately i did'nt use it when i did my SDCD (some 7 months back!)
anyway i have a question for you.
I remember that i had implemented forced unlocking after a timeout.
I understand that in your case if the client crashes, you can take appropriate action and release the lock.
Did u have a forced unlock by any chance?
Do you think anything can be done, if the client chose to ignore the "lock-read-modify-unlock" sequence (ie ignored the unlock ("just a wierd possibility")).
How did you do client identification?
is your identification based on the passing objects between client and server?
OR did you implement Callbacks?
thanks!
Rowan Brownlee
Ranch Hand

Joined: Aug 07, 2000
Posts: 97
Hi Siddharth,
Yes, that's my understanding about what happens with unreferenced. When the distributed garbage collection subsystem sees that there are no more remote clients for the object, the RMI system invokes unreferenced.
You can do lots of things within your unreferenced method. For servers, Pitt and McNiff write that "This interface is typically used for two purposes: to schedule idle-time activity of the server, and to allow a remote server to exit when idle... Many remote servers have things they could usefully do while there are no clients: cleanups, reorganizations, reports, and so on. The Unreferenced interface provides an ideal means of scheduling these activities. One particularly useful thing an unreferenced method can do is to schedule the Java garbage colector by calling System.gc." (Pitt and McNiff - The remote method invocation guide - p. 75-76)
All of this RMI and unreferenced is new to me. Prior to trawling the archives, I'd not thought about using a Connection as an intermediary between the client and database - but for my setup, it's proving pretty useful.
In my setup, Connection is the thing that a client uses to get the server to directly access the database. (A client has to obtain a Connection from ConnectionFactory, in order to access the remote database. Connection is remote, and ConnectionFactory is bound to the RMIRegistry)
For this reason, this is where I implemented Unreferenced. Since it's the Connection that asks the Server to apply and release locks (via LockManager), I'd want the Connection to know if it's no longer linked to a client (so I can get the Connection's implementation of Unreferenced to release any outstanding locks).
When I was thinking of using Unreferenced, I implemented it in several places, just to get an idea of what was happening. However, it was the problem of releasing stale locks that focussed implementation within the Connection class.

cheerio
rowan
Siddharth Mehrotra
Ranch Hand

Joined: Aug 21, 2001
Posts: 185
hi Rowan,
well i went through that url http://java.sun.com/products/jdk/1.2/docs/guide/rmi/Factory.html
and i'am pretty much convinced, and will be implementing the factory pattern in my design.
but then in that case for each user or client who logs on will ahve his own RemoteData Object to work on, well the scenario of synchronizing and all can be taken care of, but this will be the case, that ech client will have its own remote object to fiddle with
Rowan Brownlee
Ranch Hand

Joined: Aug 07, 2000
Posts: 97
Hi Siddharth,
I have each client getting their own Connection, but sharing access to a single data object (on my database server). Connection passes requests to the server. My lock manager looks after synchronisation for record locks.
Connection isn't working directly on a data object, but it is providing a mechanism to uniquely identify each client. It's also tracking locks for the client, and only allowing a client to unlock records it's already locked.
cheerio
rowan
Siddharth Mehrotra
Ranch Hand

Joined: Aug 21, 2001
Posts: 185
hi,
let me add some more points to this discussion.
1> The coonectionManager will ne the one that will be boubnd to rmiregistry, so it acts as a Factory class
2> It will be responsible for directing the calls to DataServer or the main program
3> If the above two points are fine then the connectionManager should should have multiple instances of the Server class so that it works as a Factory class. but i have tried a lot and everytime when i print the object that the connectionManager returns it has the same id, which means that the same object is being circulated again and again.
when i say multiple instances of server i mean RemoteDataImpl class
[ March 21, 2002: Message edited by: Siddharth Mehrotra ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Connection Manager