Interstage Application Server アプリケーション作成ガイド (イベントサービス編)
目次 索引 前ページ次ページ

第4章 アプリケーションの開発(各機能)> 4.1 イベントチャネル接続のアプリケーション開発> 4.1.1 ノーティフィケーションサービスのQoS機能の運用

4.1.1.1 QoSプロパティ項目の設定

 QoSプロパテ項目は、イベントチャネル(静的生成、動的生成)およびメッセージに設定できます。

(1)イベントチャネルに対するQoSプロパティ項目の設定方法

 静的生成イベントチャネルのQoSプロパティ項目の設定は、CosNotification_QoSAdmin_set_qos()を使って、QoSPropertiesを設定します。動的生成イベントチャネルのQoSプロパティ項目の設定は、CosNotifyChannelAdmin_EventChannelFactory_create_channel()を使ってイベントチャネルの生成時に、QoSPropertiesを設定します。QoSPropertiesはProperty構造体からなるシーケンス型です。CプログラムでQoSPropertiesを作成し、イベントチャネルに対してQoSプロパティ項目を設定する例と処理の流れを以下に説明します。

[QoSPropertiesの作成例(Cの場合)]

    CORBA_short                    *priority;
    CORBA_unsigned_long_long       *timeout;
    CORBA_short                    *orderpolicy;
    CORBA_short                    *discardpolicy;
    CosNotification_Property       *pProperty;
    CosNotification_QoSProperties  *pQoS=NULL;

    priority  = CORBA_short_alloc();
    *priority = 1;                                                       /* 1 */

    timeout  = CORBA_unsigned_long_long_alloc();
    *timeout = 40;                                                       /* 2 */

    orderpolicy  = CORBA_short_alloc();
    *orderpolicy = CosNotification_PriorityOrder;                        /* 3 */

    discardpolicy  = CORBA_short_alloc();
    *discardpolicy = CosNotification_AnyOrder;                           /* 4 */

    pProperty = CosNotification_PropertySeq_allocbuf( 4 );               /* 5 */

    pProperty[0].name = CORBA_string_alloc( strlen( CosNotification_Priority ) );
    strcpy( pProperty[0].name, CosNotification_Priority );
    pProperty[0].value._type   = TC_short;
    pProperty[0].value._value  = priority;                               /* 6 */

    pProperty[1].name = CORBA_string_alloc( strlen( CosNotification_Timeout ) );
    strcpy( pProperty[1].name, CosNotification_Timeout );
    pProperty[1].value._type  = TC_ulonglong;
    pProperty[1].value._value = timeout;                                 /* 7 */

    pProperty[2].name = CORBA_string_alloc( strlen( CosNotification_OrderPolicy ) );
    strcpy( pProperty[2].name, CosNotification_OrderPolicy );
    pProperty[2].value._type   = TC_short;
    pProperty[2].value._value  = orderpolicy;                            /* 8 */

    pProperty[3].name = CORBA_string_alloc( strlen( CosNotification_DiscardPolicy ) );
    strcpy( pProperty[3].name, CosNotification_DiscardPolicy );
    pProperty[3].value._type   = TC_short;
    pProperty[3].value._value  = discardpolicy;                          /* 9 */

    pQoS = CosNotification_QoSProperties_alloc();                        /* 10 */
    pQoS->_length  = 4;
    pQoS->_maximum = 4;
    pQoS->_buffer  = pProperty;
        ... 
    channel = イベントチャネルのオブジェクトリファレンスの獲得
    CosNotifyChannelAdmin_EventChannel_set_qos( channel, pQoS, &env );   /* 11 */

        ... 

    /* 動的生成イベントチャネルの生成時 */
    CosNotifyChannelAdmin_EventChannelFactory_create_channel(
                             factory, pQoS, pAdmin, channelID, &env );   /* 12 */
        ... 
    }
  1. Priorityの値を設定します(short型)。
  2. Timeoutの値を設定します(unsigned long long型)。
  3. OrderPolicyの値を設定します(short型)。
  4. DiscardPolicyの値を設定します(short型)。
  5. 上記4項目分のバッファ領域を獲得します。
  6. nameにPriority、valueにany型で1の値を設定します。
  7. nameにTimeout、valueにany型で2の値を設定します。
  8. nameにOrderPolicy、valueにany型で3の値を設定します。
  9. nameにDiscardPolicy、valueにany型で4の値を設定します。
  10. 6〜9までのシーケンス型であるQoSPropertiesを作成します。
  11. イベントチャネルに対してQoSプロパティ項目を設定します。
    動的生成イベントチャネルの場合は、12のイベントチャネルの生成時にも指定できます。
  12. 動的生成イベントチャネルの場合は、イベントチャネルの生成時にQoSプロパティ項目を設定します。

