トランザクショナル分散オブジェクト基盤 TPBroker Object Transaction Monitor プログラマーズガイド

[目次][索引][前へ][次へ]

4.3.1 非応答型呼び出しをするクライアントアプリケーションの例(Java)

非応答型呼び出しをするクライアントアプリケーションの処理の流れとコードの例を示します。斜体で示しているコードは,雛形クラスとして自動生成される部分です。

<この項の構成>
(1) サービス利用処理の流れ
(2) サービス利用処理のコード
(3) TSCユーザプロキシを呼び出すコード

(1) サービス利用処理の流れ

  1. TPBrokerの初期化処理
  2. TPBroker OTMの初期化処理
  3. TSCデーモンへの接続
  4. TSCユーザプロキシの生成および各種設定
  5. TSCユーザプロキシのメソッド呼び出し(サーバ側のオブジェクトの呼び出し)
  6. TSCデーモンへの接続解放
  7. TPBroker OTMの終了処理

(2) サービス利用処理のコード

 
//
// "ClientAP.java"
//
 
import JP.co.Hitachi.soft.TPBroker.TSC.*;
 
public class ClientAP
{
  public static void main(String[] args)
  {
    ////////
    // 1, TPBrokerの初期化処理
    ////////
    org.omg.CORBA.ORB  orb = null;
    try
    {
      // ORBの初期化処理
      orb = org.omg.CORBA.ORB.init(args,null);
    }
    catch(org.omg.CORBA.SystemException ce)
    {
      // 例外処理
      System.out.println(ce);
      System.exit(1);
    }
 
    ////////
    //2, TPBroker OTMの初期化処理
    ////////
    // TSCの初期化
    try
    {
      TSCAdm.initClient(args,null,orb);
    }
    catch(TSCSystemException tsc_se)
    {
      // 例外処理
      System.out.println(tsc_se);
      System.exit(1);
    }
 
    ////////
    // 3, TSCデーモンへの接続
    ////////
 
    TSCDomain domain = null;
    try
    {
      domain = new TSCDomain(null,null);
    }
    catch(TSCSystemException tsc_se)
    {
      // 例外処理
      System.out.println(tsc_se);
      try
      {
        TSCAdm.endClient();
      }
      catch(TSCSystemException se)
      {
        System.exit(1);
      }
 
      System.exit(1);
    }
 
    TSCClient tsc_client = null;
 
    try
    {
      tsc_client =
        TSCAdm.getTSCClient(domain, TSCAdm.Regulator);
    }
    catch(TSCSystemException tsc_se)
    {
      // Exception process
      System.out.println(tsc_se);
      try
      {
        TSCAdm.endClient();
      }
      catch(TSCSystemException se)
      {
        System.exit(1);
      }
      System.exit(1);
    }
 
    ////////
    // 4, TSCユーザプロキシの生成および各種設定
    ////////
    // ユーザ定義IDLインタフェース"XYZ"用のTSCProxy生成
 
    XYZ_TSCprxy  my_proxy = null;
    try
    {
      my_proxy = new XYZ_TSCprxy(tsc_client);
    }
    catch(TSCSystemException tsc_se)
    {
      // 例外処理
      System.out.println(tsc_se);
      try
      {
        TSCAdm.releaseTSCClient(tsc_client);
        TSCAdm.endClient();
      }
      catch(TSCSystemException se)
      {
        System.exit(1);
      }
        System.exit(1);
    }
 
    //////
    // 5, TSCユーザプロキシのメソッド呼び出し
    //    (サーバ側のオブジェクトの呼び出し)
    //////
    try
    {
      callOnlyService.invoke(my_proxy);
    }
      catch(TSCSystemException tsc_se)
    {
      System.out.println(tsc_se);
      try
      {
        TSCAdm.releaseTSCClient(tsc_client);
        TSCAdm.endClient();
      }
      catch(TSCSystemException se)
      {
        System.exit(1);
      }
      System.exit(1);
 
    }
    /////////
    // 6, TSCデーモンへの接続解放
    /////////
    try
    {
      TSCAdm.releaseTSCClient(tsc_client);
    }
    catch(TSCSystemException tsc_se)
    {
      // 例外処理
      System.out.println(tsc_se);
      try
      {
        TSCAdm.endClient();
      }
      catch(TSCSystemException se)
      {
        System.exit(1);
      }
 
      System.exit(1);
    }
 
    /////////
    //7, TPBroker OTMの終了処理
    /////////
    try
    {
      TSCAdm.endClient();
    }
    catch(TSCSystemException tsc_se)
    {
      // 例外処理
      System.out.println(tsc_se);
      System.exit(1);
 
    }
 
    System.exit(0);
 
  }
}

(3) TSCユーザプロキシを呼び出すコード

 
//
// "callOnlyService.java"
 
import JP.co.Hitachi.soft.TPBroker.TSC.*;
 
public
class callOnlyService
{
  public static void
  invoke(XYZ_TSCprxy my_proxy)
  {
    //////
    //サービスの呼び出し
    //////
    //in引数の準備
    int in_data = 0;
    
    try
    {
      //サーバのメソッド呼び出し
      my_proxy.callOnly(in_data);
    }
    catch(TSCSystemException tsc_se)
    {
      //例外処理
      System.out.println(tsc_se);
      throw tsc_se;
    }
  }
 
}