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


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Design Question" Watch "Design Question" New topic
Author

Design Question

Alan Morgan
Ranch Hand

Joined: Apr 18, 2005
Posts: 113
Hey Guys,

This is a line from my requirements:
"Keep in mind that networking must be entirely bypassed in the non-networked mode".

It got me thinking about my Design.
Specifically the fact that the interface to my Data layer exists in my remote package.
The reason for this is best explained by describing my design:

"Your data access class must be called "Data.java", must be in a package called "suncertify.db", and must implement the following interface"
...goes on to describe DB interface.

So I have DB and Data so far.
Data is a singleton.

I created an interface - IDatabase - which extends Remote and has the same methods as DB but adds RemoteException to each method.
DatabaseAdapter and RemoteDatabaseAdapter both implement IDatabase.
The only difference between them is that RemoteDatabaseAdapter extends UnicastRemoteObject.

So to access my database an IDatabase object is used regardless of what mode I am in.


So in non-networked mode I still access my database using an interface from the remote package.
It obviously works locally and networked so does it matter.

I guess my overall question is probably in relation to my design.
Does it stand up ?

Thanks.
Seb Mathe
Ranch Hand

Joined: Sep 28, 2005
Posts: 225
Hi Alan,

I had the same doubts regarding Remote vs Alone mode.

Concerning your design, why do you have 2 classes implementing your IDatabase ?

If they both delegate calls to your Data class, and if you have created DatabaseAdapter only for the non-networked mode, would'nt it make more sense to have DatabaseAdapter implemeting DBMain and to use it in networked mode ? (delegating calls to your remote IDatabase in this case).

Instead of using your IDatabase in both modes, you should be able to use only a DBMain object. (assuming DBMain is the interface provided by Sun)


Regards,<br />Seb<br /> <br />SCJP 1.4
Alan Morgan
Ranch Hand

Joined: Apr 18, 2005
Posts: 113
Ok not sure if I got your meaning 100%.

I can't use the DBMain interface for both cause in the networked case it won't work cause it doesn't allow for the throwing of a RemoteException.

I could use IDatabase for network and DBMain for non-network.
But then my code is not the same depending on what mode I am in.
My code would have to change to take account of either using one or the other.

Hope it makes sense. It barely makes sense to me....getting late

Anyway thanks for the reply and do you get what I am trying to say above ?
[ October 27, 2005: Message edited by: Alan Morgan ]
Seb Mathe
Ranch Hand

Joined: Sep 28, 2005
Posts: 225
Not sure to understand your design 100 % too
Was I right regarding your DatabaseAdapter and RemoteDatabaseAdapter classes ?


I can't use the DBMain interface for both cause in the networked case it won't work cause it doesn't allow for the throwing of a RemoteException.


I think it doesn't solve your problem : Do you think that in alone mode, client has to deal with RemoteException ?

And in networked mode, what differences for the client between receiving a RemoteException or a DataException from the database ? (If I remember, DataException is your RuntimeException throwed in case of IOException).

I had in mind discussed here many times (see below), and which is, IMO, a good way do deal with your problem.


(Is there a problem with <code> tags ? Looks good when I type my message...)


Where :
# Service interface defines some methods.
# ServiceImpl is the major implementation (deals with database)
# RemoteService extends Remote, redefine Service methods with throws RemoteException clauses
# RemoteServiceImpl is the object bounded in RMIRegistry, and delegates calls to a Service instance
# RemoteServiceWrapper delegates calls to a RemoteService instance.

And client will only see a "Service" reference, which can be :
- a ServiceImpl (alone mode)
- a RemoteServiceWrapper (networked mode). In this case, RemoteException thrown by the RemoteService are re-thrown as "ServiceException" (RuntimeException)
Alan Morgan
Ranch Hand

Joined: Apr 18, 2005
Posts: 113
Sorry for late reply.

Originally posted by Seb Mathe:

And client will only see a "Service" reference, which can be :
- a ServiceImpl (alone mode)
- a RemoteServiceWrapper (networked mode).


I don't see how this will work exactly.
When you do Naming.lookup you are returned a RemoteServiceImpl which implements the RemoteService interface.
And this interface looks the same as Service anyway

But now are you not dealing with Service in local and RemoteService in networked mode..right ?

So you are still not dealing with the same interface in either case ?

I get the feeling I may be missing what you are trying to get at.

Want to make one more attempt to explain



[ November 02, 2005: Message edited by: Alan Morgan ]
Swapnil Sapar
Ranch Hand

Joined: Sep 29, 2003
Posts: 41
I'm also stuck in the same place. Seb, I do not see any relation between RemoteServiceImpl and RemoteServiceWrapper(Service). So how can we have RemoteServiceImpl object bound in the server type casted to Service interface at client side?

I tried another solution from here
But this also did not help much.

Has anyone found any other elegant solution to this problem where I can have common service refernce for both standalone and remote mode?

Swapnil
[ January 09, 2006: Message edited by: Swapnil Sapar ]

SCJP 1.4 (90%), SCWCD 1.4 (92%)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Design Question