• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Network code "must"

 
William Smith II
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For my network code, I defined a DBConnection interface. I then define two implementing classes: a remote client and a local client; both of these classes implement DBConnection. The local client does not throw network related exceptions but does throw other exceptions (IOException, FileNotFoundException, etc).

The interface DBConnection must define all exceptions thrown, BOTH networked and local.

Now, in my business package, I call the network layer with the definition as follows:
DBConnection conn = new LocalDBClient(..);
-or-
DBConnection conn = new RemoteDBClient(..);

Since the code only knows that's it a DBConnection, and it abides by the contract provided by the DBConnection interface, I still need to check for network related exceptions, even in local mode.

For example:
DBConnection conn = new LocalDBClient(..);
try {
conn.read(8);
} catch(IOException io) {
throw io;
} catch(RemoteException re) {
throw re;
} catch(ServerNotActiveException sna) {
throw sna;
}

I have to do this because my DBConnection interface must define all exceptions utilized in my implementing classes of DBConnection.

Will this break the "must" of not using network code? Maybe I'm being too nervous about getting an automatic failure. As I see it, when using a LocalDBClient object, I'm not utilizing any network code. Am I too nervous?

Or is it better to use LocalDBClient conn = new LocalDBClient(..); And then not check for RemoteException and ServerNotActiveException.

In terms of expandability, I was hoping that someone could implement another DBConnection class and just plug it in with little change to the code.
 
Alex Belisle Turcot
Ranch Hand
Posts: 516
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm also scared of that..
In result I don't handle RemoteException specifically, I rather defined 2 other more precise Exceptions implementing IOException.

I catch those Exceptions + IOException.. the client code thus has no idea RMI exists..



What do you think of that ?

Regard,
Alex
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic