ページの先頭行へ戻る
Interstage Application Server アプリケーション作成ガイド(イベントサービス編)
FUJITSU Software

6.4 Mixedモデル

C++言語でのMixedモデルのアプリケーションの開発について説明します。


(1)概要

Mixedモデルは、PushモデルとPullモデルの2つの通信モデルを使用します。サプライヤは、イベントチャネルにイベントデータを送信し、コンシューマはイベントチャネルにイベントデータを要求します。
本概要を以下の図に示します。



(2)サプライヤの作成

サプライヤは、イベントチャネルにイベントデータを送信します。Pushモデルのサプライヤと同様のインタフェースを使用します。
サプライヤからコンシューマにイベントデータを送信する処理の鉄好きの例、および処理の流れを以下に示します。


イベントサービスの場合

[C++言語によるMixedモデルのサプライヤ]

CORBA::Boolean func() {
    ... 
    try {
        supplier = EventCh->for_suppliers( env );                  /* 1 */
        proxy_push = supplier->obtain_push_consumer( env );        /* 2 */
        proxy_push->connect_push_supplier(CORBA_OBJECT_NIL, env);  /* 3 */
        proxy_push->push( data, env );                             /* 4 */
        proxy_push->disconnect_push_consumer( env );               /* 5 */
    } catch( CORBA::Exception &e ) {
             ... 
    }
    ... 
}

ノーティフィケーションサービスの場合

[C++言語によるMixedモデル(StructuredEvent型)のサプライヤ]

CORBA::Boolean func() {
    ...
    try {
        supplier = EventCh->default_supplier_admin( env );          /* 1 */
        tmp_proxy = supplier->obtain_notification_push_consumer
                                        (ctype,proxy_id, env );     /* 2 */
        proxy_push = CosNotifyChannelAdmin::
           StructuredProxyPushConsumer::_narrow( tmp_proxy ); 
        proxy_push->connect_structured_push_supplier
             (CosNotifyComm::StructuredPushSupplier::_nil(),env);   /* 3 */
        proxy_push->push_structured_event(data,env);                /* 4 */
        proxy_push->disconnect_structured_push_consumer(env);       /* 5 */
    } catch( CORBA::Exception &e ) {
             ... 
    }      ... 
}

[C++言語によるMixedモデル(any型)のサプライヤ]

CORBA::Boolean func() {
    ...
    try {
        supplier = EventCh->default_supplier_admin( env );          /* 1 */
        tmp_proxy = supplier->obtain_notification_push_consumer
                                        (ctype,proxy_id, env );     /* 2 */
        proxy_push = CosNotifyChannelAdmin::
           ProxyPushConsumer::_narrow( tmp_proxy ); 
        proxy_push->connect_any_push_supplier
             (CosEventComm::PushSupplier::_nil(),env);              /* 3 */
        proxy_push->push(data,env);                                 /* 4 */
        proxy_push->disconnect_push_consumer(env);                  /* 5 */
    } catch( CORBA::Exception &e ) {
             ... 
    }      ... 
}

  1. イベントチャネル管理オブジェクトのオブジェクトリファレンスを獲得します。

  2. イベントチャネルのオブジェクトリファレンスを獲得します。

  3. イベントチャネルと接続します。

  4. イベントチャネルにイベントデータを送信します。

  5. イベントチャネルと切断します。


(3)コンシューマの作成

コンシューマは、イベントチャネルにイベントデータを要求します。Pullモデルのコンシューマと同様のインタフェースを使用します。
コンシューマがイベントチャネルにイベントデータを要求する手続きの例、および処理の流れを以下に示します。


イベントサービスの場合

[C++言語によるMixedモデルのコンシューマ]

CORBA::Boolean func() {
    ... 
    try {
        consumer = EventCh->for_consumers( env );                  /* 1 */
        proxy_pull = consumer->obtain_pull_supplier( env );        /* 2 */
        proxy_pull->connect_pull_consumer(CORBA_OBJECT_NIL, env);  /* 3 */
        data = proxy_pull->pull( env );                            /* 4 */
        proxy_pull->disconnect_pull_supplier( env );               /* 5 */
    } catch( CORBA::Exception &e ) {
             ... 
    }
    ... 
}

ノーティフィケーションサービスの場合

[C++言語によるMixedモデル(StructuredEvent型)のコンシューマ]

CORBA::Boolean func() {
    ... 
    try {
        consumer = EventCh->default_consumer_admin( env );          /* 1 */
        tmp_proxy = consumer->obtain_notification_pull_supplier
                                              (ctype,proxy_id,env); /* 2 */
        proxy_pull = CosNotifyChannelAdmin::
           StructuredProxyPullSupplier::_narrow( tmp_proxy ); 
        proxy_pull->connect_structured_pull_consumer
              (CosNotifyComm::StructuredPullConsumer::_nil(),env);  /* 3 */
        data = proxy_pull->pull_structured_event(env);              /* 4 */
        proxy_pull->disconnect_structured_pull_supplier(env);       /* 5 */
    } catch( CORBA::Exception &e ) {
             ... 
    }
    ... 
}

[C++言語によるMixedモデル(any型)のコンシューマ]

CORBA::Boolean func() {
    ... 
    try {
        consumer = EventCh->default_consumer_admin( env );          /* 1 */
        tmp_proxy = consumer->obtain_notification_pull_supplier
                                              (ctype,proxy_id,env); /* 2 */
        proxy_pull = CosNotifyChannelAdmin::
           ProxyPullSupplier::_narrow( tmp_proxy ); 
        proxy_pull->connect_any_pull_consumer
              (CosEventComm::PullConsumer::_nil(),env);             /* 3 */
        data = proxy_pull->pull(env);                               /* 4 */
        proxy_pull->disconnect_pull_supplier(env);                  /* 5 */
    } catch( CORBA::Exception &e ) {
             ... 
    }
    ... 
}

  1. イベントチャネル管理オブジェクトのオブジェクトリファレンスを獲得します。

  2. イベントチャネルのオブジェクトリファレンスを獲得します。

  3. イベントチャネルと接続します。

  4. イベントチャネルからイベントデータを受信します。

  5. イベントチャネルと切断します。


注意

pullメソッド/pull_waitメソッドを発行してイベントデータを待ち合わせている状態で、disconnectメソッドを発行してイベントチャネルと切断しないように注意してください。イベントデータを待ち合わせている場合は、pull_cancellメソッドを発行してイベントデータの待合せを解除させてからdisconnectメソッドを発行してください。

pullメソッド/pull_waitメソッドを発行してイベントデータを待ち合わせている状態で、disconnectメソッドを発行すると、トレースファイルに以下のメッセージが多量に出力されて、I/Oエラーが発生する可能性があります。

Exception information : method = pull()、pull_structured_event()、またはpull_wait()
 exception = COMM_FAILURE minor = 0x464a01c2 group =(グループ名), channel = (イベントチャネル名),
 ClientIP = (アプリケーションのIPアドレス) pid = (プロセスID) internalcode = (内部コード)