aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes B&S: Why not use same class for Local and Netowk mode Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "B&S: Why not use same class for Local and Netowk mode" Watch "B&S: Why not use same class for Local and Netowk mode" New topic
Author

B&S: Why not use same class for Local and Netowk mode

Alain Dickson
Ranch Hand

Joined: Dec 08, 2008
Posts: 53
Hi Ranches, need your help

From Requirements:
The operating mode is selected using the single command line argument that is permitted. Architecturally, this mode must use the database and GUI from the networked form, but must not use the network server code at all.


To make my code and life simple, I need an answer to a question:

LOCAL MODE:
:- Can I use the Data class which extends SUN's interface in local mode as it is.
How I am thinking of doing it: Import the Data class on client side and use it as regular local object. NOT accessing it through network mode(which requires registering the object on serverside and lookingup on client side).

NETWORK MODE:
Create instance of Data class on server-side, BUT this time it is registered with RMI-registry and on client side we can perform registry lookup and use remote object.

I am viewing the DATA class as designed for API of this applicaiton and can be used by the server and client both AND it becomes server code only when and instance is created on severside.

What do you say..

Many thanks,
Alain

[ December 27, 2008: Message edited by: Alain Dickson ]

[ December 27, 2008: Message edited by: Alain Dickson ]
[ December 27, 2008: Message edited by: Alain Dickson ]
Alecsandru Cocarla
Ranch Hand

Joined: Feb 29, 2008
Posts: 158
You must be able to throw RemoteException from every method of Data. If the SUN interface allows you to do this (for example the methods throw IOException) then it should be possible. Your Data class should implement an interface which extends both java.rmi.Remote and the SUN interface, and it should also extend UnicastRemoteObject.

However, I'd say this is not a very nice choice, because it makes your Data class depend on the server's implementation. If you decide sometime later that RMI is not desirable anymore, you have to change the Data class. It's better to keeps concerns separated.

About your "must not use the network server code at all" concern, I'd say it's ok as long as you don't start the RMI registry in non-networked mode.
[ December 27, 2008: Message edited by: Alecsandru Cocarla ]

SCJP 1.4 100%
SCJD 99.5%
Bod Toki
Ranch Hand

Joined: Sep 01, 2006
Posts: 95
Yes you can...
but, would you want to bother your local module with network-related code?

Maybe you'd be better of with a local-class and then a remote-class that delegates calls to the local-class, decorating it with all sorts of network-related code.
Jeffry Kristianto Yanuar
Ranch Hand

Joined: Oct 01, 2007
Posts: 759
In the local mode, my GUI application use the class that implements the interface.

In the networked mode, the class that implements the interface is encapsulated in my networking code.

That's how I done.

Good Luck !!!

Jeffry Kristianto Yanuar (Java Instructor)
SCJP 5.0, SCJA, SCJD (UrlyBird 1.3.2)

"Professional certification is the battle between formal education and informal education. So far, the formal one is winning"
Alain Dickson
Ranch Hand

Joined: Dec 08, 2008
Posts: 53
Thanks! Alecsandru, Bod & Jeffry

Alain
 
 
subject: B&S: Why not use same class for Local and Netowk mode