bea ホーム | 製品 | dev2dev | support | askBEA |
![]() |
![]() |
|
![]() |
e-docs > Tuxedo > Tuxedo CORBA ノーティフィケーション・サービス > CosNotification サービス API の使い方 |
Tuxedo CORBA ノーティフィケーション・サービス
|
CosNotification サービス API の使い方
この章では、CosNotification サービス API と C++ および Java プログラミング言語を使用してノーティフィケーション・サービス・アプリケーションを作成するための開発手順を説明します。
ここでは、以下の内容について説明します。
開発プロセス
表 4-1 は、ノーティフィケーション・サービス・アプリケーションの開発プロセスの概略です。
イベントの設計
イベントの設計は、あらゆるノーティフィケーション・サービスの基本です。イベントの設計は、一致するサブスクリプションに配信される情報の量だけでなく、ノーティフィケーション・サービスの効率と性能にも影響します。したがって、計画を慎重に行って、ノーティフィケーション・サービスが現在のニーズだけでなく将来の規模拡大にも対応できるようにする必要があります。イベント設計の説明については、第 2 章の 8 ページ「イベントの設計」を参照してください。
ステップ 1: イベントをポストするアプリケーションの記述
次のタイプの CORBA アプリケーションは、イベントをポストできます。
注記 BEA Tuxedo 8.0 では、Java のクライアントと共同クライアント/サーバがサポートされていますが、Java サーバはサポートされていません。Java サーバは BEA WebLogic Enterprise 製品のバージョン 5.0 と 5.1 ではサポートされていましたが、BEA WebLogic Enterprise がリリース 8.0 で BEA Tuxedo と結合された時点でそのサポートは除外されました。
イベントをポストするために、アプリケーションでは最低でも次の機能をインプリメントする必要があります。
以降の節では、これらの各機能について説明します。
イベント・チャネルの取得
最初にイベント・チャネルを取得しないと、クライアント・アプリケーションではイベントをポストできません。
この開発ステップは、リスト4-1 で示されています。リスト4-1 は、CosNotification サービス API を使用する Introductory サンプル・アプリケーションの Reporter.cpp ファイルのコードです。
イベント・チャネル・ファクトリのオブジェクト・リファレンスを取得するために、"NotificationService" 環境オブジェクトを使用して Bootstrap オブジェクトの resolve_initial_references メソッドが呼び出されます。取得したオブジェクト・リファレンスは、チャネル・ファクトリを取得するために使用します。チャネル・ファクトリは、イベント・チャネルを取得するために使用します。リスト4-1 と リスト4-2 は、C++ および Java のコード例を示しています。
コード リスト 4-1 イベント・チャネルの取得 (Reporter.cpp)
// CosNotification チャネル・ファクトリのオブジェクト・リファレンスを取得
CORBA::Object_var channel_factory_oref =
bootstrap.resolve_initial_references(
"NotificationService" );
CosNotifyChannelAdmin::EventChannelFactory_var
channel_factory =
CosNotifyChannelAdmin::EventChannelFactory::_narrow(
channel_factory_oref.in() );
// チャネル・ファクトリを使用してデフォルト・チャネルを取得
CosNotifyChannelAdmin::EventChannel_var channel =
channel_factory->get_event_channel(
Tobj_Notification::DEFAULT_CHANNEL );
コード リスト 4-2 イベント・チャネルの取得 (Reporter.java)
import org.omg.CosNotification.*;//CosNotification API の一部
import org.omg.CosNotifyChannelAdmin.*;import // CosNotification API
// の残り
com.beasys.Tobj_Notification.*; // CosNotification API を使用するときに
// 必要な固有の定数
import com.beasys.Tobj.*;
import com.beasys.*;
import org.omg.CORBA.*;
import java.io.*;
// CosNotification チャネル・ファクトリのオブジェクト・リファレンスを取得
org.omg.CORBA.Object channel_factory_oref =
bootstrap.resolve_initial_references("NotificationService");
EventChannelFactory channel_factory =
EventChannelFactoryHelper.narrow(channel_factory_oref);
// チャネル・ファクトリを使用してデフォルト・チャネルを取得
EventChannel channel =
channel_factory.get_event_channel(DEFAULT_CHANNEL.value);
イベントの作成とポスト
イベントをポストするには、SupplierAdmin オブジェクトを取得し、そのオブジェクトを使用してプロキシを作成し、イベントを作成して、そのイベントをプロキシにポストする必要があります。
リスト4-3 と リスト4-4 は、それぞれ C++ と Java でのインプリメンテーションを示しています。
コード リスト 4-3 イベントの作成とポスト (Reporter.cpp)
// イベントをポストする側なので、
// SupplierAdmin オブジェクトを取得する
CosNotifyChannelAdmin::SupplierAdmin_var supplier_admin =
channel->default_supplier_admin();
// サプライヤ管理を使用してプロキシを作成する。イベントはそのプロキシ
// にポストされる (シンプル・イベント・インターフェイスの場合、イベント
// はチャネルにポストされる)
CosNotifyChannelAdmin::ProxyID proxy_id;
CosNotifyChannelAdmin::ProxyConsumer_var generic_proxy_consumer =
supplier_admin->obtain_notification_push_consumer(
CosNotifyChannelAdmin::STRUCTURED_EVENT, proxy_id );
CosNotifyChannelAdmin::StructuredProxyPushConsumer_var
proxy_push_consumer =
CosNotifyChannelAdmin::StructuredProxyPushConsumer::_narrow(
generic_proxy_consumer );
// イベントをポストできるようにプロキシに接続
proxy_push_consumer->connect_structured_push_supplier(
CosNotifyComm::StructuredPushSupplier::_nil() );
...
// イベントを作成
CosNotification::StructuredEvent notification;
// ドメインを「News」に設定
notification.header.fixed_header.event_type.domain_name =
CORBA::string_dup("News");
// 型をニュース・カテゴリに設定
notification.header.fixed_header.event_type.type_name =
CORBA::string_dup(“Sports” );
// 記事を格納するフィールドを 1 つイベントのフィルタ
// 処理可能データに追加。フィールドの名前は「Story」、
// 値は記事の文字列に設定
notification.filterable_data.length(1);
notification.filterable_data[0].name =
CORBA::string_dup("Story");
notification.filterable_data[0].value <<= “John Smith wins again” ;
// イベントをポスト
// ドメインが「News」で、型がニュース・カテゴリと一致する
// イベントをサブスクライブしたサブスクライバがこのイベント
// を受信する
proxy_push_consumer->push_structured_event(notification);
...
// 接続を解除
proxy_push_consumer->disconnect_structured_push_consumer();
コード リスト 4-4 イベントの作成とポスト (Reporter.java)
// イベントをポストする側なので、
// サプライヤ管理オブジェクトを取得する
SupplierAdmin supplier_admin =
channel.default_supplier_admin();
// サプライヤ管理を使用してプロキシを作成する。イベントはそのプロキシ
// にポストされる (シンプル・イベント・インターフェイスの場合、イベント
// はチャネルにポストされる)
IntHolder proxy_id = new IntHolder();
ProxyConsumer generic_proxy_consumer =
supplier_admin.obtain_notification_push_consumer(
ClientType.STRUCTURED_EVENT, proxy_id );
m_proxy_push_consumer =
StructuredProxyPushConsumerHelper.narrow(
generic_proxy_consumer);
// イベントをポストできるようにプロキシに接続
m_proxy_push_consumer.connect_structured_push_supplier(null);
...
// イベントを作成
StructuredEvent notification = new StructuredEvent();
notification.header = new EventHeader();
// ヘッダの下位構造を作成
notification.header.fixed_header = new FixedEventHeader();
notification.header.fixed_header.event_type = new EventType();
// ドメインを「News」に設定
notification.header.fixed_header.event_type.domain_name = "News";
// 型をニュース・カテゴリに設定
notification.header.fixed_header.event_type.type_name = “Sports” ;
// このサンプルでは使用しないので、イベント名は空の
// 文字列に設定する
notification.header.fixed_header.event_name = "";
// このサンプルでは使用しないので、Variable ヘッダは空にする
notification.header.variable_header = new Property[0];
// 記事を格納するフィールドを 1 つイベントのフィルタ
// 処理可能データに追加。フィールドの名前は「Story」、
// 値は記事の文字列に設定
notification.filterable_data = new Property[1];
notification.filterable_data[0] = new Property();
notification.filterable_data[0].name = "Story";
notification.filterable_data[0].value = orb.create_any();
notification.filterable_data[0].value.insert_string(“John Smith wins again” );
// このサンプルでは使用しないので、残りの本文は
// 新しい (空の) Any に設定する
notification.remainder_of_body = orb.create_any();
m_proxy_push_consumer.push_structured_event(notification);
...
// 接続を解除 proxy_push_consumer.disconnect_structured_push_consumer();
ステップ 2: イベントをサブスクライブするアプリケーションの記述
次のタイプの CORBA アプリケーションは、イベントをサブスクライブできます。
注記 BEA Tuxedo 8.0 では、Java のクライアントと共同クライアント/サーバがサポートされていますが、Java サーバはサポートされていません。Java サーバは BEA WebLogic Enterprise 製品のバージョン 5.0 と 5.1 ではサポートされていましたが、BEA WebLogic Enterprise がリリース 8.0 で BEA Tuxedo と結合された時点でそのサポートは除外されました。
イベントをサブスクライブするために、アプリケーションでは最低でも次の機能をサポートする必要があります。
CosNotifyComm::StructuredPushConsumer インターフェイスのインプリメント
コールバック・サーバント・オブジェクトでイベントを受信するためには、push_structured_event オペレーションをサポートする CosNotifyComm::StructuredPushConsumer インターフェイスをインプリメントする必要があります。一致するサブスクリプションがあるイベントが発生すると、ノーティフィケーション・サービスではサブスクライバ・アプリケーションのサーバント・コールバック・オブジェクトのこのオペレーションを呼び出してイベントをサブスクライバ・アプリケーションに配信します。
CosNotifyComm::StructuredPushConsumer インターフェイスでは、offer_change および disconnect_structured_push_consumer というオペレーションも定義されます。これらのオペレーションはノーティフィケーション・サービスで呼び出されないので、CORBA::NO_IMPLEMENT をスローするスタブ・アウト・バージョンをインプリメントする必要があります。
リスト4-5 と リスト4-6 は、このインターフェイスが C++ でどのようにインプリメントされるのかを示しています。
コード リスト 4-5 CosNotifyComm::StructuredPushConsumer インターフェイスのサンプル・インプリメンテーション (NewsConsumer_i.h)
#ifndef _news_consumer_i_h
#define _news_consumer_i_h
#include "CosNotifyComm_s.h"
// サーバント・クラスでニュース・イベントを受信するためには、
// CosNotifyComm::StructuredPushConsumer idl インターフェイス
// をインプリメントする必要がある
class NewsConsumer_i : public POA_CosNotifyComm::StructuredPushConsumer
{
public:
// このメソッドはニュース・イベントの発生時に呼び出される
virtual void push_structured_event(
const CosNotification::StructuredEvent& notification
);
// OMG の CosNotifyComm::StructuredPushConsumer idl インターフェイス
// では、offer_change メソッドと disconnect_structured_push_consumer
// メソッドが定義される。ノーティフィケーション・サービスからそれらの
// メソッドが呼び出されることはないので、ただ単に CORBA::NO_IMPLEMENT
// 例外をスローさせる
virtual void offer_change(
const CosNotification::EventTypeSeq& added,
const CosNotification::EventTypeSeq& removed )
{
throw CORBA::NO_IMPLEMENT();
}
virtual void disconnect_structured_push_consumer()
{
throw CORBA::NO_IMPLEMENT();
}
};
#endif
コード リスト 4-6 CosNotifyComm::StructuredPushConsumer インターフェイスのサンプル・インプリメンテーション (NewsConsumer_i.cpp)
#include "NewsConsumer_i.h"
#include <iostream.h>
//-----------------------------------------------------------
// Subscriber.cpp は「News」イベントのシンプル・イベント・
// サブスクリプションを作成し、イベントが NewsConsumer_i オブジェクト
// に配信されるようにする。ニュース・イベントが発生すると (ユーザが
// Reporter アプリケーションを実行してニュース記事を報告すると発生する)、
// 次のメソッドが呼び出される
void NewsConsumer_i::push_structured_event(
const CosNotification::StructuredEvent& notification )
{
// extract the story from the first field in the event's
// filterable data
char* story;
notification.filterable_data[0].value >>= story;
// コードを単純化するために、「story」は「null」ではないと想定
// イベントを出力
cout
<< "-----------------------------------------------------"
<< endl
<< "Category : "
<< notification.header.fixed_header.
event_type.type_name.in()
<< endl
<< "Story : "
<< story
<< endl;
...
}
コード リスト 4-7 CosNotifyComm::StructuredPushConsumer インターフェイスのサンプル・インプリメンテーション (NewsConsumer_i.java)
import org.omg.CosNotification.*;
import org.omg.CosNotifyComm.*;
import org.omg.CORBA.*;
//---------------------------------------------------------------
// サーバント・クラスでニュース・イベントを受信するためには、
// CosNotifyComm::StructuredPushConsumer idl インターフェイス
// をインプリメントする必要がある
public class NewsConsumer_i extends
_StructuredPushConsumerImplBase
{
// Subscriber.java は「News」イベントのシンプル・イベント・// サブスクリプションを作成し、イベントが NewsConsumer_i オブジェクト
// に配信されるようにする。ニュース・イベントが発生すると (ユーザが
// Reporter アプリケーションを実行してニュース記事を報告すると発生する)、
// 次のメソッドが呼び出される
public void push_structured_event(StructuredEvent notification)
{
// コードを単純化するため以下を想定
// notification.header.fixed_header.event_type.domain_name は
// 「News」
// notification.header.fixed_header.event_type.type_name は
// ニュース・カテゴリ
// notification.filterable_data.length は 1
// notification.filterable_data[0].name は「Story」
// notification.filterable_data[0].value には記事 (文字列) が
// 格納されている
// イベントのフィルタ処理可能データの最初のフィールドから
// 記事を抽出する。コードを単純化するため、フィールドに
// 文字列が格納されていないことを
// 示すエラーは処理しない
String story =
notification.filterable_data[0].value.extract_string();
// イベントを出力
System.out.println("-------------------------------------");
System.out.println( "Category : " +
notification.header.fixed_header.event_type.type_name
);
System.out.println( "Story : " + story
);
// この時点では、メインがシャットダウン・オブジェクトに対して
// 「wait_for_shutdown」メソッドを呼び出している。このメソッドは、シャットダウン
// マネージャに対して「shutdown」メソッドが呼び出されるまでブロックする。
// シャットダウンマネージャに対して「shutdown」メソッドを
// 呼び出すと、「wait_for_shutdown」が返される。その後、メインが
// アプリケーションをシャットダウンする
m_shutdown_manager.shutdown();
}
// OMG の CosNotifyComm::StructuredPushConsumer idl インターフェイス
// では、offer_change メソッドと disconnect_structured_push_consumer
// メソッドが定義される。ノーティフィケーション・サービスからそれらの
// メソッドが呼び出されることはないので、ただ単に CORBA::NO_IMPLEMENT
// 例外をスローさせる
public void disconnect_structured_push_consumer()
{
throw new NO_IMPLEMENT();
}
public void offer_change(EventType[] added, EventType[] removed)
{
throw new NO_IMPLEMENT();
}
}
イベント・チャネル、ConsumerAdmin オブジェクト、およびフィルタ・ファクトリ・オブジェクトの取得
最初にイベント・チャネル、ConsumerAdmin オブジェクト、およびフィルタ・ファクトリ・オブジェクトを取得しないと、アプリケーションではサブスクリプションを作成できません。リスト4-8 と リスト4-9 は、それぞれ C++ と Java でのインプリメンテーションを示しています。
イベント・チャネル・ファクトリのオブジェクト・リファレンスを取得するために、"NotificationService" 環境オブジェクトを使用して Bootstrap オブジェクトの resolve_initial_references メソッドが呼び出されます。取得したオブジェクト・リファレンスは、チャネル・ファクトリを取得するために使用します。チャネル・ファクトリは、イベント・チャネルを取得するために使用します。最後に、イベント・チャネルは ConsumerAdmin オブジェクトと FilterFactory オブジェクトを取得するために使用します。
コード リスト 4-8 イベント・チャネル、ConsumerAdmin オブジェクト、およびフィルタ・ファクトリ・オブジェクトの取得 (Subscriber.cpp)
// CosNotification チャネル・ファクトリのオブジェクト・リファレンスを取得
CORBA::Object_var
channel_factory_oref =
bootstrap.resolve_initial_references(
"NotificationService" );
CosNotifyChannelAdmin::EventChannelFactory_var
channel_factory =
CosNotifyChannelAdmin::EventChannelFactory::_narrow(
channel_factory_oref.in() );
// チャネル・ファクトリを使用してデフォルト・チャネルを取得
CosNotifyChannelAdmin::EventChannel_var channel =
channel_factory->get_event_channel(
Tobj_Notification::DEFAULT_CHANNEL );
// チャネルを使用してコンシューマ管理とフィルタ・ファクトリを取得
CosNotifyChannelAdmin::ConsumerAdmin_var consumer_admin =
channel->default_consumer_admin();
CosNotifyFilter::FilterFactory_var filter_factory =
channel->default_filter_factory();
コード リスト 4-9 イベント・チャネルの取得 (Subscriber.java)
// CosNotification チャネル・ファクトリのオブジェクト・リファレンスを取得
org.omg.CORBA.Object channel_factory_oref =
bootstrap.resolve_initial_references("NotificationService");
EventChannelFactory channel_factory =
EventChannelFactoryHelper.narrow(channel_factory_oref);
// チャネル・ファクトリを使用してデフォルト・チャネルを取得
EventChannel channel =
channel_factory.get_event_channel(DEFAULT_CHANNEL.value);
// チャネルを使用してコンシューマ管理とフィルタ・ファクトリを取得
ConsumerAdmin consumer_admin =
channel.default_consumer_admin();
FilterFactory filter_factory =
channel.default_filter_factory();
コールバック・オブジェクトの作成
イベントを受信するためには、アプリケーションはサーバであることも必要です。つまり、アプリケーションでは、サブスクライバのサブスクリプションと一致するイベントが発生したときに呼び出すことができるコールバック・オブジェクトをインプリメントしなければなりません。
コールバック・オブジェクトを作成する手順は次のとおりです。
注記 この手順は、共同クライアント/サーバでの手順です。BEA Tuxedo CORBA サーバでもイベントをサブスクライブできます。
BEAWrapper コールバック・オブジェクトとそのメソッドの詳細については、『BEA Tuxedo CORBA プログラミング・リファレンス』の「共同クライアント/サーバ」を参照してください。
注記 BEAWrapper コールバック・オブジェクトを使用してコールバック・オブジェクトを作成する方法は、以下に説明します。POA を使用してコールバック・オブジェクトをインプリメントする方法については、『BEA Tuxedo CORBA サーバ間通信』を参照してください。
リスト4-10 と リスト4-11 は、それぞれ C++ および Java で、BEAWrapper コールバック・オブジェクトを使用してコールバック・オブジェクトを作成する方法を示しています。コード例では、NewsConsumber_i servant が作成され、start_transient メソッドを使用して一時的なオブジェクト・リファレンスが作成されます。
コード リスト 4-10 一時的なオブジェクト・リファレンスでコールバック・オブジェクトを作成するサンプル・コード (Introductory サンプル・アプリケーションの Subscriber.cpp)
// このクライアントではコールバックをサポートする必要があるので
// コールバック・ラッパー・オブジェクトを作成する
BEAWrapper::Callbacks wrapper(orb.in());
NewsConsumer_i* news_consumer_impl = new NewsConsumer_i;
// このサーバントの一時的なオブジェクト・リファレンスを作成
CORBA::Object_var news_consumer_oref =
wrapper.start_transient(
news_consumer_impl,
CosNotifyComm::_tc_StructuredPushConsumer->id()
);
CosNotifyComm::StructuredPushConsumer_var
news_consumer =
CosNotifyComm::StructuredPushConsumer::_narrow(
news_consumer_oref.in() );
コード リスト 4-11 一時的なオブジェクト・リファレンスでコールバック・オブジェクトを作成するサンプル・コード (Introductory サンプル・アプリケーションの Subscriber.java)
// このクライアントではコールバックをサポートする必要があるので
// コールバック・ラッパー・オブジェクトを作成する
Callbacks callbacks = new Callbacks(orb);
// イベントを受信するサーバントをインスタンス化
NewsConsumer_i news_consumer_impl =
new NewsConsumer_i(shutdown_manager);
// コールバック・サーバントの一時的なオブジェクト・リファレンスを作成
callbacks.start_transient(
news_consumer_impl,
news_consumer_impl._ids()[0]
);
サブスクリプションの作成
サブスクライバでイベントを受信するためには、ノーティフィケーション・サービスをサブスクライブする必要があります。一時的なサブスクリプションまたは永続的なサブスクリプションのいずれかを作成できます。
サブスクリプションを作成するには、次の手順を実行する必要があります。
Introductory サンプル・アプリケーションのコードである リスト4-12 と リスト4-13 は、それぞれ C++ および Java で一時的なサブスクリプションを作成する方法を示しています。
コード リスト 4-12 一時的なサブスクリプションの作成
// 新しいサブスクリプションを作成 (この時点ではまだ完全ではない)
CosNotifyChannelAdmin::ProxyID subscription_id;
CosNotifyChannelAdmin::ProxySupplier_var generic_subscription =
consumer_admin->obtain_notification_push_supplier(
CosNotifyChannelAdmin::STRUCTURED_EVENT,
subscription_id );
CosNotifyChannelAdmin::StructuredProxyPushSupplier_var
subscription =
CosNotifyChannelAdmin::StructuredProxyPushSupplier::_narrow(
generic_subscription );
s_subscription = subscription.in();
// サービスの品質を設定する。これでサブスクリプション名
// とサブスクリプションのタイプ (TRANSIENT) が設定される
CosNotification::QoSProperties qos;
qos.length(2);
qos[0].name =
CORBA::string_dup(Tobj_Notification::SUBSCRIPTION_NAME);
qos[0].value <<= subscription_name;
qos[1].name =
CORBA::string_dup(Tobj_Notification::SUBSCRIPTION_TYPE);
qos[1].value <<=
Tobj_Notification::TRANSIENT_SUBSCRIPTION;
subscription->set_qos(qos);
// フィルタを作成 (ドメイン、型、およびデータ・フィルタの指定に使用)
CosNotifyFilter::Filter_var filter =
filter_factory->create_filter(
Tobj_Notification::CONSTRAINT_GRAMMAR );
s_filter = filter.in();
// フィルタ処理パラメータを設定
// (ドメイン = "News"、型 = "Sports"、およびデータ・フィルタなし)
CosNotifyFilter::ConstraintExpSeq constraints;
constraints.length(1);
constraints[0].event_types.length(1);
constraints[0].event_types[0].domain_name =
CORBA::string_dup("News");
constraints[0].event_types[0].type_name =
CORBA::string_dup(“Sports” );
constraints[0].constraint_expr =
CORBA::string_dup(""); // データ・フィルタなし
CosNotifyFilter::ConstraintInfoSeq_var
add_constraints_results = // この戻り値は無視
filter->add_constraints(constraints);
// フィルタをサブスクリプションに追加
CosNotifyFilter::FilterID filter_id =
subscription->add_filter(filter.in());
// サブスクリプションの名前、タイプ、およびフィルタ処理の各パラメータ
// が設定されたので、イベントを配信するコールバック・オブジェクトの
// オブジェクト・リファレンスを渡してサブスクリプションを完成する
subscription->connect_structured_push_consumer(
news_consumer.in() );
コード リスト 4-13 一時的なサブスクリプションの作成 (Introductory の Subscriber.java)
// 新しいサブスクリプションを作成 (この時点ではまだ完全ではない)
IntHolder subscription_id = new IntHolder();
ProxySupplier generic_subscription =
consumer_admin.obtain_notification_push_supplier(
ClientType.STRUCTURED_EVENT,
subscription_id );
StructuredProxyPushSupplier subscription =
StructuredProxyPushSupplierHelper.narrow(
generic_subscription );
// サービスの品質を設定する。これでサブスクリプション名
// とサブスクリプションのタイプ (TRANSIENT) が設定される
Property qos[] = new Property[2];
qos[0] = new Property();
qos[0].name = SUBSCRIPTION_NAME.value;
qos[0].value = orb.create_any();
qos[0].value.insert_string(subscription_name);
qos[1] = new Property();
qos[1].name = SUBSCRIPTION_TYPE.value;
qos[1].value = orb.create_any();
qos[1].value.insert_short(TRANSIENT_SUBSCRIPTION.value);
subscription.set_qos(qos);
// フィルタを作成 (ドメイン、型、およびデータ・フィルタの指定に使用)
Filter filter =
filter_factory.create_filter(CONSTRAINT_GRAMMAR.value);
// フィルタ処理パラメータを設定
// (ドメイン = "News"、型 = "Sports"、およびデータ・フィルタなし)
ConstraintExp constraints[] = new ConstraintExp[1];
constraints[0] = new ConstraintExp();
constraints[0].event_types = new EventType[1];
constraints[0].event_types[0] = new EventType();
constraints[0].event_types[0].domain_name = "News";
constraints[0].event_types[0].type_name = “Sports” ;
constraints[0].constraint_expr = "";
ConstraintInfo add_constraints_results[] =
filter.add_constraints(constraints);
// フィルタをサブスクリプションに追加
int filter_id = subscription.add_filter(filter);
// サブスクリプションの名前、タイプ、およびフィルタ処理の各パラメータ
// が設定されたので、イベントを配信するコールバック・オブジェクトの
// オブジェクト・リファレンスを渡してサブスクリプション
// を完成する
subscription.connect_structured_push_consumer(
news_consumer_impl );
ステップ 3: ノーティフィケーション・サービス・アプリケーションのコンパイルと実行
ノーティフィケーション・サービス・アプリケーション開発の最後のステップでは、アプリケーションをコンパイル、ビルド、および実行します。そのためには、次の手順を実行する必要があります。
クライアント・スタブ・ファイルとスケルトン・ファイルの生成
クライアント・スタブ・ファイルとスケルトン・ファイルを生成するには、アプリケーションで使用されるノーティフィケーション IDL ファイルごとに idl コマンドを実行する必要があります。表 4-2 は、各タイプのサブスクライバで使用する idl コマンドを示しています。
次に、idl コマンドの例を示します。 >idl -IC:¥tuxdir¥include C:¥tuxdir¥include¥CosEventComm.idl 表 4-3 は、各タイプのノーティフィケーション・サービス・アプリケーションで必要な IDL ファイルを示しています。
アプリケーション・コードのコンパイルとリンク
コンパイルとリンクの手続きは、ノーティフィケーション・サービス・アプリケーションのタイプによって異なります。表 4-4 は、各タイプのアプリケーションをコンパイルするために使用するコマンドとファイルの概要を示しています。
リスト4-14 は、Microsoft Windows システム上の C++ Reporter アプリケーション (Reporter.cpp) で使用するコマンドを示しています。C++ の実行可能ファイルを作成するために、idl コマンドが必要な IDL ファイルで実行され、buildobjclient コマンドによって C++ クライアント・アプリケーション・ファイルと IDL スタブがコンパイルされます。 コード リスト 4-14 C++ Reporter アプリケーションのビルドと実行のコマンド リスト4-15 と リスト4-16 は、それぞれ Microsoft Windows および UNIX 上の C++ Subscriber アプリケーション (Subscriber.cpp) で使用するコマンドを示しています。C++ の実行可能ファイルを作成するために、-P オプションを設定した buildobjclient コマンドによって、共同クライアント/サーバ・アプリケーション・ファイル (Subscriber.cpp と NewsConsumer_i.cpp)、IDL スタブ、および IDL スケルトン (CosNotifyComm_s.cpp 用) がコンパイルされます。 コード リスト 4-15 C++ Subscriber アプリケーションのビルドと実行のコマンド (Microsoft Windows) コード リスト 4-16 C++ Subscriber アプリケーションのビルドと実行のコマンド (UNIX) リスト4-17 と リスト 4-18 は、リモートの Java Reporter アプリケーションおよび Java Subscriber アプリケーションをリンク、ビルド、および実行するために使用するコマンドの例を示しています。 コード リスト 4-17 Java Reporter アプリケーションのリンク、ビルド、および実行のコマンド コード リスト 4-18 注記 リスト 4-18 の java コマンド行は、アプリケーションコード内でポートを設定するアプリケーション、またはユーザにポートの設定を要求するアプリケーションです。java コマンド行でポートを設定することもできます。ポート番号を設定する java コマンド行の例を次に示します。 java -DTOBJADDR=//BEANIE:2359 ¥ -Dorg.omg.corba.ORBPort=portnumber -classpath...
# idl コマンドを実行
idl -IC:¥tuxdir¥include C:¥tuxdir¥include¥CosEventComm.idl ¥
C:¥tuxdir¥include¥CosEventChannelAdmin ¥
C:¥tuxdir¥include¥CosNotification.idl ¥
C:¥tuxdir¥include¥CosNotifyComm.idl ¥
C:¥tuxdir¥include¥CosNotifyFilter.idl ¥
C:¥tuxdir¥include¥Tobj_Notification.idl # buildobjclient コマンドを実行
buildobjclient -v -o is_reporter.exe -f ” ¥
-DWIN32 ¥
Reporter.cpp ¥
CosEventComm_c.cpp ¥
CosEventChannelAdmin_c.cpp ¥
CosNotification_c.cpp ¥
CosNotifyComm_c.cpp ¥
CosNotifyFilter_c.cpp ¥
CosNotifyChannelAdmin_c.cpp ¥
Tobj_Events_c.cpp ¥
Tobj_Notification_c.cpp ” # アプリケーションを実行
is_reporter# idl コマンドを実行
idl -P -IC:¥tuxdir¥include C:¥tuxdir¥include¥CosEventComm.idl ¥
C:¥tuxdir¥include¥CosEventChannelAdmin ¥
C:¥tuxdir¥include¥CosNotification.idl ¥
C:¥tuxdir¥include¥CosNotifyComm.idl ¥
C:¥tuxdir¥include¥CosNotifyFilter.idl ¥
C:¥tuxdir¥include¥CosNotifyChannelAdmin ¥ ¥C:¥tuxdir¥include¥Tobj_Events.idl ¥
¥C:¥tuxdir¥include¥Tobj_Notification# buildobjclient コマンドを実行
buildobjclient -v -P -o is_subscriber.exe -f " ¥
-DWIN32 ¥
Subscriber.cpp ¥
NewsConsumer_i.cpp ¥
CosEventComm_c.cpp ¥
CosEventChannelAdmin_c.cpp ¥
CosNotification_c.cpp ¥
CosNotifyComm_c.cpp ¥
CosNotifyComm_s.cpp ¥
CosNotifyFilter_c.cpp ¥
CosNotifyChannelAdmin_c.cpp ¥
Tobj_Events_c.cpp ¥
Tobj_Notification_c.cpp ¥
C:¥tuxdir¥lib¥libbeawrapper.lib ¥
"# アプリケーションを実行
is_subscriber# idl コマンドを実行
idl -P -I/usr/local/tuxdir/include /usr/local/tuxdir/include/CosEventChannelAdmin ¥
/usr/local/tuxdir/include/CosEventComm.idl ¥
/usr/local/tuxdir/include/CosNotification.idl ¥
/usr/local/tuxdir/include/CosNotifyComm.idl ¥
/usr/local/tuxdir/include/CosNotifyFilter.idl ¥
/usr/local/tuxdir/include/CosNotifyChannelAdmin ¥
/usr/local/tuxdir/include/Tobj_Events.idl ¥
/usr/local/tuxdir/include/Tobj_SimpleEvents.idl# buildobjclient コマンドを実行
buildobjclient -v -P -o subscriber -f " ¥
Subscriber.cpp ¥
NewsConsumer_i.cpp ¥
CosEventComm_c.cpp ¥
CosEventChannelAdmin_c.cpp ¥
CosNotification_c.cpp ¥
CosNotifyComm_c.cpp ¥
CosNotifyComm_s.cpp ¥
CosNotifyFilter_c.cpp ¥
CosNotifyChannelAdmin_c.cpp ¥
Tobj_Events_c.cpp ¥
Tobj_SimpleEvents_c.cpp ¥
-lbeawrapper ¥
"
# アプリケーションを実行
is_subscriber# idltojava コマンドを実行
idltojava -IC:¥tuxdir¥include C:¥tuxdir¥include¥CosEventComm.idl ¥
C:¥tuxdir¥include¥CosEventChannelAdmin.idl ¥
C:¥tuxdir¥include¥CosNotification.idl C:¥tuxdir¥include¥CosNotifyComm.idl ¥
C:¥tuxdir¥include¥CosNotifyFilter.idl ¥
C:¥tuxdir¥include¥CosNotifyChannelAdmin.idl ¥
C:¥tuxdir¥include¥Tobj_Events.idl ¥
C:¥tuxdir¥include¥Tobj_Notification.idl# Java ファイルをコンパイル
javac -classpath C:¥tuxdir¥udataobj¥java¥jdk¥m3envobj.jar Reporter.java# Java .class ファイルを Java アーカイブ (JAR) ファイルに結合
jar cf reporter.jar Reporter.class org¥omg¥CosEventComm ¥
org¥omg¥CosEventChannelAdmin org¥omg¥CosNotification org¥omg¥CosNotifyComm ¥
org¥omg¥CosNotifyFilter org¥omg¥CosNotifyChannelAdmin com¥beasys¥Tobj_Events ¥
com¥beasys¥Tobj_Notification# Reporter アプリケーションを実行
java -DTOBJADDR=//BEANIE:2359 -classpath ¥
reporter.jar;C:¥tuxdir¥udataobj¥java¥jdk¥m3envobj.jar Reporter# idltojava コマンドを実行
idltojava -IC:¥tuxdir¥include C:¥tuxdir¥include¥CosEventComm.idl ¥
C:¥tuxdir¥include¥CosEventChannelAdmin.idl ¥
C:¥tuxdir¥include¥CosNotification.idl C:¥tuxdir¥include¥CosNotifyComm.idl ¥
C:¥tuxdir¥include¥CosNotifyFilter.idl ¥
C:¥tuxdir¥include¥CosNotifyChannelAdmin.idl ¥
C:¥tuxdir¥include¥Tobj_Events.idl C:¥tuxdir¥include¥Tobj_Notification.idl# Java ファイルをコンパイル
javac -classpath C:¥tuxdir¥udataobj¥java¥jdk¥m3envobj.jar;¥
C:¥tuxdir¥udataobj¥java¥jdk¥wleclient.jar Subscriber.java# Java .class ファイルを Java アーカイブ (JAR) ファイルに結合
jar cf subscriber.jar Subscriber.class NewsConsumer_i.class ¥
org¥omg¥CosEventComm org¥omg¥CosEventChannelAdmin org¥omg¥CosNotification ¥
org¥omg¥CosNotifyComm org¥omg¥CosNotifyFilter org¥omg¥CosNotifyChannelAdmin ¥
com¥beasys¥Tobj_Events com¥beasys¥Tobj_Notification# サブスクライバ・アプリケーションを実行
java -DTOBJADDR=//BEANIE:2359 -classpath ¥
subscriber.jar;C:¥tuxdir¥udataobj¥java¥jdk¥m3envobj.jar;¥
C:¥tuxdir¥udataobj¥java¥jdk¥wleclient.jar Subscriber
![]() |
![]() |
![]() |
![]() |
||
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |