Any example of dynamic proxy with RMI?
Hi, are there any good example of dynamic proxy with RMI, using the new RemoteObjectInvocationHandler class?
I am currently implementing a Registry, and want to use dynamic proxy to wrap around the registry stub, to pass extra information to the client.
I've tried it, but the program will hang and get this exception:
Exception in thread "RMI TCP Connection(1616)-192.168.1.23" java.lang.OutOfMemoryError: Java heap space
My implementation looks like this:
public RegistryImplextends RemoteServer Implements Registry{
public RegistryImpl(int port, Properties... properties)throws RemoteException, ChannelException{
// Create a reference for the registry.
LiveRef liveref =new LiveRef(id, port);
ref =new UnicastServerRef(liveref);
Registry proxy = (Registry)RegistryProxy.newProxyInstance(
this.getClass().getClassLoader(),
this.getClass().getInterfaces(),
new RemoteObjectInvocationHandler(this.getRef()));
/* Using dynamic proxy */
usref.exportObject(proxy, null,true);
}
}
publicclass RegistryProxyextends Proxyimplements Registry{
private InvocationHandler handler;
public RegistryProxy(InvocationHandler handler){
super(handler);
this.handler = handler;
}
public Remote lookup(String name)throws RemoteException, NotBoundException, AccessException{
Remote result;
try{
Method m = Registry.class.getMethod("lookup",new Class[]{String.class});
result = (Remote)handler.invoke(this, m,new Object[]{name});
}catch (SecurityException e){
thrownew UndeclaredThrowableException(e);
}catch (NoSuchMethodException e){
thrownew UndeclaredThrowableException(e);
}catch (Throwable e){
thrownew UndeclaredThrowableException(e);
}
return result;
}
publicvoid bind(String name, Remote remoteObj)throws RemoteException, AlreadyBoundException, AccessException{
...
}
publicvoid unbind(String name)throws RemoteException, NotBoundException, AccessException{
...
}
publicvoid rebind(String name, Remote remoteObj)throws RemoteException, AccessException{
...
}
public String[] list()throws RemoteException, AccessException{
...
}
}
I am new to Java programming, any help is appriciated.
Regards
Eddie

