TSCContextを利用するクライアントアプリケーションの処理の流れとコードの例を示します。太字で示しているコードは,同期型呼び出しのコードと異なる部分です。
//
// "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)
{
// 例外処理
System.out.println(tsc_se);
try
{
TSCAdm.endClient();
}
catch(TSCSystemException se)
{
System.exit(1);
}
System.exit(1);
}
////////
// 4, TSCユーザプロキシの生成および各種設定
////////
// ユーザ定義IDLインタフェース"ABC"用のTSCProxy生成
ABC_TSCprxy my_proxy = null;
try
{
my_proxy = new ABC_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コンテキストへのユーザデータの設定
////////
// TSCContextの取得
TSCContext ctx = my_proxy._TSCContext();
// ユーザIDの設定
String user_id = "UserID:111";
ctx.setUserData(user_id.getBytes());
////////
// 6, TSCユーザプロキシのメソッド呼び出し
// (サーバ側のオブジェクトの呼び出し)
////////
try
{
callService.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);
}
////////
// 7, 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);
}
////////
// 8, TPBroker OTMの終了処理
////////
try
{
TSCAdm.endClient();
}
catch(TSCSystemException tsc_se)
{
// 例外処理
System.out.println(tsc_se);
System.exit(1);
}
System.exit(0);
}
}
同期型呼び出しの場合と同様です。「4.2.1(3) TSCユーザプロキシを呼び出すコード」を参照してください。