aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes RMI frustration Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "RMI frustration" Watch "RMI frustration" New topic
Author

RMI frustration

Robert Benson
Ranch Hand

Joined: Apr 04, 2010
Posts: 56
Hi,
This is the toughest part for me by far. I've been stuck on this for a long time.

I've searched the web for tutorials, previous posts etc and am working through the book (Andrew's).
The RMI concept seems straightforward, but I have spent a lot of time trying to implement my solution.

I am following DennysDVD model. This I have scrutinised many times.

I am following the same model for my project - URLyBird.

However, my factory class is giving problems:

N.B. I have extended the suncertify interface DB with one of my own methods. So I am using DB2.





The ide is marking the find method (and other DB methods) as an error with:

Multiple markers at this line
- implements suncertify.db.DB.find
- Exception RemoteException is not compatible with throws clause in DB.find
(String[])



Question 1: Why can the DennysDVD add throws RemoteException, whereas my project is not allowed to add throws RemoteException.
Question 2: What do I have to change in my project?


Thanks, Robert.


SCJP 6 , OCMJD 6 ,
http://www.robertbenson.ie/
Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2266
    
    3

Howdy, Robert!

Champion, by the exception you are having, I'd say that you didn't declare the RemoteException in the find method of your DB2 class.

Other than that, did you check this thread already?


Cheers, Bob "John Lennon" Perillo
SCJP, SCWCD, SCJD, SCBCD - Daileon: A Tool for Enabling Domain Annotations
Robert Benson
Ranch Hand

Joined: Apr 04, 2010
Posts: 56
Hi Roberto,
Thanks for getting back. Thanks for the link, I've read this thread but still cant figure out my problem. I tried your suggestion but it moves the same error down to where I use throws RemoteException in DB2.

I am confused because DennysDVD does not refer to RemoteException in the original interface method (DBClient):

The factory implementation of DennysDVD throws RemoteException.


However the original interface (DBClient) does not refer to RemoteEXception:


This works!

But when I try to implement my version I get:

Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2266
    
    3

It's just that IOException is a more general exception, since RemoteException extends IOException.

You can just declare IOException in your interface and throw RemoteException in your implementation.
Robert Benson
Ranch Hand

Joined: Apr 04, 2010
Posts: 56
Hi Roberto,
Thanks for your input. It's really appreciated. I tried that also:

This is an extract of the suncertify.db:



However I get this error on line 9 of the code extract.
Multiple markers at this line
- Exception IOException is not compatible with throws clause in DB.find
(String[])
- implements suncertify.db.DB.find


Robert Benson
Ranch Hand

Joined: Apr 04, 2010
Posts: 56
Hi,
Ignore my last post - I got so burried with this one that I got sucked in and was digging a hole.

I think I need to pull back, abstract and conceptualise

It looks as though I need to implement a business service level, and from the attached thread, I create interfaces that throw RemoteException methods. Should I:

1/ implement an exact copy of the suncertify interface. This would be better if the common interface were to change.
or 2/ must I add my own customised methods that throw RemoteException's. However, this moves away from the common interface.

Regards, Robert.
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5408
    
  13

I created a remote interface with 2 business methods (find and book), but you could also expose the methods from the interface you have to implement by creating an interface with similar methods as this interface throwing a RemoteException. So you'll create a thin respectively fat/thick client.


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
Robert Benson
Ranch Hand

Joined: Apr 04, 2010
Posts: 56
Hi Roel,
From looking at previous posts, and I've read a lot of them, the Business service seems to be one of the hardest concepts to grasp. People are coming at this from different angles .

I am trying to work through an example that you posted in a previous thread:




Q/ What is "MyBusinessService" in above code? Might be a typo.
Q/ How do your methods in Business service relate to the methods in the supplied interface (DB)?
Q/ It looks as though a new level has been created with methods that throw RemoteException. Is this changing the common interface ?
Should you stay faithful to the supplied common interface (DB) and not change it in any way?


Regards, Robert.
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5408
    
  13

Hi Robert,

1/ obviously a typo class LocalBusinessServiceImpl implements BusinessService is the correct code
2/ the methods in my BusinessService are just functionalities the business wants, like booking and finding rooms. These methods will use the methods in the supplied interface to do the magic
3/ it all depends on what you want to do: if you'll opt for a thin client (like I did), you will use a business service layer between client and Data class. This business layer will contain all business logic (prevent a booked room from being booked by another user) and in your client you will have 1 call to book a room: businessService.book(parameters);. If you opt for a fat client, you will have to create a similar interface to the supplied interface (e.g. just a copy where each method throws a RemoteException). And the business logic will reside at the client. You can not reuse the supplied interface, because you are not allowed to change it and your methods need to throw RemoteException otherwise you can't expose it through the RMI registry (I played a bit around to ensure what's necessary and what's not to be able to expose a class/interface with RMI, you can find it here).

And as a final remark: choosing between a thin or fat client is your own decision. Andrew Monkhouse (author of the best SCJD book on the market) has strong feelings to expose the methods of the supplied interface to the client (fat client approach). It was the start of a great discussion, which can be found here. But people passed with both approaches.

Kind regards,
Roel
 
Consider Paul's rocket mass heater.
 
subject: RMI frustration