Java Reference
In-Depth Information
/** Does something locally. There is no way to call this
* method remotely since it does not appear in the list
*ofremote methods in the < tt > RMIExampleInterface < /tt >
* interface.
**/
public void doSomethingLocal (float x) {
System.err.println ("RMIExampleImpl.doSomethingLocal");
} // doSomethingLocal
} // class RMIExampleImpl
One new requirement that we haven't mentioned yet is that the constructor must
be declared to throw RemoteException ,evenifthe constructor is otherwise
empty. The normal default constructor provided by the compiler when no explicit
constructor appears in the code is purely empty with no throws clauses. But
since our implementation class must extend UnicastRemoteObject ,whose
constructor does throw RemoteException , the javac compiler complains if
our subclass constructor does not declare that it throws the same exception (or a
superclass thereof) as its parent class.
Now we move on to the class that we use to instantiate an RMIExampleImpl
object and bind it into the registry:
// RMIExampleServer.java
package javatech.rmi18.server.impl;
import java.net.MalformedURLException;
import java.rmi.*;
/** The server class that will get run to start up the
* remote implementation class and bind it into
* the RMI registry.**/
public class RMIExampleServer
{
public static void main (String[] args) {
// Create and install a security manager
if (System.getSecurityManager() == null) {
System.setSecurityManager (new RMISecurityManager());
}
// Instantiate an RMIExampleImpl implementation class
// and bind into the registry.
try {
// Instantiate.
Search WWH ::




Custom Search