Meaningless Drivel is fun!*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes B&S: Doubts in RMI Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "B&S: Doubts in RMI" Watch "B&S: Doubts in RMI" New topic
Author

B&S: Doubts in RMI

Christian Nicoll
Ranch Hand

Joined: Mar 09, 2008
Posts: 106
Hi Ranchers,

Background
----------
I am working on my SCJD. Until now I've created a Data-Access-Layer and a GUI. Between both I've implemented a very small business layer (methods book, release, search). My GUI doesn't communicate directly with the Data-Access-Layer, it goes over the business layer. The application works quite fine, but until now it is all single-user. I've not create the server part.

I'm quite familiar with topics like Swing or the RandomAccessFile, but RMI and Sockets are new for me. Because I don't know any of these twos techniques, and most of you use RMI, I decided to make my first steps in RMI.

Server
------
I successfully created a very small test case with a Server (extends UnicastRemoteObject implements ServerInterface), a ServerInterface (extends Remote), a ServerMain and a ClientMain-Class.

My idea to "migrate" my actual application on RMI is to change the connection between my GUI and my Business-Layer, where I have an interface ServiceInterface. For that I want to create a ServerInterface that extends my ServiceInterface. By the way can this be a wise approach ?

The problem on this is that the ServerInterface has to add the RemoteException to all of my methods and if I do that than I break my contract with the ServiceInterface. So, I can't do this.

In Ken Krebs thread (thread) I read about one solution, but I don't prefer it:

Networking
========
Choosing RMI seemed to be a total no-brainer as it is so simple compared to using sockets. My entire networking code compiles to only 5,408 bytes of code. It consists of 2 classes, RemoteServices and RemoteServicesImpl. RemoteServices is an interface that extends Services and Remote. It has no body. This is possible because all the Services methods throw IOException and can therefore also throw a RemoteException. It's a nice trick that keeps things simple. RemoteServicesImpl extends UnicastRemoteObject and implements RemoteServices. It has 2 parts, the implementation of RemoteServices (i.e. the 2 Services methods) and static getServices methods that allow the clients to get a Services instance that is either an RMI server for the Network Server application functionality or its stub for the Network Client application functionality. The Services method implementations simply delegate all work to the ServicesImpl singleton. Since all of the locking occurs in a single method call in the Network Server's JVM, there is no need to worry about the RMI connection dieing in the middle of a locking operation.


I 've another idea. I'm not able to extend the ServerInterface from the ServiceInterface. But I'm able to do the contrary. What do you think about extending the ServiceInterface from the ServerInterface. That doesn't violate any rules. The only which I found not really fine is that my ServerInterface extends Remote, and if I extend the ServiceInterface from ServerInterface than I've an "IS-a" relationship between ServiceInterface and Remote. I don't believe that a ServiceInterface is a Remote-Object.

What do you think about it ? Is it ok ? Have you other ideas ?

Best regards
Christian Nicoll


SCJP 5, SCJD 5, SCWCD 5, SCBCD 5, SCJDWS 5
My SCBCD-Notes - My Hello World Webservice
Mary John
Ranch Hand

Joined: Sep 17, 2007
Posts: 109
I'm not able to extend the ServerInterface from the ServiceInterface. But I'm able to do the contrary. What do you think about extending the ServiceInterface from the ServerInterface. That doesn't violate any rules

Hi,

I am not an RMI expert, (just a beginner) and my assignment has reached the same status as yours. This comment may not be what you are looking for, but just a thought and clarification.
-------------------------------------------------------------------------
Can you explain why you said:
I'm not able to extend the ServerInterface from the ServiceInterface.
-------------------------------------------------------------------------
About Doing the reverse....ie......What do you think about extending the ServiceInterface from the ServerInterface

How do you think it will affect the statement in the assignment that the standalone mode should completely be independent of the network parts. It should not use any network related classes, as I understand.....or NOT? or is it just that the standalone should not use the actual network for functioning?

--------------------------------------------------------------------------


ServiceInterface and ServerInterface, seems to be confusing names IMO.
You could append Remote to the remote interface to make it easier for
those who read.


--------------------------------------------------------------------------


SCJP 5.0<br />SCJD working on it
Christian Nicoll
Ranch Hand

Joined: Mar 09, 2008
Posts: 106
Hi Mary,

Can you explain why you said:
I'm not able to extend the ServerInterface from the ServiceInterface.


Well, if my ServiceInterface declares some methodes with Exceptions like RecordNotFoundException, but no one RemoteException, than I'll go into a conflict. For my ServerImpl I need methods which throws RemoteException, so the result is that the ServerInterface has to add to each method of the ServiceInterface a RemoteException. If I do that than I violate against the ServerInterface server = new ServerImpl();contract with the ServiceInterface. I can only throw less Exceptions but not more in a child class/interface.

About Doing the reverse....ie......What do you think about extending the ServiceInterface from the ServerInterface

This is techniqual no problem as I wrote it in my first post.

How do you think it will affect the statement in the assignment that the standalone mode should completely be independent of the network parts. It should not use any network related classes, as I understand.....or NOT? or is it just that the standalone should not use the actual network for functioning?
Good question! Until now I'm not really sure about it. Perhaps I will use a switch (network and offline). In one case I use a type and in the other


ServiceInterface and ServerInterface, seems to be confusing names IMO.
You could append Remote to the remote interface to make it easier for
those who read.

Yes, this is absolute correct.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: B&S: Doubts in RMI
 
Similar Threads
Design questions
nx:All of URLy Bird1.1.3 about record lock
NX: stand-alone mode using RMI
nx:All of URLy Bird 1.1.3 about interface extends multiple interface
B&S Stub errors running in network client mode