⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bankmanagerimpl.java

📁 java rmi技术实例
💻 JAVA
字号:
import java.util.Hashtable;
import java.rmi.server.UnicastRemoteObject;
import java.rmi.RemoteException;

public class BankManagerImpl implements BankManager {
  private Hashtable accounts;
  private Hashtable clients;

  // public No-argument constructor
  public BankManagerImpl()
      throws java.rmi.RemoteException {
    initialize();
  }

  public Account getAccount(String accountNumber) 
      throws RemoteException {
    AccountImpl account = (AccountImpl)accounts.get(accountNumber);
    return account;
  }

  public Client getClient(String clientName) 
      throws RemoteException {
    ClientImpl client = (ClientImpl)clients.get(clientName);
    return client;
  }

  public void initialize()
      throws java.rmi.RemoteException {
    // Create the hashtables
    accounts = new Hashtable(20);
    clients  = new Hashtable(10);
    // Create clients and put them in the hashtable
    Client clientCharlie = new ClientImpl(this, "Charlie");
    UnicastRemoteObject.exportObject(clientCharlie);
    Client clientShannon = new ClientImpl(this, "Shannon");
    UnicastRemoteObject.exportObject(clientShannon);
    clients.put("Charlie", clientCharlie);
    clients.put("Shannon", clientShannon);

    // Create accounts:
    //     * put them into the hashtable
    //     * associate them with clients
    Account account;
    account = new AccountImpl(this, clientCharlie, "4434");
    ((AccountImpl)account).deposit(500);
    UnicastRemoteObject.exportObject(account);
    accounts.put("4434", account);
    account = new AccountImpl(this, clientCharlie, "4461");
    ((AccountImpl)account).deposit(600);
    UnicastRemoteObject.exportObject(account);
    accounts.put("4461", account);
    account = new AccountImpl(this, clientShannon, "6678");
    ((AccountImpl)account).deposit(700);
    UnicastRemoteObject.exportObject(account);
    accounts.put("6678", account);
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -