Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: Java
Expertise: Advanced
May 5, 1999



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Create a Remote Object Without Extending UnicastRemoteObject

When using Java's Remote Method Invocation (RMI), you may have defined a server class that extends java.rmi.server.UnicastRemoteObject. Extending UnicastRemoteObject makes your class capable of handling incoming calls, and is acceptable in many cases. However, you sometimes will want to extend a different class and still retain the ability to handle incoming RMI calls. Fortunately, there's a simple solution to this problem. The UnicastRemoteObject constructor makes the object accessible by calling the static exportObject() method, and because this method is public, your class can call it directly. In this code, an instance of RMIServer is created, exported, and added to the registry. Although it does not extend UnicastRemoteObject, it can be accessed through registry lookup and called using RMI.
import java.rmi.*;
import java.rmi.server.*;

public class RMIServer extends Object implements RMIInterface {

	public static void main(String[] args) throws Exception {
		RMIServer s = new RMIServer();
		Naming.rebind("MyServer", s);
	}  //  public static void main()

}  //  public class RMIServer extends Object
Brett Spell
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date