• 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

RMI - Stub Generation - B & S

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I've written some code on the RMI server side and now need to generate stubs. My problem is that I know that the stub generation requires that I throw RemoteException. The supplied interface from Sun doesn't do this. Ive searched the knowledge based here, but most topics talke about creating a superinterface that does throw RemoteException and then changing DBMain to subclass this.... but after numerous reads and what I always thought was the case, you can't change the supplied interface from Sun. Currently thinking of a way around this, so any help or pointing in the right direction would be appreciated.

Cheers,


Paul.
 
Ranch Hand
Posts: 357
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Paul,

One word: Adapter.

Frans.
 
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Paul,

As Frans suggested, the Adapter Pattern is one solution to this problem.

Since I don't like one word answers to questions, here is a little more detail:

In this case, you could have an interface that looks similar to the supplied Sun interface however all it's methods do throw RemoteException. A class that implements this interface could be extremely simple: it would just call the relevant methods of the Data class - in effect, adapting the interface to the format you require.

I have still kept this vague. Have a think about it, and come back with further questions as required.

Regards, Andrew
 
Paul Truckle
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi. Yes, thanks .. I've sorted it. Basically, I created a further class that has an instance of the interface within it. The new class doesn't have the RemoteExceptions within it's methods, but the interface then references the methods that do have the RemoteExceptions (what's returned from rmi server). I've then repeated the methods of the interface within the new class without RemoteException and called the equivalent method in the interface reference...thus achieving my requirement. Is this your definition of Adapter ? This certainly resolves my problem by keeping the client side of the solution still referencing DBMain for remote and local versions.
 
Frans Janssen
Ranch Hand
Posts: 357
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Paul,

I do not understand your explanation of your design completely.

The simplest solution (I think) is:

(assumption: the interface given in the assignment is called DBMain)

  • Data implements DBMain
  • Adapter is a new class that has the same interface as DBMain, except for RemoteException that has been added to all methods
  • Adapter is a server-side remote object (extends UnicastRemoteObject)
  • Adapter has a reference to a Data object
  • All methods in Adapeter do no more than forwarding the call to the Data object


  • e.g. the implementation of the isLocked() method in Adapter could be this:



    I hope I did not give away too much

    Frans.
     
    Paul Truckle
    Greenhorn
    Posts: 24
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Yep ... thanks....that's it....that's what I've done.
     
    Frans Janssen
    Ranch Hand
    Posts: 357
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Originally posted by Paul Truckle:
    Yep ... thanks....that's it....that's what I've done.



    OK, good job then

    Frans.

    BTW, I see now that I forgot that the Adapter must implement your RMI interface. But I guess you already found that out yourself.
    [ February 25, 2005: Message edited by: Frans Janssen ]
     
    Paul Truckle
    Greenhorn
    Posts: 24
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Correct.... that's why I talked about interfaces more in my answer.

    Thanks again.
     
    You had your fun. Now it's time to go to jail. Thanks for your help tiny ad.
    a bit of art, as a gift, the permaculture playing cards
    https://gardener-gift.com
    reply
      Bookmark Topic Watch Topic
    • New Topic