I'm trying to call a fibonacci method on a remote server using RMI but when I try to invoke the method on the client side by giving the method an integer value, I get these errors:
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: unrecognized method hash: method not supported by remote object
at sun.rmi.server.UnicastServerRef.dispatch(Unknown Source)
at sun.rmi.transport.Transport$1.run(Unknown Source)
at sun.rmi.transport.Transport$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Unknown Source)
at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source)
at sun.rmi.server.UnicastRef.invoke(Unknown Source)
at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(Unknown Source)
at java.rmi.server.RemoteObjectInvocationHandler.invoke(Unknown Source)
at com.sun.proxy.$Proxy0.fibonacciArrayTest(Unknown Source)
at ie.gmit.FibonacciClient.main(FibonacciClient.java:37)
Does anyone have any idea where I have gone wrong with this implementation?
This is the client side of the RMI application:
//get user input
Scanner user_input = new Scanner(System.in);
String fibMaxNum;
System.out.println("Enter the max fibonacci number: ");
fibMaxNum = user_input.next();
int fibMax = Integer.parseInt(fibMaxNum);
//Get Fibonacci array.
int[] sequence = power_proxy.fibonacciArrayTest(fibMax);
for (int value : sequence) {
System.out.println(value);
}
And this is the implementation on the server side, I also get an error here The return type is incompatible with IPower.fibonacciArrayTest(int)
.I gather from this that I'm not specifying the correct return type in the Ipower
interface, but how can I correct the signatures to fix this? Should I Change the method in Ipower
to :
public int[] fibonacciArrayTest(int n) {
int a = 0;
int b = 1;
int[] sequence = new int[n];
// Fill array with Fibonacci values.
for (int i = 0; i < n; i++) {
sequence[i] = a;
int temp = a;
a = b;
b = temp + b;
}
return sequence;
}
The interface:
public interface IPower extends Remote{
//Declare available methods and must throw RemoteException
int[] fibonacciArrayTest(int fibMax) throws RemoteException;
}
You've changed your remote method signature after deployment.
Clean and rebuild and redeploy to both client and server, not forgetting to restart the Registry too.