C
Christian Hvid
Can anyone help with these Java 5 RMI related questions?
I want to make a very basic RMI application; something needs to run as
a "background job" that I should be able to query the state of and
start and shutdown cleanly.
* Is there a clean way to shutdown a registry created locally in the
server code?
My code looks like this:
public interface Hello extends Remote {
public String sayHello() throws RemoteException;
public void shutdown() throws RemoteException;
}
public class ServerTest implements Hello {
public static void main(String args[]) throws RemoteException,
AlreadyBoundException {
ServerTest obj = new ServerTest();
Hello stub = (Hello) UnicastRemoteObject.exportObject(obj, 0);
Registry registry = LocateRegistry.createRegistry(2001);
registry.rebind("hello", stub);
}
public String sayHello() throws RemoteException {
return "Hello there";
}
public void shutdown() throws RemoteException {
System.exit(0); // Other than doing something as violent as
this?????????????
}
}
public class ClientTest {
public static void main(String args[]) throws RemoteException,
NotBoundException {
Registry registry = LocateRegistry.getRegistry(2001);
Hello hello = (Hello)registry.lookup("hello");
System.out.println("stub.sayHello returns "+hello.sayHello());
hello.shutdown();
}
}
I am looking for a call like:
registy.shutdownInOrderlyFashion();
* Why does rmiregistry need to have access to the class definitions of
the interfaces?
The alternative way of doing the above is to run the rmiregisty
program seperately and get the registry by:
LocaleRegistry.getRegistry();
This works *only* if I start the rmiregistry program at the root of
generated class files; presumably because the rmiregistry program
needs to have access to the class definition of "Hello".
While I get that can define a codebase or classpath to point
elsewhere, I don't get why the rmiregistry program needs to have
access to the class definitions?
I as understand it, the rmiregistry simply should register the name
"hello" for the server and resolve the name "hello" as a reference to
something on the server for the client.
Only the client and the server should need to know the interface
definition.
-- Christian
I want to make a very basic RMI application; something needs to run as
a "background job" that I should be able to query the state of and
start and shutdown cleanly.
* Is there a clean way to shutdown a registry created locally in the
server code?
My code looks like this:
public interface Hello extends Remote {
public String sayHello() throws RemoteException;
public void shutdown() throws RemoteException;
}
public class ServerTest implements Hello {
public static void main(String args[]) throws RemoteException,
AlreadyBoundException {
ServerTest obj = new ServerTest();
Hello stub = (Hello) UnicastRemoteObject.exportObject(obj, 0);
Registry registry = LocateRegistry.createRegistry(2001);
registry.rebind("hello", stub);
}
public String sayHello() throws RemoteException {
return "Hello there";
}
public void shutdown() throws RemoteException {
System.exit(0); // Other than doing something as violent as
this?????????????
}
}
public class ClientTest {
public static void main(String args[]) throws RemoteException,
NotBoundException {
Registry registry = LocateRegistry.getRegistry(2001);
Hello hello = (Hello)registry.lookup("hello");
System.out.println("stub.sayHello returns "+hello.sayHello());
hello.shutdown();
}
}
I am looking for a call like:
registy.shutdownInOrderlyFashion();
* Why does rmiregistry need to have access to the class definitions of
the interfaces?
The alternative way of doing the above is to run the rmiregisty
program seperately and get the registry by:
LocaleRegistry.getRegistry();
This works *only* if I start the rmiregistry program at the root of
generated class files; presumably because the rmiregistry program
needs to have access to the class definition of "Hello".
While I get that can define a codebase or classpath to point
elsewhere, I don't get why the rmiregistry program needs to have
access to the class definitions?
I as understand it, the rmiregistry simply should register the name
"hello" for the server and resolve the name "hello" as a reference to
something on the server for the client.
Only the client and the server should need to know the interface
definition.
-- Christian