Entering content frame

Procedure documentation Implementing the Remote Interface Locate the document in its SAP Library structure

In this class, you must implement the remote interface that you have defined. That is, you must provide the implementation of the method signatures of the interface.

Note

RMI_P4 does not define the requirement that your implementation class must enhance UnicastRemoteObject (as opposed to the standard RMI). You benefit from this because you can build the class hierarchy that is best adapted to the design of your application.

You can implement more than one remote interface in your implementation class. You can also define additional methods that do not appear in any of the implemented remote interfaces. However, such methods cannot be called remotely.

Example

The AccountImpl class is the implementation class of the Account remote interface. The full code of the class is listed below:

This graphic is explained in the accompanying text

package exapmles.rmi_p4;

 

import java.rmi.RemoteException;

 

public class AccountImpl implements Account {

  private int balance = 0;

 

  public void deposit(int amount) throws RemoteException {

    if (amount < 0) {

      throw new RemoteException("Incorect value:" +amount);

    }

    balance += amount;

  }

 

  public void draw(int amount) throws OverdrawException {

    if (balance < amount) {

      throw new OverdrawException(amount - balance );

    }

    balance -= amount;

  }

 

  public int getBalance() {

    return balance;

  }

}

 

 

Leaving content frame