Show TOC Start of Content Area

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

...

       1.      Define the class that implements the remote interface and provide the implementation of the methods of this interface.

Note

You can implement more than one remote interface in your implementation class.

Caution 

The RMI-P4 runtime makes no guarantees with respect to mapping remote object invocations to threads. The next invocation of the same remote method may or may not happen in the same thread so remote object implementations should not use and rely on the state of thread-local variables.

Since remote method invocation on the same remote object may execute concurrently, a remote object implementation needs to make sure its implementation is thread-safe.

       2.      You can also implement additional methods that are not defined by 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:

Syntax

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("Incorrect 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;

  }

}

 

 

End of Content Area