Local mode - Remote mode

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

...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

Joined: Mar 28, 2002
Posts: 42

posted Apr 03, 2002 08:59:00

0

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.

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

Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher

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

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

Joined: Sep 19, 2001
Posts: 273

posted Apr 04, 2002 21:47:00

0

..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.

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..