Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

RemoteException Problem...

 
Song Jing Lim
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got a interface (a.java) that got a method (x) which will throws a custome exception (FileNotFoundException) only.
Well, another interface (b.java) that extends Remote and above interface (a.java).
Then my concrate class will implement b.java as RMI implementation class. Well problem came out, the method (x) can't throw RemoteException because method (x) at interface a didn't throw RemoteException (only and only FileNotFoundException).
note: method x at interface a are restrict to not allow be change (method x can only throw FileNotFoundException).
note; FileNotFoundException, I extend from Exception
Any ideal how I can solve above problem???
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well by the nature of the Remote, if you extend remote, then you must through RemoteException in your public methods.
If this class is implementing another interface, then that interface either has to throw RemoteException, or a super class which leaves Exception.
Personally I had my interface throw Exception, then in my implementation classes I can now throw any type of Exception that I like.
Mark
 
Song Jing Lim
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is the interface is define by Sun and I can't change it as I had confirm by Sun Education Worldwide Manager.
For example one of the method at DBMain.java (interface) will have the signature:
public String [] read(int recNo) throws RecordNotFoundException;
The remote implementation class need to throw the RemoteException else can't be compile by RMIC.
Any ideal I can do?
I had try to extends RecordNotFoundException from Exception and IOException but both also not work.
Any help on that?
Thx
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 11855
187
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Song Jing
From when we were discussing this in this thread, we had gotten to the point where:

Andrew: Write Data.java to implement the interface as provided by Sun, without changes.
Once you have done that, you can start thinking about what methods you want to provide to clients, and what exceptions need to be thrown. Then create your own interface to define those methods and those exceptions.
Song Jing: So the actualy data access class is create by me which is either using inheritan (extend) or using composition from the class requrie by Sun. So like wrapping class.
ie. my 'real' data access interface class call papter.java and implement by database.java. Inside database.java I can either extend the data.java or create a private object of data.java for composition.

So you have interface DBMain, and you have implemented it's methods in your class Data.java
Now you are trying to develop another class to provide the remote access to the Data class. For the sake of having something to talk about, I am going to call this RemoteData (you can call it anything you want). This is the class that is wrapping Data class as we discussed earlier.
And your question is: how can the method read() in RemoteData throw RemoteException, when it is not declared to throw that in DBMain?
However there is nothing to say that RemoteData has to implement DBMain.
DBMain is the interface that you have to implement in order to create the Data class. Any class that needs to get direct access to the Data class (such as RemoteData, or Sun's automated testing tools) can write to the DBMain interface.
But you are not forced to provide those same methods to remote clients (we were in the old assignment, but it does not appear to be a requirement of the new assignment). You could decide to provide the same methods (and to be honest, I dont see any reason not to), but you dont have to.
So the question then becomes: what methods do you provide to your remote clients, and how do you let them know?
Tackling these in the reverse order: how do you let other programmers know what methods they can use? Simple: create an interface (let's call it RemoteReference). Then RemoteData can implement RemoteReference, and your remote clients can code to the RemoteReference interface.
Now, if you decide that the read() method in RemoteReference should throw RemoteException - go right ahead: you own RemoteReference interface, so you can do that without any problems.
Is this making sense?
Regards, Andrew
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this making sense?

Makes sense to me.
Mark
 
Song Jing Lim
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ya...
Thx again
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic