Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Extending Data class for RMI

Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Am using RMI for networking portion and plan to extend the Data class to and implement the same functionality as UnicastRemoteObject. In the Java RMI Tutorial is the following:
UnicastRemoteObject is a convenience class, defined in the RMI public API, that can be used as a superclass for remote object implementations. The superclass UnicastRemoteObject supplies implementations for a number of java.lang.Object methods (equals, hashCode, toString) so that they are defined appropriately for remote objects. UnicastRemoteObjectalso includes constructors and static methods used to export a remote object, that is, make the remote object available to receive incoming calls from clients.
A remote object implementation does not have to extend UnicastRemoteObject, but any implementation that does not must supply appropriate implementations of the java.lang.Object methods. Furthermore, a remote object implementation must make an explicit call to one of UnicastRemoteObject's exportObject methods to make the RMI runtime aware of the remote object so that the object can accept incoming calls. By extending UnicastRemoteObject, the ComputeEngine class can be used to create a simple remote object that supports unicast (point-to-point) remote communication and that uses RMI's default sockets-based transport for communication.
If you choose to extend a remote object from any class other than Unicast-RemoteObject or, alternatively, extend from the new JDK 1.2 class java.rmi.activation.Activatable (used to construct remote objects that can execute on demand), you need to export the remote object by calling either the UnicastRemoteObject.exportObject or Activatable.exportObject method explicitly from your class's constructor (or another initialization method, as appropriate).
Question--how to get a look at the Java code for UnicastRemoteObject to see how the Object methods are implemented? As well, how does UnicastRemoteObject call exportObject? With "this" as the argument?
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can try and copy/paste the code...
But a better solution (because Java doesn't have multiple inheritance) is probably to use a separate proxy class that does the following:
class MyRMIClass extends UnicastRemoteObject {
private Data myData; //Reference to data object
public void lock(int record) {
If you want to be super-correct, you can create an interface that you can modify Data to implement, and you can define MyRMIClass to implement. Then you're sure that if you make changes to the method signatures in one, you'll get compile errors if you don't keep everything nice and consistant.
Hope this helps?
Otherwise, get your hands on the JDK and delve into src.jar to get the exact implementation of the methods that you want.
[This message has been edited by Dave Boden (edited February 15, 2001).]
Douglas Kent
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Dave. I used the exact method recommended by Sun--subclassing the Data class and implementing the RMI interface, what I named rmiData. I called exportOjbect(this), implmented toString(), hashode(), equals() and it works great! (well, I got it to compile and generated the stubs, etc with rmic).
thanks again.
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic