![]() |
![]() |
![]() |
![]() |
![]() |
|
You need to do more work to prepare the RatingServer for remote
method invocation. For example, RatingServer must extend
UnicastRemoteObject, rather than extending Object,
because the constructors and methods of UnicastRemoteObject perform
all sorts of wizardry that enable remote activation. RatingServer
must also implement the Serializable interface.
Also, you now must define a zero-argument constructor that calls the
zero-argument UnicastRemoteObject constructor and throws the
RemoteException exception.
The definition is required because the
zero-argument constructor in UnicastRemoteObject happens to throw
the RemoteException exception.
import java.rmi.*; import java.rmi.server.*; public class RatingServer extends UnicastRemoteObject implements RatingServerInterface, Serializable { public RatingServer () throws RemoteException { super(); } public int serverRating (MovieInterface m) throws RemoteException { System.out.println("RatingServer asked for a rating"); int s = m.getScript(); int a = m.getActing(); int d = m.getDirection(); return 3 * Math.max(Math.max(s, a), d); } }