G
Guest
Hi,
I wonder why the method "LocateRegistry.getRegistry(int port)" doesn't throw
an exception if no registry is available?
This seems a really bad design to me. I allways get a registry with this
method (even if no registry has been created) but when I try to bind some
object I get an exception, no wonder, there is no registry, so why is this
not notified by the getRegistry method???
See the code bellow for details (I'm using j2sdk1.4.2_02 / Windows XP):
[BEGIN CODE]
import java.rmi.*;
import java.rmi.registry.*;
import java.rmi.server.*;
public class StupidRegistry extends UnicastRemoteObject implements
DummyRemoteInterface {
protected StupidRegistry() throws RemoteException {
super();
}
public static void main(String[] args) {
Registry reg = null;
try {
reg = LocateRegistry.getRegistry(12321);
} catch (RemoteException e) {
System.out.println("couldn't get the registry, nice to be
notified of this!");
}
// well, it seems we got the registry, let's bind something...
StupidRegistry sr = null;
try {
sr = new StupidRegistry();
} catch (RemoteException e) { }
try {
reg.bind("I guess I won't be bound", sr);
} catch (AccessException e) {
} catch (RemoteException e) {
System.out.println("Well, I guess there is no registry...");
System.exit(-1);
} catch (AlreadyBoundException e) {
}
}
}
interface DummyRemoteInterface extends Remote { }
class StupidRegistry_Stub extends RemoteStub implements
DummyRemoteInterface, Remote {
public StupidRegistry_Stub() {
super();
}
public StupidRegistry_Stub(RemoteRef ref) {
super(ref);
}
}
[END CODE]
This will allways prints "Well, I guess there is no registry...". (Unless
you've got a registry allready running and listening to the used
port...)
I really don't see why the getRegistry method doesn't throw any exception. I
do
actually expect that exception. Why do I get a non usable registry? What
is this good for?
Is there any way to check that the registry returned by the getRegistry
method is usable before trying to bind anything to it ?
Greetings,
Mike
I wonder why the method "LocateRegistry.getRegistry(int port)" doesn't throw
an exception if no registry is available?
This seems a really bad design to me. I allways get a registry with this
method (even if no registry has been created) but when I try to bind some
object I get an exception, no wonder, there is no registry, so why is this
not notified by the getRegistry method???
See the code bellow for details (I'm using j2sdk1.4.2_02 / Windows XP):
[BEGIN CODE]
import java.rmi.*;
import java.rmi.registry.*;
import java.rmi.server.*;
public class StupidRegistry extends UnicastRemoteObject implements
DummyRemoteInterface {
protected StupidRegistry() throws RemoteException {
super();
}
public static void main(String[] args) {
Registry reg = null;
try {
reg = LocateRegistry.getRegistry(12321);
} catch (RemoteException e) {
System.out.println("couldn't get the registry, nice to be
notified of this!");
}
// well, it seems we got the registry, let's bind something...
StupidRegistry sr = null;
try {
sr = new StupidRegistry();
} catch (RemoteException e) { }
try {
reg.bind("I guess I won't be bound", sr);
} catch (AccessException e) {
} catch (RemoteException e) {
System.out.println("Well, I guess there is no registry...");
System.exit(-1);
} catch (AlreadyBoundException e) {
}
}
}
interface DummyRemoteInterface extends Remote { }
class StupidRegistry_Stub extends RemoteStub implements
DummyRemoteInterface, Remote {
public StupidRegistry_Stub() {
super();
}
public StupidRegistry_Stub(RemoteRef ref) {
super(ref);
}
}
[END CODE]
This will allways prints "Well, I guess there is no registry...". (Unless
you've got a registry allready running and listening to the used
port...)
I really don't see why the getRegistry method doesn't throw any exception. I
do
actually expect that exception. Why do I get a non usable registry? What
is this good for?
Is there any way to check that the registry returned by the getRegistry
method is usable before trying to bind anything to it ?
Greetings,
Mike