• 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

Local mode - Remote mode

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi folks,
To keep the remote-local issue as simple as posible I'm thinking of a design, something like this :
ServerSide :
-----------
Let Data implement RemoteDataInterface, which contains all Data's methods and extends RemoteInterface.
Also let Data extend UnicastRemoteObject.
Obviously, it's a Data object your binding to the registry.
As you can see, there's no DataInterface nor a RemoteData object like some of us explained in other threads. So no distinction.
ClientSide
----------
One DataProxy object implementing RemoteDataInterface containing 2 ctors; one for local mode, the other for remote mode.
DataProxy also contains a RemoteDataInterface object that gets initialized in one of the ctors. In local mode I would initialize it with a Data object while in remote mode the corresponding DataProxy ctor makes use of the RMIRegistry to obtain a pointer to the remote Data object.
Dataproxy delegates all its method invocations to the RemoteDataInterface object.
Seems to work just fine, but since I'm not a OO wizard I'm hesitating to use this implementation.
I have to say I don't feel comfortable that all clients have to deal with the RemoteException, even in local mode.
I need your advice guys !
Thanx
 
Andrew Collins
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Advice of you girls out there is also more than welcome, ofcourse
 
Ranch Hand
Posts: 273
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
...I have to say I don't feel comfortable that all clients have to deal with the RemoteException, even in local mode.
Hello Andrew:
Let me explain you, how did I handle this in my project?
I needed a reference to access the database from my Client class. If user is in the local mode the Data class must be used; if user is in the remote mode the RemoteData class must be used. I wrote a new interface that extends java.rmi.Remote. Included all methods from the Data class except the lock and unlock methods. I felt that the lock and unlock methods are not required while the program is in local mode. My new DataInterface can throw DatabaseException and Exception. It does not throw RemoteException; however it extends Remote. I intentionally excluded RemoteException from this interface because running the program in the local mode does not need to throw RemoteException. Throwing generic 'Exception' is enough in this situation. Now Data class implements DataInterface.
I added RemoteDataInterface which extends DataInterface in the suncertify.server package. The RemoteDataInterface has three methods, (1)lock, (2)unlock, and (3)lockRecordOrDatabase. The RemoteData class that is in the suncertify.server package implements RemoteDataInterface. The RemoteData class object has incorporated the special functionalities of lock, and unlock plus whatever it was in the DataInterface class. All the methods in the RemoteData class throw RemoteException. The client class has a reference of DataInterface (abstract) to hold the Data or RemoteData class object. Actual object is being created from derived one) at the implementation.
There are multiple ways of doing same things. I am not saying this is the good one. At lest it will give some light on this issue how to look at it.
Hope it is some help. By the way, I am a guy not a pretty gal. -Bal
 
Andrew Collins
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Thanks for your quick reaction.
Your explanation is very clear, but the point I'm trying to make here is, is my design Ok ? Would you guys ( and gals ) dare to submit this or am I breaking every possible OO rule here ?
I was just trying to avoid what you have been explaining here.
Please don't get me wrong !! I wanted a design as simple as possible, that's all. I really do appreciate your help on this, pal.
 
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Andrew,
The only thing about your proposed design that I would feel uneasy about is having the Data class extend UnicastRemoteObject. That just doesn't seem like a job for the Data class. But, if you feel like it is appropriate and can defend that choice, then go for it.
Michael Morris
 
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
Serverside is breaking all the OOP rules. There is no seperation between Data and server, and RMI, and you will also find the extensibility is therefore compromised.
On client side

DataProxy object implementing RemoteDataInterface


Here you are telling readers of your code this Proxy is only for remote access, since it implements the RemoteDataInterface. But then you state that for local mode you are only going to pass the Dataclass. Is there a contradiction here?
Think of ways of spliting responsibilities apart so that each class does one thing and one thing only, just like each method should have that ideal. If you have a method that adds two numbers, it shouldn't also have to provide the two numbers for you, Or The rules of multiplication in it, just in case we have a second parameter that states, add/subtract or multiply.
Hope that helps.
Mark
 
Andrew Collins
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks to all of you.
Ok, I studied Bal's design. Seems like Mark's tips and tricks are all present here.
There's only one question to you Bal : why does your DataInterface extends Remote, wouldn't it be better to let RemoteDataInterface extend DataInterface and Remote ? Or am I missing something here ?
Greetz
[ April 03, 2002: Message edited by: Andrew Collins ]
 
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

why does your DataInterface extends Remote, wouldn't it be better to let RemoteDataInterface extend DataInterface and Remote ? Or am I missing something here ?


Not sure if Bal's reason is the same as mine, but they are both valid either way since Bal did great on his assignment
My reason is that I did not have a RemoteDataInterface. Therefore my DataInterface was used by both the local and remote implementations of the Interface, and for the local it doesn't hurt it to also have it being a remote object.
Mark
 
Bal Sharma
Ranch Hand
Posts: 273
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
..one question to you Bal : why does your DataInterface extends Remote, wouldn't it be better to let RemoteDataInterface extend DataInterface and Remote ? Or am I missing something here ?
Hello Andrew:
Goal is the same either you take Mark example OR mine. If I am not mistaken, Mark used DataInterface for both local and remote implementations. I did little extra work to distinguish remote and local implementation.
Why my DataInterface extends Remote? I needed a handle to access the database from my Client. My RemoteDataInterface extends DataInterface. Data class implements DataInterface. RemoteData implements RemoteDataInterface. In other words, I was able to use DataInterface to hold Data OR RemoteData objects. I do not have to worry which one is being created.

Your question as I have understood, If I had RemoteDataInterface extend DataInterface and Remote. My answer is, first of all in JAVA I could not extend from more than one supercalss. So, it is not possible to extend from two supercalsses. Second, If my DataInterface would not extend Remote, then it would not be a Remote object. I could not use DataInterface to hold both Data and RemoteData object.
Hope it helps.
 
Andrew Collins
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks guys, I get your point.
Bal, my multiple inheritance idea was applied on interfaces
Allow me to present you my design, I'd appriciate your wise words :
db package
----------
- all classes provided by Sun
- DataInterface extends Remote throwing Exceptions
- LockManager nested within Data
- Data implements DataInterface
server package
--------------
- RemoteDataImpl extends UnicastRemoteObject implements DataInterface throwing RemoteException, DatabaseException, IOException : wraps a Data object
- Server : binds RemoteDataImpl to RMIRegistry
client package
--------------
- LocalDataImpl implements DataInterface throwing DatabaseException, IOException : wraps a Data object
- DataProxy implements Data throwing Exceptions : has 2 ctors : 1 for local, 1 for remote. Wraps LocalDataImpl or RemoteDataImpl depending on choosen ctor
- ClientData : facade for the DataProxy : 2 methods : book() and search()
Andrew
[ April 05, 2002: Message edited by: Andrew Collins ]
[ April 05, 2002: Message edited by: Andrew Collins ]
 
Andrew Collins
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi folks,
can you please give me your opinion on the design stated in the previous message ?
Thanks
 
Ranch Hand
Posts: 560
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good start. I would suggest the following:
1) RemoteException extends IOException. So I would eliminate RemoteException if you are going to declare both.
2) My server also extends UnicastRemoteObject
3) My client design is somewhat elaborate using Mediator pattern. I am using JTabbedPane with a controller for every JPanel.
 
Andrew Collins
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sai !
I appreciate your input, thanks buddy
 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have been reading a bit here and I'm currently working on the db and server part. My design of these are almost identical to Andrews, except I have created a new subclass of Data called BookingData which deals with the more spesific functionallity of the application, leaving Data as a more generic "database". My Data class implements DataInterface which extends Remote, and my BookingData class implements the BookingDataInterface, which again extends DataInterface. This BookingDataInterface is then used as the remote interface in the rmi part. Then I use a DataFacade as the remote implementation of the interface, which just keep a private variable of type BookingData and just pass the method calls on to this object.
Any comments on this? I'm really unsure about this design..
 
Bal Sharma
Ranch Hand
Posts: 273
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Andrew:
It sounds to me good. Keep it up. -Bal
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic