|
|
| Sun ONE Messaging and Collaboration イベント通知サービスマニュアル |
第 4 章 Sun ONE Calendar Server 固有の情報
この章では、ENS API を使用するために必要となる Sun ONE Calendar Server に固有の項目について説明します。
Sun ONE Calendar Server 通知
Sun ONE Calendar Server コーディング例
Sun ONE Calendar Server 通知
Sun ONE Calendar Server 通知の形式は、次の 2 つの部分に分かれています。
カレンダー通知には、リマインダを中継するアラーム通知、およびカレンダーデータベースに変更を配信するカレンダー更新通知の 2 種類があります。
アラーム通知
アラーム通知は、リマインダを中継します。csadmind デーモンがリマインダを送信しようとするたびに公開されます。Sun ONE では、これらのアラームのデフォルトのサブスクライバは、csnotifyd デーモンです。csnotifyd がコンシュームする通知は、バイナリペイロードを持ち、肯定応答を受けます (高信頼)。
また、追加の通知を各リマインダに 1 つ生成するようにサーバを構成して、サードパーティの通知インフラストラクチャがコンシュームできるようにすることも可能です。
表 4-1 に、2 種類のアラーム通知を使用可能にする方法、そのベースイベント URL、および各アラームのイベントペイロード形式を示します (「カレンダー通知の形式」 を参照)。
カレンダー更新通知
カレンダー更新通知 は、カレンダーデータベースに変更を配信します。データベースに変更が加えられるたびに、cshttpd デーモンまたは csdwpd デーモンによって公開されます (このタイプの変更に対する通知が使用可能になっている場合)。
表 4-2 に、各タイプのカレンダー更新通知と、それぞれのics.conf 設定、ベースイベント URL を示します。
種類
使用可能にする ics.conf のパラメータ
(特に記載のないかぎり、パラメータの
デフォルトはすべて「yes」)
ベースイベント URL および値
またはイベントペイロード
イベント URL パラメータに含まれる項目は次のとおりです。
カレンダー通知の形式
通知は、次の 2 つの部分に分かれています。
拡張機能トピック
通常、出席者の応答および開催者の再表示のための ENS 通知は、他の修正と共に caldb.berkeleydb.ensmsg.modifyevent トピックに公開されます。 ics.conf の変数 caldb.berkeleydb.ensmsg.advancedtopics を「yes」(デフォルトは「no」) に設定すると、ENS 通知を公開してトピックの修正、応答および再表示を分けることができます。 これにより通知のコンシューマは、どの種類のトランザクションが通知をトリガーしたかをより正確に把握することができます。
表 4-3 は、ENS が ics.conf の変数 caldb.berkeleydb.ensmsg.advancedtopics の設定に応じて通知を公開するトピックを示します。
ics.conf 変数 caldb.berkeleydb.ensmsg.advancedtopics の値
ENS が出席者通知を公開するトピック
caldb.berkeleydb.ensmsg.modifyevent
caldb.berkeleydb.ensmsg.refreshevent
caldb.berkeleydb.ensmsg.replyevent
WCAP appid パラメータおよび X-Token
ENS が既存のイベントに行った修正の通知を送信する場合、通知と共に X-NSCP-COMPONENT-SOURCE および X-NSCP-TRIGGERED-BY の 2 つの X-Token を戻します。
X-NSCP-COMPONENT-SOURCE X-Token の内容は、イベントの送信者やそのイベントを要求したオリジナルの WCAP コマンドに appid パラメータが存在しているかどうかによって変わります。
appid パラメータがオリジナルの WCAP コマンドに存在する場合、ENS は X-NSCP-COMPONENT-SOURCE X-Token にその値を返します (特定のコマンドだけが appid パラメータを取得します。appid パラメータの詳細は、『Sun ONE Calendar Server プログラマーズマニュアル』を参照してください)。 このメカニズムを使用して、アプリケーションは、送信した通知を検出するために ENS 通知に「タグ」を付けることができます。 appid コマンドの値は、アプリケーション選択の文字列です。 appid パラメータが存在しない場合は、標準値は送信元に応じて X-Token に割り当てられます 。これらの標準値については、表 4-4 を参照してください 。
X-Token (X-NSCP-TRIGGERED-BY) は、appid パラメータの有無に関係なく、通知をトリガーした開催者または出席者の名前 (uid) を保持します。
表 4-4 に、WCAP コマンドにappid パラメータが存在するかどうかによって、 X-Token X-NSCP-COMPONENT-SOURCE の値がどのように異なるかを示します。
表 4-4    appid の存在および X-Token X-NSCP-COMPONENT-SOURCE の値
appid の存在
要求元による X-Token X-NSCP-COMPONENT-SOURCE の値
Sun ONE Calendar Server コーディング例
Sun ONE Calendar Server は、完全な ENS 実装を伴って出荷されています。ENS API を使用して Calendar Server をカスタマイズすることができます。次の 4 つのコーディング例 (簡単なパブリッシャとサブスクライバ、および信頼性の高いパブリッシャとサブスクライバ) で、ENS API の使い方を示します。コーディング例は、製品の次のディレクトリにあります。
/opt/SUNWics5/cal/csapi/samples/ens
パブリッシャおよびサブスクライバのコーディング例
次の 2 つのコーディング例では、簡単な対話形式の非同期パブリッシャとサブスクライバを確立します。
パブリッシャのコーディング例
/*
* Copyright 2000 by Sun Microsystems, Inc.
* All rights reserved
*
* apub : simple interactive asynchronous publisher using
*
* Syntax:
* apub host port
*/
#include <stdlib.h>
#include <stdio.h>
#include "pasdisp.h"
#include "publisher.h"
static pas_dispatcher_t *disp = NULL;
static publisher_t *_publisher = NULL;
static int _shutdown = 0;
static void _exit_usage()
{
printf("\nUsage:\n apub host port\n");
exit(5);
}
static void _exit_error(const char *msg)
{
printf("%s\n", msg);
exit(1);
}
static void _call_shutdown()
{
_shutdown = 1;
pas_shutdown(disp);
}
static void _open_ack(void *arg, int rc, void *enc)
{
_publisher = (publisher_t *)enc;
(void *)arg;
if (!_publisher)
{
printf("Failed to create publisher with status %d\n", rc);
_call_shutdown();
return;
}
static void _publish_ack(void *arg, int rc, void *ignored)
{
(void *)ignored;
printf("Publish failed with status %d\n", rc);
if ( !fgets(input, sizeof(input), stdin) )
{
continue;
} else {
char *message;
unsigned int message_len;
input[strlen(input) - 1] = 0; /* Strip off the \n */
if (*input == '.' && input[1] == 0)
{
publisher_delete(_publisher);
_call_shutdown();
break;
}
message = strdup(input);
message_len = strlen(message);
publish(_publisher, "enp://yoyo.com/xyz",message,
message_len,
_publish_ack, NULL, (void *)message, 0);
return;
}
}
return;
}
main(int argc, char **argv)
{
unsigned short port = 7997;
char host[256];
if (*(argv[1]) == '0')
{
strcpy(host, "127.0.0.1");
} else {
strcpy(host, argv[1]);
}
if (argc > 2)
{
port = (unsigned short)atoi(argv[2]);
}
disp = pas_dispatcher_new(NULL);
if (disp == NULL) _exit_error("Can't create publisher");
publisher_new_a(disp, NULL, host, port, _open_ack, disp);
サブスクライバのコーディング例
/*
* Copyright 1997 by Sun Microsystems, Inc.
* All rights reserved
*
* asub : example asynchronous subscriber
*
* Syntax:
* asub host port
*/
#include <stdlib.h>
#include <stdio.h>
#include "pasdisp.h"
#include "subscriber.h"
static pas_dispatcher_t *disp = NULL;
static subscriber_t *_subscriber = NULL;
static subscription_t *_subscription = NULL;
static renl_t *_renl = NULL;
static void _exit_usage()
{
printf("\nUsage:\n asub host port\n");
exit(5);
}
static void _exit_error(const char *msg)
{
printf("%s\n", msg);
exit(1);
}
static void _subscribe_ack(void *arg, int rc, void *subscription)
{
(void)arg;
if (!rc)
{
_subscription = subscription;
printf("Subscription successful\n");
} else {
printf("Subscription failed - status %d\n", rc);
pas_shutdown(disp);
}
}
static void _unsubscribe_ack(void *arg, int rc, void *ignored)
{
(void *)ignored;
(void *)arg;
if (rc != 0)
{
printf("Unsubscribe failed - status %d\n", rc);
}
subscriber_delete(_subscriber);
pas_shutdown(disp);
}
static int _handle_notify(void *arg, char *url, char *str, int len)
{
(void *)arg;
printf("[%s] %.*s\n", url, len, (str) ? str : "(null)");
return 0;
}
static void _open_ack(void *arg, int rc, void *enc)
{
_subscriber = (subscriber_t *)enc;
(void *)arg;
if (rc)
{
printf("Failed to create subscriber with status %d\n", rc);
pas_shutdown(disp);
return;
}
subscribe(_subscriber, "enp://yoyo.com/xyz",
_handle_notify, NULL,
_subscribe_ack, NULL);
static void _unsubscribe(int sig)
{
(int)sig;
unsubscribe(_subscriber, _subscription, _unsubscribe_ack, NULL);
}
main(int argc, char **argv)
{
unsigned short port = 7997;
char host[256];
if (argc < 2) _exit_usage();
if (*(argv[1]) == '0')
{
strcpy(host, "127.0.0.1");
} else {
strcpy(host, argv[1]);
}
if (argc > 2)
{
port = (unsigned short)atoi(argv[2]);
}
disp = pas_dispatcher_new(NULL);
if (disp == NULL) _exit_error("Can't create publisher");
subscriber_new_a(disp, NULL, host, port, _open_ack, NULL);
信頼性の高いパブリッシャとサブスクライバ
次の 2 つのコーディング例では、信頼性の高い非同期パブリッシャとサブスクライバを確立します。
信頼性の高いパブリッシャのコーディング例
/*
* Copyright 2000 by Sun Microsystems, Inc.
* All rights reserved
*
* rpub : simple *reliable* interactive asynchronous publisher.
* It is designed to be used in combination with rsub,
* the reliable subscriber.
*
* Syntax:
* rpub host port
*/
#include <stdlib.h>
#include <stdio.h>
#include "pasdisp.h"
#include "publisher.h"
static pas_dispatcher_t *disp = NULL;
static publisher_t *_publisher = NULL;
static int _shutdown = 0;
static renl_t *_renl;
printf("\nUsage:\n rpub host port\n");
static void _exit_error(const char *msg)
{
printf("%s\n", msg);
exit(1);
}
static void _call_shutdown()
{
_shutdown = 1;
pas_shutdown(disp);
}
static void _renl_create_cb(void *arg, int rc, void *ignored)
{
(void *)arg;
(void *)ignored;
if (!_publisher)
{
printf("Failed to create RENL - status %d\n", rc);
_call_shutdown();
return;
}
static void _publisher_new_cb(void *arg, int rc, void *enc)
{
_publisher = (publisher_t *)enc;
if (!_publisher)
{
printf("Failed to create publisher - status %d\n", rc);
_call_shutdown();
return;
}
renl_create_publisher(_publisher, "renl_id", NULL,
_renl_create_cb,NULL);
static void _recv_ack(void *arg, int rc, void *ignored)
{
(void *)ignored;
if (rc < 0)
{
printf("Acknowledgment Timeout\n");
} else if ( rc == 0) {
printf("Acknowledgment Received\n");
}
fflush (stdout);
static void _read_stdin()
{
static char input[1024];
printf("rpub> ");
fflush(stdout);
while (!_shutdown)
{
if ( !fgets(input, sizeof(input), stdin) )
{
continue;
} else {
char *message;
unsigned int message_len;
input[strlen(input) - 1] = 0; /* Strip off the \n */
if (*input == '.' && input[1] == 0)
{
publisher_delete(_publisher);
_call_shutdown();
break;
}
message = strdup(input);
message_len = strlen(message);
/* five seconds timeout */
publish(_publisher, "enp://yoyo.com/xyz",
message, message_len,
NULL, _recv_ack, message, 5000);
main(int argc, char **argv)
{
unsigned short port = 7997;
char host[256];
if (argc < 2) _exit_usage();
if (*(argv[1]) == '0')
{
strcpy(host, "127.0.0.1");
} else {
strcpy(host, argv[1]);
}
if (argc > 2)
{
port = (unsigned short)atoi(argv[2]);
}
disp = pas_dispatcher_new(NULL);
if (disp == NULL) _exit_error("Can't create publisher");
publisher_new_a(disp, NULL, host, port, _publisher_new_cb,
NULL);
信頼性の高いサブスクライバのコーディング例
/*
* Copyright 1997 by Sun Microsystems, Inc.
* All rights reserved
*
* asub : example asynchronous subscriber
*
* Syntax:
* asub host port
*/
#include <stdlib.h>
#include <stdio.h>
#include "pasdisp.h"
#include "subscriber.h"
static pas_dispatcher_t *disp = NULL;
static subscriber_t *_subscriber = NULL;
static subscription_t *_subscription = NULL;
static renl_t *_renl = NULL;
static void _exit_usage()
{
printf("\nUsage:\n asub host port\n");
exit(5);
}
static void _exit_error(const char *msg)
{
printf("%s\n", msg);
exit(1);
}
static void _subscribe_ack(void *arg, int rc, void *subscription)
{
(void)arg;
if (!rc)
{
_subscription = subscription;
printf("Subscription successful\n");
_renl = renl_create_subscriber(_subscription, "renl_id", NULL);
} else {
printf("Subscription failed - status %d\n", rc)
pas_shutdown(disp);
}
}
static void _unsubscribe_ack(void *arg, int rc, void *ignored)
{
(void *)ignored;
(void *)arg;
if (rc != 0)
{
printf("Unsubscribe failed - status %d\n", rc);
}
subscriber_delete(_subscriber);
pas_shutdown(disp);
}
static int _handle_notify(void *arg, char *url, char *str, int len)
{
(void *)arg;
printf("[%s] %.*s\n", url, len, (str) ? str : "(null)");
return 0;
}
static void _open_ack(void *arg, int rc, void *enc)
{
_subscriber = (subscriber_t *)enc;
(void *)arg;
if (rc)
{
printf("Failed to create subscriber with status %d\n", rc);
pas_shutdown(disp);
return;
}
subscribe(_subscriber, "enp://yoyo.com/xyz",_handle_notify,
NULL,_subscribe_ack, NULL);
static void _unsubscribe(int sig)
{
(int)sig;
unsubscribe(_subscriber, _subscription, _unsubscribe_ack, NULL);
}
main(int argc, char **argv)
{
unsigned short port = 7997;
char host[256];
if (argc < 2) _exit_usage();
if (*(argv[1]) == '0')
{
strcpy(host, "127.0.0.1");
} else {
strcpy(host, argv[1]);
}
if (argc > 2)
{
port = (unsigned short)atoi(argv[2]);
disp = pas_dispatcher_new(NULL);
if (disp == NULL) _exit_error("Can't create publisher");
subscriber_new_a(disp, NULL, host, port, _open_ack, NULL);
前へ 目次 索引 次へ
Copyright 2002 Sun Microsystems, Inc. All rights reserved.
最終更新日 2002 年 8 月 30 日