• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Design Question

 
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)
 
Alan Morgan
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 225
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
reply
    Bookmark Topic Watch Topic
  • New Topic