• 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

B&S: Doubts in RMI

 
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.


--------------------------------------------------------------------------
 
Christian Nicoll
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic