Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Local / Remote Connection

 
Chris Popz
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[URLyBird 1.3.3]
Some help is desired :

- As a requirement I have Data.java implementing the DBMain.java interface.
- In order to use rmi I have wrapped the DBMain.java interface into an interface I call DBMainRmi.java (this interface is identical to DBMain.java with the addition of having support for throwing RemoteException). As a complement I have have a class, DataRmi.java, that implements DBMainRmi.java. This class has an instance of Data.java and just delegates method calls to the Data.java class, as:



Finally I have registered DBMainRmi.java with the RmiRegistry.

Now, I been searching the forum for an idea of how to run the appliction in alone vs. remote mode... and alot of threads ends up with "use the factory pattern". What I haven't "gripped" is what I need to have on the "client side" in order for my design to work...

Any ideas?

Regards,
Chris
 
Mihai Radulescu
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hallo Chris,

Try something like.

Local mode : GUI Client -> local adapter -> Data
Net mode : GUI Client -> Net adapter -> Data

The net and local adapter implements the same interface - the adapter, the UI client sees only this interface, so you can run it with a local or with a remote adapter. You can have a factory which is responsible for the adapter build process - but this is up to you.


Regards M.
 
Lucy Hummel
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mihai,

I did it that way and it successfully works

Local mode : GUI Client -> local adapter -> Data
Net mode : GUI Client -> Net adapter -> local adapter -> Data

To stress out the net adapter calls the local adapter
 
Bod Toki
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I used something like:
Data -> DataService -> Client
DataRemote -> DataService -> Client
(DataService has a handle to both a Data and a DataRemote but only initializes one).

depending on whether the DataService is initialized as local or as remote it transfers the Client calls to either Data or DataRemote using the if statement.

What do you guys think?
 
Chris Popz
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lucy:

I did it that way and it successfully works

Local mode : GUI Client -> local adapter -> Data
Net mode : GUI Client -> Net adapter -> local adapter -> Data

To stress out the net adapter calls the local adapter


Does the local adapter and net adapter implement a common interface?
As i understand you register the net adapter with the rmi registry...?
Can you please explain "To stress out the net adapter calls the local adapter"...?

Regards,

Chris
 
Lucy Hummel
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Chris,

Local and Net Adapter implement the same, common interface. So that is similar to what Mihai proposed.

Because of re-use I just delegated my remote calls to the Local Adapter. To stress out: I did not want to rewrite all Data calls again. Just being lazy.

The Net Adapter is remote and it registers itself to Naming Service.
 
Mihai Radulescu
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys

The adapter is a interface and it has two implementations (specializations)
a local and a remote one. The client see only this interface so it can serve different adapters.

Lucy,
Yeep, thats the spirit (you can read I choose the same solution), the net adapter encapsulate a local adapter and delegate all its task to this one - the net adapter alone(without the local adapter) only transports information.

Regards M.
 
Chris Popz
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok - I been playing with something like that!
My desin suggestion is something like this:


The SuperInterface is like DBMain/DBMainRmi + additional methods used in Data/DataRmi. Each method in the SuperInterface throws Exception (only).
The next step is to get a local or remote connection from a connection factory, which instantiate from my controller class. Now, the catched exceptions in my controller class must be of type Excpetion...
Do you guys think this is a valid design, or am I breaking any contract as you see it?

Regards,

Christian
[ April 13, 2007: Message edited by: Chris Popz ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic