File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Design and questions 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 "Design and questions" Watch "Design and questions" New topic
Author

Design and questions

Tomi Kus
Greenhorn

Joined: Oct 29, 2001
Posts: 5
Hi, guys.
There is short description of my current design:
1. interface DataInterface { all public methods of Data class throwing all Data's exceptions plus RemoteExceptions}
2. public class Data implements DataInterface {} with implemented criteriaFind() method and changed implemetation of deprecated methods to use platform's default encoding. That's it for local mode.
3. Server class, which launches ConnectionManager and HashMap for locks. No input parameters.
4. public interface ConnectionManagerInterface extends Remote {...}
5. public class ConnectionManager extends UnicastRemoteObject implements ConnectionManagerInterface {...}. has a method which returns a Connection object.
6. public class Connection extends UnicastRemoteObject{}. Creates an instance of RemoteData object and registers it.
7. interface RemoteDataInterface extends Remote, DataInterface
8. public class RemoteData extends UnicastRemoteObject implements RemoteDataInterface {
private Data data;
private Connection cnt;
Locks locks = Locks.getReference();
...}. Creates an instance of Data, based on path provided by client.
9. Locks is a singleton, and is implementing a HashMap. Has methods:
synchronized public void addLock(Integer rowNumber, Object connection){};
synchronized public void addLock(Integer rowNumber, Object connection){};
private boolean isLocked(Integer rowNumber){} - probably will be changed to private boolean isLocked(Integer rowNumber, Object connection){} - to avoid re-locking by the same client.
10. Client either creates an instance of Data for local mode or looks-up in registry for Connection factory, creates a connection and looks-up for RemoteData, created by that connection.
I am almost 100% sure that this design has a few week spots. For example, Locks is not good enough. It cannot handle locks for more than 1 table. Most likely i would have to abandon singleton pattern here. But it requires some modifications in design and i am not clear at the moment about those.
I would really appreciate your ideas and suggestions on my design, as i feel it's kinda messed-up.
Thanks
Tomi Kus
Greenhorn

Joined: Oct 29, 2001
Posts: 5
Lance,
thanks for reply.
You are absolutely right. I should take Remote out of that. Funny thing tough: i have tried to compile it and compiler did not complain at all. Tried to run application: same thing. Any thoughts?
In meantime i was thinking about my Lock management mechanism. Most likely i'm going to step away from singleton idea and go with factory implementation, which would produce 1 instance of Locks object per data file (table).
There is another issue i would like to ask your suggestions about. As far as my understanding goes, if i want to implement Unreferenced interface, i should implement it for ConnectionManager class, which is Connection factory. Am i right?
Also i was thinking about using Connection pool instead of Connection factory: when client connects to sever, he looks for Connection with no RemoteData object. If there is none, he creates Connection object, otherwise he receives Connection already created by client already disconnected. When client is done, RemoteData is destroyed and Connection returns to pool. What do you think about that? And how this would change my implementation of Unreferenced interface.
Thanks
Lance Finney
Ranch Hand

Joined: Apr 26, 2001
Posts: 133
I deleted my post because an interface can extend multple interfaces. So, that part of your design is ok, and I was wrong.
Tomi Kus
Greenhorn

Joined: Oct 29, 2001
Posts: 5
Lance, thanks again.
I went through few books to find out same thing
At least i will remember that for a long time now
anyway: could you guys address my questions regarding locks, Unreferenced interface and connection pool. I would really appreciate that
thanks
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Originally posted by Tomi Kus:
6. public class Connection extends UnicastRemoteObject{}. Creates an instance of RemoteData object and registers it.
With "registers it", do you mean the RMI registry? If so, you probably shouldn't register it there.
I'm not sure what the difference between RemoteData and Connection is (unless Connection is your factory for RemoteData objects, in which case it's arguably poorly named since all clients would share the same Connection object?)
Your lock manager should be a "per-Data Singleton" (an oxymoron, but you may get my drift). So whatever object holds the Data "master reference" is also the prime location for the lock manager reference; the two belong together.
- Peter
Tomi Kus
Greenhorn

Joined: Oct 29, 2001
Posts: 5
Peter, thank you for reply.
Probably i would need to explain my design a bit more clear, not just by providing fragments of code (writing something other than source code is a pain for me ).
My server launches ConnectionManager, which is factory for Connection object. Each client has a different Connection object. Connection creates RemoteData object, which is also different per client, and passes reference of itself (Connection) to that RemoteData. RemoteData is a "cornerstone" of my design. It has a reference to Connection(already mentioned), Data, and Locks and implements all the methods of DataInterface.
So each client has it own and unique Connection � RemoteData � Data combination. Probably i could change it to using just 1 Data object for all clients?
Reason i have Connection object between factory and RemoteData is:
synchronized public void addLock(Integer rowNumber, Object connection){};
instead of
synchronized public void addLock(Integer rowNumber, Object RemoteData){}:
Connection is much lighter than RemoteData. So if there were a lot of locks, it would save some memory. That is a difference between Connection and RemoteData. How reasonable is this part of design is subject of discussion
>>Your lock manager should be a "per-Data Singleton" (an oxymoron, but you may get my drift). So whatever object holds the Data "master reference" is also the prime location for the lock manager reference; the two belong together.<<<br /> I�m not 100% clear what exactly you meant, but hopefully we are talking about same thing. In my design: Locks object is unique per table. For example: <br /> Client1 calls: java FBN filepath1 � I will create Locks(filepath1)<br /> Client2 calls: java FBN filepath1 � I will return a reference to same Locks(filepath1)<br /> Client3 calls: java FBN filepath2 � I will create Locks(filepath2) and so on.<br /> Locks is a HashMap. Locking mechanism is record-level, as I want to implement my database locking as a loop of record lockings.<br /> >> So whatever object holds the Data "master reference" is also the prime location for the lock manager reference; the two belong together.<<<br /> That would be RemoteData. It has both.<br /> Now about:<br /> >> quote:

Originally posted by Tomi Kus:
6. public class Connection extends UnicastRemoteObject{}. Creates an instance of RemoteData object and registers it.

With "registers it", do you mean the RMI registry? If so, you probably shouldn't register it there.<<
The way in which my client runs is:
1. Looks-up for ConnectionManager reference
2. Calls method to create Connection (which creates RemoteData)
3. Looks-up for reference of RemoteData, as it uses something like FBN_GUI(DataInterface data).
Is there another way? I don�t see it at the moment.
I really appreciate your comments. Thanks.
Farouk Mohamed1
Ranch Hand

Joined: Jul 26, 2001
Posts: 113
hi
AS you are having one client to have one instance of data there is no need for thread synchronisation as Data object is no more a shared object and so all synchronisation and locking provided by data object is meaning less, by this mechanism you cannot handle suns requriement because even though there is a lock Manager he is doing nothing here as only one thread will have access todata object on one time and what we are intrested is to protect the real fiel data and your design will not handle it as which ever thread (data object has first update to file will do it).
Please have an think and reply.
Farouk
Tomi Kus
Greenhorn

Joined: Oct 29, 2001
Posts: 5
I have been working on project for dental practices few years back. Once i had a discussion with this dentist. And he said that one of the disatvantages being destist is that he cannot say "Oops" when working on his project (patient's mounth) But we are working here on SCJD, where D stands for developer, not for dentist. So i guess i can say "Oops".
Veeeeeeeeeery good point, Farouk. It was like eye-opener.
I'm already thinking about "slightly" different approach. I will describe my new design a bit later, because i do not want to rush myself into saying "Oops" this time
Thanks.
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
With one Data per client, not only do you not satisfy Sun's requirements, it also quite simply won't work. You cannot safely access a single file with more than one RandomAccessFile (unless you never update the file).
- Peter
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Design and questions