• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

BusinessService: interfaces and implememtations using RMI factory

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys,

I already read a lot of posts regarding this topic:

https://coderanch.com/t/479761/java-developer-SCJD/certification/design-cloudier#2361306
https://coderanch.com/t/547905/java-developer-SCJD/certification/Business-Service#2497723
...

And actually I am in the middle of testing my implementation but still I have some doubts. Maybe some of you could help me with the following questions.

Facts:
I need a RMI factory to identify clients. Meaning each client will get its own RemoteService instance from the RMI factory impl. Each RemoteService instance has its own Data(Implementaion of given interface) instance used as lock-identifier-object in the Data.lock() method implementation.

Code:



Question 1: Is it ok to call "UnicastRemoteObject.exportObject(this);" in the RemoteServiceImpl constructor to avoid RemoteServiceImpl "extends UnicastRemoteObject"?
Question 2: Is it ok that RemoteServiceImpl does actually not redeclare the service methods incl. throwing RemoteException. Instead just the interface RemoteService declares the RemoteException??? That feels quite strange to me?
Question 3: Overall design approach? Any hints or recommendations?

Thanks and regards

Martin

 
Bartender
Posts: 2292
3
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Howdy, Martin. Welcome to the CodeRanch!

Is it ok to call "UnicastRemoteObject.exportObject(this);" in the RemoteServiceImpl constructor to avoid RemoteServiceImpl "extends UnicastRemoteObject"?



You mean, on line 32 of your code? I don't think that is necessary because you are already doing so on line 58. I'm not sure though, because I didn't run this code...

Is it ok that RemoteServiceImpl does actually not redeclare the service methods incl. throwing RemoteException. Instead just the interface RemoteService declares the RemoteException??? That feels quite strange to me?



Declaring a method in an interface with a throws clause means that the implementations can throw the listed exceptions, not that the implementations have to throw them. It's not strange

Question 3: Overall design approach? Any hints or recommendations?



I couldn't take a very deep look at your code, but for what I've seen, I think you're fine!
 
Martin de Klaus
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Roberto,

Thanks for the quick reply.

You mean, on line 32 of your code? I don't think that is necessary because you are already doing so on line 58. I'm not sure though, because I didn't run this code...



Hmmm, Actually in line 32 the RemoteServiceImpl itself is exported.
In line 58 the RemoteServiceFACTORY is exported.

If I remove line 32, I recieve a java.io.NotSerializableException: RemoteServiceImpl. So I guess I need to export both, the RemoteServiceFactory and the RemoteServiceImpl. As far as I understand, the RemoteServiceImpl needs to be exported as well to enable the client to access the server via the Proxy(Stubs) pattern. To make the RemoteServiceImpl serializable doesnt make sense to me because then RemoteServiceImpl gets transported to the client and executed on the client side only without communicating to the server.

Declaring a method in an interface with a throws clause means that the implementations can throw the listed exceptions, not that the implementations have to throw them. It's not strange



That's obviously true . I was just wondering, if the actual class method does not declare the RemoteException, even if the interface did so, how will a error during execution of a remote method call indicated? Or is this somehow handled by RMI itself?



 
Sheriff
Posts: 11606
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Martin de Klaus wrote:Question 1: Is it ok to call "UnicastRemoteObject.exportObject(this);" in the RemoteServiceImpl constructor to avoid RemoteServiceImpl "extends UnicastRemoteObject"?


From an OO perspective it's in my opinion much better to call UnicastRemoteObject.exportObject(this); than extending UnicastRemoteObject. Why? If you extend a class, you are actually creating a more specialized version of the base class with more specific behavior. But your RemoteServiceImpl class doesn't do that I guess, it just wants to use the remote capabilities of that class. Another (obvious) reason (but for me less important than the 1st one): Java doesn't support multiple inheritance, so if you extend UnicastRemoteObject, you can't extend from another (business related) class.


Martin de Klaus wrote:Hmmm, Actually in line 32 the RemoteServiceImpl itself is exported.
In line 58 the RemoteServiceFACTORY is exported.

If I remove line 32, I recieve a java.io.NotSerializableException: RemoteServiceImpl. So I guess I need to export both, the RemoteServiceFactory and the RemoteServiceImpl.


I didn't implement a rmi factory myself, so no practical knowledge here. Just some (a little bit) common sense If you get an exception when removing the line, I think it's really needed But I wonder if the constructor is the right place to invoke that method I would move that call to the getRemoteService() method of the RemoteServiceFactoryImpl class. Seems more logical to me.


Martin de Klaus wrote:That's obviously true . I was just wondering, if the actual class method does not declare the RemoteException, even if the interface did so, how will a error during execution of a remote method call indicated? Or is this somehow handled by RMI itself?


Yes, that RemoteException is an RMI thingy In my SCJD days I had some fun playing around with all possible variants with Remote interface and RemoteException in method signature. Here you'll find the results.


Hope it helps!
 
reply
    Bookmark Topic Watch Topic
  • New Topic