Using Remote Objects
Earlier in the chapter we mentioned some of the situations that might lead you to use message passing rather than remote objects to handle the agent-to-agent communication in your distributed system. To get a more concrete feeling for the differences between a message-passing system and one based on remote objects, this section describes an RMI implementation of our chess game.
The RMI implementation of the chess game uses two remote objects: a
remote chess player and a remote chess move. The interface for the
RMIChessMove
object is shown in Example 6.18. It has essentially the same interface as the
ChessMove
class in our earlier examples.
package dcj.examples.message; import java.rmi.RemoteException; // Interface for an RMI-based chess move public interface RMIChessMove { public String from() throws RemoteException; public void setFrom(String f) throws RemoteException; public String to() throws RemoteException; public void setTo(String t) throws RemoteException; public int checkFlag() throws RemoteException; public void setCheckFlag (String f) throws RemoteException; }
Example 6.19 shows the
RMIChessMoveImpl
class, which is the server
implementation of the chess move object.
package dcj.examples.message; import java.rmi.*; public class RMIChessMoveImpl implements RMIChessMove extends Remote { String fromPos; String toPos; int checkFlag; public RMIChessMoveImpl(String from, ...
Get Java Distributed Computing now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.