(2)メッセージに対するQoSプロパティ項目の設定方法

 メッセージにQoSプロパティ項目を設定するには、StructuredEvent型データの中のOptionalHeaderFieldsとして設定します。OptionalHeaderFieldsはProperty構造体からなるシーケンス型です。CプログラムでQoSプロパティ項目を設定したStructuredEvent型データの作成例と処理の流れを以下に説明します。

[StructuredEvent型データの作成例(Cの場合)]

    CORBA_short                      *priority;
    CORBA_unsigned_long_long         *timeout;
    CosNotification_Property         *pProperty;
    CosNotification_StructuredEvent  *event;
    CORBA_char                       *domain_name_data;
    CORBA_char                       *type_name_data;
    CORBA_char                       *event_name_data;
    CORBA_string                     *any_string;

    priority  = CORBA_short_alloc();
    *priority = 1;                                                         /* 1 */

    timeout  = CORBA_unsigned_long_long_alloc();
    *timeout = 40;                                                         /* 2 */

    event = CosNotification_StructuredEvent_alloc();                       /* 3 */
    pProperty = CosNotification_PropertySeq_allocbuf( 2 );                 /* 4 */

    pProperty[0].name = CORBA_string_alloc( strlen( CosNotification_Priority ) );
    strcpy( pProperty[0].name, CosNotification_Priority );
    pProperty[0].value._type   = TC_short;
    pProperty[0].value._value  = priority;                                 /* 5 */

    pProperty[1].name = CORBA_string_alloc( strlen( CosNotification_Timeout ) );
    strcpy( pProperty[1].name, CosNotification_Timeout );
    pProperty[1].value._type  = TC_ulonglong;
    pProperty[1].value._value = timeout;                                   /* 6 */

    /* ---- domain_name ---- */
    domain_name_data = CORBA_string_alloc( strlen( "Telecom" ) );
    strcpy( domain_name_data, "Telecom" );
    event->header.fixed_header.event_type.domain_name = domain_name_data;  /* 7 */

    /* ---- type_name ---- */
    type_name_data = CORBA_string_alloc( strlen( "CommunicationsAlarm" ) );
    strcpy( type_name_data, "CommunicationsAlarm" );
    event->header.fixed_header.event_type.type_name   = type_name_data;    /* 8 */

    /* ---- event_name ---- */
    event_name_data = CORBA_string_alloc( strlen( "data" ) );
    strcpy( event_name_data, "data" );
    event->header.fixed_header.event_name = event_name_data;               /* 9 */

    /* ---- remainder_of_data->_value ---- */

    event->filterable_data._maximum = 0;
    event->filterable_data._length  = 0;
    event->filterable_data._buffer  = NULL;

    any_string       = CORBA_string_ptr_alloc();
    *any_string      = CORBA_string_alloc( strlen("StructuredEvent data");

    strcpy( *any_string, "StructuredEvent data" );
    event->remainder_of_body._type  = TC_string;
    event->remainder_of_body._value = any_string;                          /* 10 */
  1. Priorityの値を設定します(short型)。
  2. Timeoutの値を設定します(unsigned long long型)。
  3. StructuredEvent型データを作成します。
  4. 1、2の項目分のバッファ領域を獲得します。
  5. nameにPriority、valueにany型で1の値を設定します。
  6. nameにTimeout、valueにany型で2の値を設定します。
  7. domain_nameを設定します。
  8. type_nameを設定します。
  9. event_nameを設定します。
  10. remainder_of_bodyを作成します。ここで送信したいデータ本体を設定します。
    例では"StructuredEvent data"というstring型のデータを作成しています。

目次 索引 前ページ次ページ

All Rights Reserved, Copyright(C) 富士通株式会社 2007