rmiexample

rmiexample - RMI Example A Remote Account Interface...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
RMI Example A Remote Account Interface (filename: Account.java) import java.rmi.Remote; import java.rmi.RemoteException; public interface Account extends Remote { public String getName() throws RemoteException; public float getBalance() throws RemoteException; public void withdraw(float amt) throws RemoteException; public void deposit(float amt) throws RemoteException; public void transfer(float amt, Account src) throws RemoteException; }
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Implementation of the Remote Account Interface ( filename: AccountImpl.java) import java.rmi.server.UnicastRemoteObject; import java.rmi.RemoteException; public class AccountImpl extends UnicastRemoteObject implements Account { private float balance = 0; private String name = ""; // Constructor creates a new account with the given name public AccountImpl(String aName) throws RemoteException { name = aName; } public String getName() throws RemoteException { return name; } public float getBalance() throws RemoteException { return balance; } //Withdraw some funds public void withdraw(float amt) throws RemoteException { balance -= amt; //Ensure balance never drops below zero balance = Math.max(balance, 0); } //Deposit some funds public void deposit(float amt) throws RemoteException { balance += amt; } //Transfer some funds from another (remote) account into this one public void transfer(float amt, Account src) throws RemoteException { src.withdraw(amt); this.deposit(amt); } }
Background image of page 2
The utility class, RegAccount (filename: RegAccount.java) //Utility class, RegAccount, creates an AccountImpl object and then
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 07/29/2011 for the course CNT 6707 taught by Professor Ahuja during the Spring '11 term at UNF.

Page1 / 7

rmiexample - RMI Example A Remote Account Interface...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online