client.java

来自「weblogic应用全实例」· Java 代码 · 共 487 行 · 第 1/2 页

JAVA
487
字号
    /**
     * 为业务创建一个唯一的id
     *
     * @返回                  string 业务ID
     */
    String getTransactionID() {
      return new String("" + System.currentTimeMillis());
    }

    /**
     * 调用TellerBean执行业务
     *
     * @异常               TellerException if there is
     *                          an error in performing the transaction
     * @异常               RemoteException if there is
     *                          a communications or systems failure
     */
    void invokeTransaction() throws TellerException, RemoteException {
    }

    /**
     * 构造业务结果报告
     *
     */
    void buildReport() {
      tellerServer    = result.getTellerServer();
      account1Server  = result.getAccount1Result().getServer();
      account1Balance = result.getAccount1Result().getBalance();
      tellerMessage   = "Teller (" + tellerServer + "): ";
      account1Message = "Account " + account1Id + 
                        " (on " + account1Server + "): " +
                        "balance: $" + account1Balance;
    }

    /**
     * 打印业务结果报告
     *
     */
    void printReport() {
      System.out.println("    " + tellerMessage + actionMessage);
      stats.addClusterMessage("Teller on: " + tellerServer);
      if (account1Server != null) {
        stats.addClusterMessage("Account 1 on: " + account1Server);
        System.out.println("    " + account1Message);
      }
      if (account2Server != null) {
        stats.addClusterMessage("Account 2 on: " + account2Server);
        System.out.println("    " + account2Message);
      }
    }
  }

  /**
   * 执行结算值查询
   * 
   */
  class Balance extends Transaction {

    /**
     * 构造方法
     * 
     * @参数 accountId         string 账号Id
     * @异常               TellerException if there is
     *                          an error in performing the transaction
     * @异常               RemoteException if there is
     *                          a communications or systems failure
     * @异常               CreateException if there is
     *                          a problem creating a teller
     */
    Balance(String accountId)
        throws TellerException, RemoteException, CreateException {
     this.account1Id = accountId;
    }

    /**
     * 调用TellerBean执行结算值查询
     *
     * @异常               TellerException if there is
     *                          an error in performing the transaction
     * @异常               RemoteException if there is
     *                          a communications or systems failure
     */
    void invokeTransaction() throws TellerException, RemoteException {
      result = teller.balance(account1Id);
    }

    /**
     * 构造一个事务结果的报告
     *
     */
    void buildReport() {
      super.buildReport();
      actionMessage = "balance of account";
    }
  }

  /**
   * 执行存入
   * 
   */
  class Deposit extends Transaction {

    /**
     * 构造方法.
     * 
     * @参数 accountId         string 账号ID
     * @参数 amount            double 数量
     * @异常               TellerException if there is
     *                          an error in performing the transaction
     * @异常               RemoteException if there is
     *                          a communications or systems failure
     * @异常               CreateException if there is
     *                          a problem creating a teller
     */
    Deposit(String accountId, double amount)
        throws TellerException, RemoteException, CreateException {
       this.account1Id = accountId;
       this.amount     = amount;
    }

    /**
     * 调用TellerBean执行存入
     *
     * @异常               TellerException if there is
     *                          an error in performing the transaction
     * @异常               RemoteException if there is
     *                          a communications or systems failure
     */
    void invokeTransaction() throws TellerException, RemoteException {
      result = teller.deposit(account1Id, amount, transId);
    }

    /**
     * 构造一个事务结果的报告
     *
     */
    void buildReport() {
      super.buildReport();
      actionMessage = "deposited $" + amount;
    }
  }

  /**
   * 执行提取
   * 
   */
  class Withdrawal extends Transaction {

    /**
     * 构造方法.
     * 
     * @参数 accountId         string 账号 ID
     * @参数 amount            double 数量
     * @异常               TellerException if there is
     *                          an error in performing the transaction
     * @异常               RemoteException if there is
     *                          a communications or systems failure
     * @异常               CreateException if there is
     *                          a problem creating a teller
     */
    Withdrawal(String accountId, double amount)
        throws TellerException, RemoteException, CreateException {
       this.account1Id = accountId;
       this.amount     = amount;
    }

     /**
     * 调用TellerBean执行提取
     *
     * @异常               TellerException if there is
     *                          an error in performing the transaction
     * @异常               RemoteException if there is
     *                          a communications or systems failure
     */
    void invokeTransaction() throws TellerException, RemoteException {
      result = teller.withdraw(account1Id, amount, transId);
    }

    /**
     * 构造一个事务结果的报告
     *
     */
    void buildReport() {
      super.buildReport();
      actionMessage = "withdrew $" + amount;
    }
  }

  /**
   * 执行转账
   * 
   */
  class Transfer extends Transaction {

    /**
     * 构造方法
     * 
     * @参数 accountFrom       string 源账号 ID
     * @参数 amount            double 数量
     * @参数 accountTo         string 目的账号 ID
     * @异常               TellerException if there is
     *                          an error in performing the transaction
     * @异常               RemoteException if there is
     *                          a communications or systems failure
     * @异常               CreateException if there is
     *                          a problem creating a Teller
     */
    Transfer(String accountFrom, String accountTo, double amount)
        throws TellerException, RemoteException, CreateException {
      this.account1Id = accountFrom;
      this.account2Id = accountTo;
      this.amount     = amount;
    }

    /**
     * 调用TellerBean执行转账
     *
     * @异常               TellerException if there is
     *                          an error in performing the transaction
     * @异常               RemoteException if there is
     *                          a communications or systems failure
     */
    void invokeTransaction() throws TellerException, RemoteException {
      result = teller.transfer(account1Id, account2Id, amount, transId);
    }

    /**
     * 构造一个事务结果的报告
     *
     */
    void buildReport() {
      super.buildReport();
      account2Server  = result.getAccount2Result().getServer();
      account2Balance = result.getAccount2Result().getBalance();
      actionMessage   = "Transfered $" + amount + " from " + account1Id + 
                        " to " + account2Id;
      account2Message = "Account " + account2Id + 
                        " (on " + account2Server + "): " +
                        "balance: $" + account2Balance;
    }
  }
}

⌨️ 快捷键说明

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