aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes RemoteException Confusion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "RemoteException Confusion" Watch "RemoteException Confusion" New topic
Author

RemoteException Confusion

Conor O'Mahony
Greenhorn

Joined: Aug 08, 2005
Posts: 7
Hey,

DB is the interface that I have to implement.
I have a class called Data that implements it.

Then I have an interface called DBRemote that extends DB and Remote.
The interface is empty.
And DataImpl implements DBRemote and extends UnicastObject.

This is basically the same as the example in Max's book.

When I try to create Stub for DataImpl I get an error telling me that DB is not a valid remote interface as its methods must throw RemoteException.
This wasn't a problem in Max's example as the methods in his interface threw IOException from which RemoteException extends.

I obviously can't just replicate the methods in DBRemote and add the Exception as this is not allowed.

I'm a bit stuck at this point. Any thoughts to get me moving forward again ?

Thanks,
Conor
Daniel Dalton
Ranch Hand

Joined: Mar 20, 2005
Posts: 146
You will have to create a different interface that IS suitable for using via RMI and then adapt the Data class to it. Look up the adapter pattern or search this forum for posts regarding it. Here's one you might find useful:



Good luck!
Alan Morgan
Ranch Hand

Joined: Apr 18, 2005
Posts: 113
Hi,

I'm having a similar problem.

I used the Adapter pattern to get around it ok but a further problem has arisen.

I have a DataConnector class that has two methods getLocal and getRemote.
Both used to return DB which meant that the code throughout my application was the same regardless of whether I was connected remotely or working locally.

But now following the changes mentioned above , DBRemote no longer extends DB and so I can no longer just deal with DB everywhere.

Any thoughts on ways around this ?
Jan Groth
Ranch Hand

Joined: Feb 03, 2004
Posts: 456
hi there,

i built an adapter interface DbAdapter, extending Remote, but nothing else. it adaptees Data, which itself implemnts DBAccess.

DbAdapter is implemented by LocalDbAdapter and RemoteDbAdapter, the first one is used for local connection, the latter one - also extending UnicastRemoteObject - for network connection.

DataConnector returns a DbAdapter, either a LocalDbAdapter or a RemoteDbAdapter.

sorry, an uml diagramm would make reading way easier, but i hope it still makes sense to you.

greetings,
jan
Alan Morgan
Ranch Hand

Joined: Apr 18, 2005
Posts: 113
Originally posted by Jan Groth:
hi there,

i built an adapter interface DbAdapter, extending Remote, but nothing else. it adaptees Data, which itself implemnts DBAccess.

DbAdapter is implemented by LocalDbAdapter and RemoteDbAdapter, the first one is used for local connection, the latter one - also extending UnicastRemoteObject - for network connection.

DataConnector returns a DbAdapter, either a LocalDbAdapter or a RemoteDbAdapter.

sorry, an uml diagramm would make reading way easier, but i hope it still makes sense to you.

greetings,
jan


Hi,

My instructions include the following:

"Your data access class must be called "Data.java", must be in a package called "suncertify.db", and must implement the following interface:

package suncertify.db;
public interface DB................." goes on to list methods such as read(), find() etc

It seems to me that your DBAccess is the same as my DB here ?

I take from your comments above that DBAdapter includes the same methods as DBAccess except with the addition of RemoteException perhaps ?

If this is true then you are in effect using DbAdapter everywhere and at no point use the DBAccess interface.
And if this is the case is that ok to do ?

Hope I am making sense.

Thanks,
Alan.
Daniel Dalton
Ranch Hand

Joined: Mar 20, 2005
Posts: 146
Hi Alan -

Your data access class must be called "Data.java"


I think you could argue that the above doesn't say that you must have an instance of Data and directly call methods on it from the client. So... think about how you want the client program to access the database. This doesn't have to be constrained by the Sun supplied interface - all they say is that you have to provide an implementation of it called Data and not use the server code when running in local mode.

So how about you create a brand new interface called say "Database", and define client side methods like book() or whatever in it. Notice that RemoteException extends IOException. Now think about how to create a local and a remote implementation of Database using the facilities supplied by the Data class...
Jan Groth
Ranch Hand

Joined: Feb 03, 2004
Posts: 456
Hi Allen,

in principal, you are right:

Data & DBAccess is the class / interface combination sun requires.

I'm doing all the "work" in Data, but it is only accessed via DbAdapter.

DbAdapter is not like DBAccess just with RemoteException, it has many methods like DbAccess has (lock, unlock, read,...), but it also comes up with own methods, like getHeaderNames(), which is used by the gui to name the columns...

Usually, I would have changed DBAccess in a appropriate way, but as this is not an option, I'm solving my problem / needs with the adapter pattern. I'm going to document this, sure.

REgards,
Jan.
Alan Morgan
Ranch Hand

Joined: Apr 18, 2005
Posts: 113
Daniel and Jan,

I can see how I can make it work by not using the DB interface to access my Data class.
Jan's solution makes sense to me.

I was just concerned that not accessing the the information via the interface that you have to implement may lead to marks deducation or even automatic failure.

Alan.
 
 
subject: RemoteException Confusion