-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFibonacciServer.java
31 lines (26 loc) · 1.06 KB
/
FibonacciServer.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
public class FibonacciServer implements FibonacciInterface {
public long calculateFibonacci(int n) throws RemoteException {
if (n <= 1) {
return n;
} else {
return calculateFibonacci(n - 1) + calculateFibonacci(n - 2);
}
}
public static void main(String[] args) {
try {
FibonacciServer server = new FibonacciServer();
FibonacciInterface stub = (FibonacciInterface) UnicastRemoteObject.exportObject(server, 0);
// Bind the remote object's stub in the registry
Registry registry = LocateRegistry.getRegistry();
registry.rebind("FibonacciServer", stub);
System.out.println("FibonacciServer ready");
} catch (Exception e) {
System.err.println("FibonacciServer exception: " + e.toString());
e.printStackTrace();
}
}
}