• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Remote Data and Data Class

 
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all
In my design the Connection Factory object registered with the registry and creates instances of remote Data class.
My doubt is every remote data class will have a new Data class in it. Effectively every client will have its own Data object to read the db file.
So only one thread will use Data class and it is no longer a shared object, at one time only one thread will access the data in it so where is the locking confusion
Very urgent
Please reply
Farouk
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Connection factory has the instance of the single database. When your client calls getConnection(), the connection object created by the factory is passed a reference to the database instance in the factory. Then all connection objects have a reference to the one and only one instance of the database
Mark
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Mark Spritzler:
[...]When your client calls getConnection(), the connection object created by the factory is passed a reference to the database instance in the factory. [...]

NB: if you choose to implement your connection class as an inner class, the reference to the factory and thereby the database is created implicitly.
- Peter

[This message has been edited by Peter den Haan (edited October 25, 2001).]
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmm, not sure if I understand what you mean Peter. In my factory, there is an instance variable that points to the data class, when getConnection is called I return:
return new RemoteConnection(data);
data being the instance variable.
Is that an Inner Class?
Thanks
Mark
 
Farouk Mohamed1
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
Sending Database location i believe there is two options
1. Pass Database location from client to server.
or
2. Tie the database location details with the RMIServer.
I was using the first option of client able to select the database present in any location and getting a connection by Naming look up will return you a RemoteConnecion(registry entry) class and then i execute a getConnection(dblocation) to the RemoteConnection object to create a RemoteData class which was creating for me a new Data instance for the specified Datalocation so i had each thread using one Data object
So according to your thaughts
RemoteConnection implements ConnectionInterface and has a Data instance, i understand by this we will have only one object wrapper around the database file, but to create a Data Instance in the remote Connection i need a database location.
I cannot do this as i cannot pass a argument when i look up.
Can I still use the getConnection(dblocation) to pass database location to server?
I am still consfused please help me, Here is my redesign
 
Peter den Haan
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Mark Spritzler:
Hmm, not sure if I understand what you mean Peter.

It's not important. An inner class gets an implicit reference to the instance of the enveloping class it is associated with. So if a reference to the Data object is, say, stored in an instance variable on ConnectionFactory, and Connection is an inner class, then Connection can directly access the Data object.
Some people hate inner classes. Provided they are sufficiently "thin" I find them a useful way to realise dependent objects. As my Connection class contained literally no data and virtually no code, just a pile of methods that delegated the hard work to Data and LockManager, I used an inner class.
- Peter
 
Peter den Haan
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Farouk, I assume you now see that it's a bad idea to have a Data instance per client.
The scheme presented doesn't prevent you from doing the filename look-up thing. But your ConnectionFactory will have to keep track for which paths it has already created a Data instance (and perhaps a LockManager). If there already is a Data/LockManager, it needs to return a Connection tied to the existing instances.
In fact this really wants to be split into two classes: a RemoteDatabase that encapsulates a single Data and a LockManager and can create Connections on demand, and a DatabaseFactory that will produce a RemoteDatabase for a given file path, returning an existing instance or creating a new one as needed. As a convenience DatabaseFactory might implement a getConnection() method that is no more than getDatabase().getConnection().
- Peter
 
Farouk Mohamed1
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Peter
Thanks for your quick reply. yes now I do understand that we dont need separate Data Class object for each client and what we have to provide is a wrapper of one single Data Instance for each client that is Remote Data in my case and this Remote Data is created by a Remote Connection registry object essentially a factory for Remtoe Data.
Sorry I dint get the point of your explanation previously can you please use my class names.
Here is my new Design
1. RemoteConnection(registry Object, essentially a server connection factory) implements a ConnectionInterface has a single Data Instance (data).
methods: getConnection() which returns a new RemoteData(data)
2. Lock Manager does not know which database it is managing it only deals with request from RemoteData class to lock abnd unlock records. At the moment it is a singleton and i think it is wrong and it should be associated with Data object of RemoteConnection.(Your comments plase).
You are rigth the previous design of Lock manager is dependant on RemoteData which has one Data class at the moment.
So lock manager was associated with Data indirectly.
What I dont udnerstand still is the connection Factory (RemoteConnection) has a reference to Data instance and to create one we need to pass databaselocation. How can i do that ,i know i can allow client to select the path of the file but how can i pass it to the RemoteConnection when he does a Naming look up thro client connection factory.
Please peter
Farouk
 
Peter den Haan
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you don't let your client determine the database location, this looks just fine - forget what I said about DatabaseFactory. Your RemoteConnection object encapsulates a single Data and hands out connections to it. Fine.
The lock manager should not be a singleton - you need a lock manager for each RemoteConnection/Data. Remember that the database code is for re-use - another project might well need three tables, i.e. three RemoteConnection objects, three Data instances and three lock managers.
If, on the other hand, you want to allow the client so select the path of the file, you need another factory layer: a factory that takes the file path and returns the RemoteConnection factory for it. If a RemoteConnection has already been instantiated for the path (i.e. the file is already open) then the existing instance is returned. Else a new RemoteConnection factory is instantiated. You would bind this factory-factory in the registry instead of RemoteConnection itself. It's arguably a bit outside the scope of the project though.
- Peter

[This message has been edited by Peter den Haan (edited October 27, 2001).]
 
Farouk Mohamed1
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello peter
Thanks for your reply,and i take your advice, I am approaching the above said logic of having a RemoteConnectionsFactory registered with the registry and maintains a hashtable of RemoteConnections using dbname location as a key and a RemoteConnection object as a value.
In the getConnection(Dblocation) method of the RemoteConnectionsFactory checks the hastable to see whether it has a remote connection for the give databaselocation or not, if the there is no remote connection for a database location then it creates a new remote connection else gives back the existing RemoteConnection.
A RemoteConnection has 2 attributes one is the Data object associated with the connection and another is the LockManager.
So by this design the client can select a database location and operate it in either remote mode or localmode.
The remoteConnection has a getConnection method which returns a RemoteData one for each client using the existing single instance of Data object of RemoteCOnnection.
Is this design ok? please your comments and I dont know how to associate a lock Manager with a RemoteConnection and RemoteData.
I have changed the constructor of lockmanager to have Data object to create it but i am not using the data object inside Lock manager pelase can you tell me how to link the lock manager with RemoteData and RemoteConnection please.
Farouk
 
Farouk Mohamed1
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Peter please your comments
Farouk
 
Peter den Haan
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Farouk,
Looks fine to me. The only point of (possible) concern is local mode - it's not entirely clear to me how you are implementing that, just take care that you follow Sun's instructions that you do no networking whatsoever in local mode.
Regarding your question, in my design the remote data object itself contained the glue between LockManager and Data. This made the whole affair very loosely coupled - LockManager had no awareness of Data and vice versa. It might work in your design as well.
- Peter
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic