File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes LocalAdapter and Remote Adapter Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "LocalAdapter and Remote Adapter" Watch "LocalAdapter and Remote Adapter" New topic
Author

LocalAdapter and Remote Adapter

Tommy Wan
Greenhorn

Joined: Jan 05, 2005
Posts: 14
I have been reading this forum a lot recently because I am trying to finalize my assignment. I found that many people talk about creating a local adapter and a remote adapter class, and they both in turns call DB/DBMain class to access data file.

I understand the local adapther and remote adapter design is trying to separate the network mode and non network mode.

But my design is different.

I have only one adapter, which calls Data class to work with data file. THis adapter throws RemoteException just to be compatible with RMI Code in Network Mode.

So in network mode, GUi calls this only adapter through RMI network code.
In local mode, GUI calls this only adapter directly.

Anything is wrong with this design?

According to the requirement, I should not use the network code when the codes work in non network mode. It does not say that I can't use the same model class - adapter for both modes.

Am I wrong?
peter wooster
Ranch Hand

Joined: Jun 13, 2004
Posts: 1033
I'm a big proponent of the use of two nested adapters. My project provided a DBAccess interface that is to be used to access the database. To meet this requirement I built Data class that implements this interface and is used by the server and the standalone client.

I use a DataAdapter interface that adds the RemoteException to all the methods in DBAccess. This allows me to use Data across RMI, but this is no longer LSP substitutable for Data. At this point my network access would need to use a different interface than my local access.

To get around this I defined a DataProxy class that implements the DBAccess interface and is an Adapter in the GoF object meaning of that word. This second Adapter creates a Proxy, which GoF defines as an Adapter that has an identical interface to its Adaptee.

All this lets me use a Factory Method to pick either a Data or DataProxy instance based on the mode and allows both the networked client and the standalone client to use the same DBAccess interface.
Tommy Wan
Greenhorn

Joined: Jan 05, 2005
Posts: 14
In my design, I have the DB as the interface provided by SUN. Data is the class implementing DB interface to do all data read/write/lock/unlock/delete/create operation.
I create DBAdapter to call Data class to implement only the methods needed by GUI, like book a hotel/return a hotel(extra)/search. This DBApdater adds RemoteException to all methods So I can use it across RMI.

In my GUIController class, it will determine to get a local instance or get an instance through RMI based on the network mode.Either case, the instance will be an instance of DBAdapter.

Could you tell me wether I am voilating the requirement to separate the network mode or not?
peter wooster
Ranch Hand

Joined: Jun 13, 2004
Posts: 1033
Originally posted by Tommy Wan:
In my design, I have the DB as the interface provided by SUN. Data is the class implementing DB interface to do all data read/write/lock/unlock/delete/create operation.
I create DBAdapter to call Data class to implement only the methods needed by GUI, like book a hotel/return a hotel(extra)/search. This DBApdater adds RemoteException to all methods So I can use it across RMI.

In my GUIController class, it will determine to get a local instance or get an instance through RMI based on the network mode.Either case, the instance will be an instance of DBAdapter.

Could you tell me wether I am voilating the requirement to separate the network mode or not?


You are using the "thin client" model. I don't agree that this actually meets the project requirements, but people have passed using it, so it's OK if you can justify it in your choices document.

The requirement to not use any networking applies to the use of actual RMI or socket methods. I don't believe that declaring that a method throws RemoteException would be considered a violation.
Tommy Wan
Greenhorn

Joined: Jan 05, 2005
Posts: 14
Hi Peter,

Thanks for clarification.
Tommy Wan
Greenhorn

Joined: Jan 05, 2005
Posts: 14
Hi Peter,

You are using the "thin client" model. I don't agree that this actually meets the project requirements, but people have passed using it, so it's OK if you can justify it in your choices document.


what do you mean this doesn't actually meets the project requirements?

I finally finished testing and fixing my lock logic. This adapter stuff is the last one I need to confirm.

Could anybody else kind enough to offer some insights here?
I really appreciate it.
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11523
    
100

Hi Tommy,

what do you mean this doesn't actually meets the project requirements?


Actually, Peter stated that he doesnt agree that this actually meets the project requirements (emphasis is mine). That is, it is Peter's personal opinion.

I happen to agree with Peter's opinion (and again, this is a personal opinion ). If you are interested, you can read the really long topic "Should lock methods be callable by the client" which discusses the reasons for and against thin client solutions. The final conclusion (if you can call it a conclusion) was that either choice could be OK - you just have to justify it in your choices document.

Regards, Andrew


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: LocalAdapter and Remote Adapter