| CONTENTS | PREV | NEXT | Java Remote Method Invocation |
java.rmi.server.UnicastRemoteObject, thereby
inheriting the remote behavior provided by the classes
java.rmi.server.RemoteObject and
java.rmi.server.RemoteServer.BankAcctImpl implements the
BankAccount remote interface and extends the
java.rmi.server.UnicastRemoteObject class:
package mypackage;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
public class BankAccountImpl
extends UnicastRemoteObject
implements BankAccount
{
private float balance = 0.0;
public BankAccountImpl(float initialBalance)
throws RemoteException
{
balance = initialBalance;
}
public void deposit(float amount) throws RemoteException {
...
}
public void withdraw(float amount) throws OverdrawnException,
RemoteException {
...
}
public float getBalance() throws RemoteException {
...
}
}
Note:
java.rmi.server.UnicastRemoteObject. However, the implementation class must then assume the responsibility for exporting the object (taken care of by the UnicastRemoteObject constructor) and for implementing (if needed) the correct remote semantics of the hashCode, equals, and toString methods inherited from the java.lang.Object class.UnicastRemoteObject.exportObject or the constructor UnicastRemoteObject that does not contain parameters of type RMIClientSocketFactory and RMIServerSocketFactory, then the remote object is exported to all local addresses. To export a remote object to a specific address, see the section RMI Socket Factories.