Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Initial design review

 
Fred Barnes
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,
Here is my plan of attack! Please comment and advise...
suncertify.db

public interface DataInterface
Includes all the public methods of Data, plus criteriaFind method.
All methods throws IOExceptions.
getRecord, find, add, modify, delete also throws DatabaseExceptions.

public class Data
Data is changed to implement DataInterface
citeriaFind is implemented while lock and unlock remain empty.
Datainfo, FieldInfo and DatabaseException remain unchanged.

suncertify.server

public interface RemoteDataInterface
Extends DataInterface and implements Remote.
public class RemoteData
Extends UnicastRemoteObject implements RemoteDataInterface and Unreferenced.
Has a static reference to Data and LockManager.
Implement lock and unlock methods.
public interface ConnectionFactory
Implements Remote
Has a getConnection method that returns a DataInterface. For local connection it will return Data and remote an instance of RemoteData.
public class ConnectionFactoryImpl
Extends UnicastRemoteObject and implements ConnectionFactory.
public class LockManager
Uses a HashMap to store locked records.
suncertify.client
public class DataModel extends AbstractTableModel
Implemented as a facade.
Contains the book, search and getConnection methods.
public class DataController
The controller class in my client side MVC.
Here I will implement all needed listeners.
public class DataView
Class containing all my GUI components.
Kind Regards
Fred
 
Omar Abdel Moniem
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Fred Barnes:
Hi Guys,
Here is my plan of attack! Please comment and advise...
suncertify.db

public interface DataInterface
Includes all the public methods of Data, plus criteriaFind method.
All methods throws IOExceptions.
getRecord, find, add, modify, delete also throws DatabaseExceptions.

public class Data
Data is changed to implement DataInterface
citeriaFind is implemented while lock and unlock remain empty.
Datainfo, FieldInfo and DatabaseException remain unchanged.

suncertify.server

public interface RemoteDataInterface
Extends DataInterface and implements Remote.
public class RemoteData
Extends UnicastRemoteObject implements RemoteDataInterface and Unreferenced.
Has a static reference to Data and LockManager.
Implement lock and unlock methods.
public interface ConnectionFactory
Implements Remote
Has a getConnection method that returns a DataInterface. For local connection it will return Data and remote an instance of RemoteData.
public class ConnectionFactoryImpl
Extends UnicastRemoteObject and implements ConnectionFactory.
public class LockManager
Uses a HashMap to store locked records.
suncertify.client
public class DataModel extends AbstractTableModel
Implemented as a facade.
Contains the book, search and getConnection methods.
public class DataController
The controller class in my client side MVC.
Here I will implement all needed listeners.
public class DataView
Class containing all my GUI components.
Kind Regards
Fred

Hello I just have one remark. Why RemoteData class and ConnectionFactoryImpl both extend UnicastRemoteObject.
Regards
Omar
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Fred
Originally posted by Fred Barnes:
public class RemoteData [...]
Has a static reference to Data and LockManager.
Static? As in "private static FooBar foobar"? Reconsider that -- this would limit you to a single database table, ruining most prospects of reusability for the server.
One fix would be to turn them into final instance variables, supplied via the constructor by the ConnectionFactory. Each factory instance would have one Data and LockManager. You could have as many factories as you'd want.
Looks fine to me otherwise.
- Peter
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Omar Abdel Moniem:
[...] Why RemoteData class and ConnectionFactoryImpl both extend UnicastRemoteObject.
The factory gives each client its own connection object to talk to -- that way, clients can be identified and unlock() implemented as required (see the javadoc). Both the factory and the connections it creates need to be remote objects, but only the factory is bound in the RMI registry; connections are private to each client.
If you want to read more, search this forum for the word "connection".
- Peter
 
Jawad Kakar
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To give each client its own connection, I do the following.

To give each client its own connection object to talk to Server I call the following code in a factory method.


By doing it this way I extend UnicastRemoteObject only once.
Jawad
 
Sri Addanki
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

But by doing this, each client will have its own instance of Data class and its own instance of lockManager class. is this ok?
What i feel is that each client should have its own instance of only lockManager and not Data.
Any comments Peter?
thanks,
sri
 
Jawad Kakar
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are 2 constructor, by calling

you get an instance of remote object only.
Jawad
 
Sri Addanki
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jawad Kakar:
There are 2 constructor, by calling

you get an instance of remote object only.
Jawad

Yes, thats right.
But when you instantiate a new RemoteDataServer object, then you are also creating a new instance of Data class for each remote object you've created. I am not sure if this is fine.
But here's your code:

thanks,
sri
 
Jawad Kakar
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sri,
Thank you for your reply, you are right that was a mistake and I fixed it.
Thank you
Jawad
 
Sri Addanki
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay...I'll come again. I think i'm confused too.
Hope this should be clear.

Each time you create a new instance of RemoteDataServer, you also are binding this.

So for 'n' clients there would be 'n' objects bound to registry. This shouldn't be like this.
Instead at any point intime, theres only one remote object bound to registry.
Each client should get a new connection, also each client should be bind to only one remote object in registry.
Hence you have to define a different class, like DataAccessRemote, which creates a factory of remote connection objects.
Thanks,
sri
 
Jawad Kakar
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Constructor which binds the remote object to the registry is called only once( when I start the server from command line) which is the following constructor

To bind the remote object to the registry.
The second constructor which no parameter the one you are talking about is called inside getConnection() method.
Therefor remote object is bind to the registry only once.
Jawad
 
Sri Addanki
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

The second constructor which no parameter the one you are talking about is called inside getConnection() method.

so, what exactly happens in this no args constructor?
thanks,
sri
 
Jawad Kakar
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a default constructor which is for getting different client id.
Jawad
 
Sri Addanki
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jawad Kakar:
This is a default constructor which is for getting different client id.
Jawad

Does this mean that the constructor will be empty
thanks,
sri
 
Jawad Kakar
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes
 
Sri Addanki
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Am i missing something here.
1. Server creates factory of connection Objects. Right.
2. What i feel is that each client should have one connectionObject through which it accesses the database.
3. So, what i feel is that the empty RemoteDataServer constructor should take the variable dataWrapper as parameter. So each client can handle its lock/unlock of records, with that variable.
thanks,
sri
[ December 26, 2002: Message edited by: Sri Addanki ]
 
Jawad Kakar
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
have a look at my getRemoteConnection() method, that is how I do it and it works fine for me.
I am still not done with the assignment, I might change it in future if I find a better reason to do so.
Jawad
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic