• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Remote /Local mode

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,
I used the factory pattern to handle local / remote mode.i've one remote interface which has all the public methods of the data class.This interface is implemented by both the rmi client and rmi server.So both the client and server are remote objects.
I've a factory which instantiates the rmi client or rmi server depending on the mode.The GUI makes method calls on the rmi client in case of the remote mode and for local mode ,the calls are directly on the rmi server.
this how it looks :

interface xyz extends remote
{
}
class rmiclient extends UnicastRemoteObject implements xyz
{
}
class rmiserver extends UnicastRemoteObject implements xyz
{
}
class factory
{
getclass(boolean local)
{
if(local)
{
return new rmiserver();
}
else
{
return new rmiclient();
}
}
The problem with this desgin (i dunno know wether it's a problem) is that stubs/skeletons come into play even in local mode.
would appreciate a healthy run down of this design !
cheers
pac
 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Pac,
Your design is pretty much ok. However you're making a mistake thinking that your Local Data access implementation must be an RMI object as well. You can still enjoy the benefits of having a single interface to access both the Remote and Local implementations without making both remote objects.
Instead of using :
class rmiclient extends UnicastRemoteObject implements xyz
You should use:
class rmiclient implements xyz
Infact if you do it this way the rmiclient has actually no RMI links and doesn't need to have any stubs/skeletons. Infact the methods in rmiclient won't even have to throw RemoteException!! This sounds strange but it's true since implementing classes are only obliged NOT to throw MORE exceptions than are defined in the interface. They are not forced to throw all the interfaces exceptions. Thus your local class will be quite 'clean'.
You might want to rename your classes along a local - remote lines as against the client - server lines which you're using, as it kind of creates some confusion in the analogy.
Hope this helps.
Akanimo.
[This message has been edited by Akanimo Udoh (edited June 15, 2001).]
 
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree that the local mode client should not implement the RemoteInterface.
I further abstracted the DataInterface layer and it helps.
I created a FlightServices class. This class does not implement the DataInterface but has methods such as BookFlight(String FlightNumber, int numSeats) and LookupFlight(String FlightNumber). Internally it contains an object of type DataInterface which instantiates the Data object or Remote object depending upon the startup mode.
I then created a class called FlightServicesException. So all method calls from FlightServices throw FlightServicesException instead of DatabaseException or RemoteException.
Abstracting it this way also gave me the ability to write some nonGUI test clients with which I could run simulations of many users hitting the server at the same time.
The testclients would instantiate a FlightServices object and perform all the calls that GUI does, but alot faster, and concurrently. My testclients were in different categories: lookup clients, booking clients, lockWithNoUnlock clients, and lockWholeDB clients. Running them all together helps test out my server design.
 
death pac
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Akanimo ,
I agree that i dont need to make my Client a Remote object. The reason i did that in the first place was to implement call backs.But i guesss i 'll have to revert on that one.
i think i need to rephrase my previous post .
In the local mode ,i m not using the rmiclient.instead my factory returns an instance of the rmiserver .the calls to the server are made from the GUI classes using a object of type xyz .so the gui classes are totally unaware of the mode the application is working in .The reason ,i need stubs /skeletons is bcoz of the fact that rmiserver is a remote object and hence the jvm looks for stubs and skeletons .
yes i think it might be a good idea to name my classes accoring to the mode .but again,i m using the same classes for both modes of the application ..except for the fact that i m eliminating the rmi client in the local mode .
hope to hear more comments
cheers
pac
 
Akanimo Udoh
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
pac,
Sorry for the silence, but i kinda forgot exactly 'where' this discussion thread was.
I finally understand what you're doing. You're using an rmi server class called rmiserver and when a remote client wants to connect to it he does so by using rmiclient which establishes a connection to this server, after looking up the required registry, getting the reference etc. In the case of local client you just instantiate the rmiserver object and pass the reference thru the interface xyz to the client to use directly.
The main set back here is the stub/skeleton stuff which you end up being stuck with even in local mode. I think a better architecture for you would be to use rmiserver as a 'composition' class. ie move all the code you want shared for both remote and local access into a new class that implements the xyz interface, lets call it dataserver.
Then you have a member of this class in your rmiserver so that all calls are just passed to this new member. For local access you just create a dataserver object and pass the interface reference to the client. This does a good job of separating the remote stuff from the local stuff so there are no funny complications.
Its very important that you separate the implementations since the instructions state that no sockets etc. should be created in local mode. If you open the source code for UnicastRemoteObject (which comes with the SDK) you'll see from the comments that instantiating any UnicastRemoteObject will "Create and export a new UnicastRemoteObject object using an anonymous/particular supplied port". So that rules that out.
Hope this helps.
Akanimo
 
death pac
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi there ,
thanx for your commments ! they say "better late than never"!! i was gonna submit my assignment on firday!!i ve reworked my design according to your suggestions !!
thanks again
cheers
Amjad
 
Akanimo Udoh
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
amjad,
Glad to hear that the suggestion was of some use. Good luck in your developer submission/exam. I got my own result last week and got 148/155. Only thing left for you is the written exam, which most guys on this site say is 'trivial' ... and i probably have to agree.
Akanimo
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Akanimo,
congrats on getting such a great score. I am currently preparing to take the scjd exam and I was wondering if you could briefly detail what kind of approach you took. For example what design patterns you used, whether you used rmi or object serialization.
How long did it take you to finish?
Enough of the questions and avidly awaiting your reply.
Onyedima Azu
 
Akanimo Udoh
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Onyedima,
Thats the first name from naija I'm seeing on this site.
Its difficult to really explain the details that you want if you haven't gotten a actual project assignment. It won't make much sense without it. Since you can take as long as you want to do the assignment it makes sense for you to get the assignment as soon as possible. If you want to DO the assignment 3 months from now, it makes good sense to register and get it now and use the time inbetween to just go over it and consider design options. You don't lose anything by doing so.
Basically i used RMI which is implicitly singleton design pattern, though to tell you the truth its better to CONCENTRATE ON YOUR DESIGN/IMPLEMENTATION than to worry about what its called! If you understand your assignment well enough and can come up with a good design I bet you that you'll find the name for the pattern easily enough ... i did!
It took me 2 weeks to finish the core code, and another 1 week for trimmings ( documentation, 'nice-to-haves', etc) and testing. I wouldn't really recommend this timetable for most people, but i've this bad habit of keeping late long nights that comes in very useful atimes (Department of health warns that...)
Hope this helps. Get your assignment and you'll be able to both ask more specific questions and get more specific answers.
Akanimo.
 
Onyedima Azu
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
Thanks for the advice and the speedy reply. I will take your advice and register for the exam.. I think I was making the mistake of trying to do the example in the Heller example before starting on the real thing but I am not sure that is a good idea now.
Thanks
Onyedima
ps. Well spotted the name is naija!!
 
Tongue wrestling. It's not what you think. And here, take this tiny ad. You'll need it.
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic