17.4.1 リクエストを起動

リクエストを送信する最も単純な方法は,そのリクエストのinvokeメソッドを呼び出すことです。このメソッドはリクエストを送信し,応答を待ってからクライアントプログラムに戻ります。return_valueメソッドは,リターン値を表すAnyオブジェクトのポインタ(C++)またはリファレンス(Java)を返します。

コードサンプル17-18 invokeを使用してリクエストを送信する(C++)

try {
  . . .
  // Create request that will be sent to the account object
  request = account->_request("balance");
  // Set the result type
  request->set_return_type(CORBA::_tc_float);
  // Execute the request to the account object
  request->invoke();
  // Get the return balance
  CORBA::Float balance;
  CORBA::Any& balance_result = request->return_value();
  balance_result >>= balance;
  // Print out the balance
  cout << "The balance in " << name << "'s account is $"
        << balance << endl;
} catch(const CORBA::Exception& e) {
  cerr << e << endl;
  return 1;
}
return 0;
. . .

コードサンプル17-19 invokeを使用してリクエストを送信する(Java)

try {
  . . .
  // Create request that will be sent to the account object
  request = account._request("balance");
  // Set the result type
  request.set_return_type(orb.get_primitive_tc
                 (org.omg.CORBA.TCKind.tk_float));
  // Execute the request to the account object
  request.invoke();
  // Get the return balance
  float balance;
  org.omg.CORBA.Any balance_result = request.return_value();
  balance = balance_result.extract_float();
  // Print out the balance
  System.out.println("The balance in " + name +
                     "'s account is $" + balance);
} catch(Exception e) {
  e.printStackTrace();
}