O'Reilly logo

Java Distributed Computing by Jim Farley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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.

Example 6-18. A Remote Chess Move Interface
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.

Example 6-19. Chess Move Implementation
package dcj.examples.message; import java.rmi.*; public class RMIChessMoveImpl implements RMIChessMove extends Remote { String fromPos; String toPos; int checkFlag; public RMIChessMoveImpl(String from, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required