Sun ONE Messaging and Collaboration 6.0 Event Notification Service Manual |
Chapter 1
Introduction to Event Notification ServiceThis chapter provides an overview of the Event Notification Service (ENS) components, architecture, and Application Programming Interfaces (APIs).
This chapter contains these sections:
Event Notification Service OverviewThe Event Notification Service (ENS) is the underlying publish-and-subscribe service available in the following Sun Open Net Environment (ONE) communications products:
ENS acts as a dispatcher used by Sun ONE applications as a central point of collection for certain types of events that are of interest to them. Events are changes to the value of one or more properties of a resource. In this structure, a URI (Uniform Resource Identifier) represents an event. Any application that wants to know when these types of events occur registers with ENS, which identifies events in order and matches notifications with subscriptions.
Event examples include:
Specifically, ENS accepts reports of events that can be categorized, and notifies other applications that have registered an interest in certain categories of events.
ENS provides a server and APIs for publishers and subscribers. A publisher makes an event available to the notification service; and a subscriber tells the notification service that it wants to receive notifications of a specific event. See "Event Notification Service API Overview" for more information on the ENS APIs.
ENS in Sun ONE Calendar Server
By default, ENS is enabled in Sun ONE Calendar Server. For Sun ONE Calendar Server you do not need to do anything else to use ENS.
A user who wants to subscribe to notifications other than the alarms generated by Sun ONE Calendar Server needs to write a subscriber.
Sample ENS C publisher and subscriber code is bundled with Sun ONE Calendar Server. (See "ENS Sample Code for Calendar Server".) Once Calendar Server is installed, the code can be found in the following directory:
/opt/SUNWics5/cal/csapi/samples/ens
ENS in Sun ONE Messaging Server
ENS and iBiff (the ENS publisher for Sun ONE Messaging Server, also referred to as the notification plug-in to Sun ONE Messaging Server) are bundled in Sun ONE Messaging Server and ENS is enabled. However, the iBiff plug-in file, libibiff, is not automatically loaded at installation.
To subscribe to notifications, you need to first perform the following two actions on the Sun ONE Messaging Server host:
See Appendix C in the Sun ONE Messaging Server Administrator’s Guide for further instructions.
A user who wants to subscribe to Sun ONE Messaging Server notifications needs to write a subscriber to the ENS API. To do so, the subscriber needs to know what the various Sun ONE Messaging Server notifications are. See Chapter 5, "Sun ONE Messaging Server Specific Information" for that information.
Sun ONE Messaging Server comes bundled with sample ENS C publisher and subscriber code. See "Sample Code" for more information.
Sample Sun ONE Messaging Server code is provided with the product in the following directory:
msg_server_base/examples
Event References
Event references identify an event handled by ENS. Event references use the following URI syntax (as specified by RFC 2396):
scheme://authority resource/[?param1=value1¶m2=value2¶m3=value3]
where:
- authority is the DNS domain or host name that controls access to the resource.
- resource is the path leading to the resource in the context of the authority. It can be composed of several path components separated by a slash (“/”).
- param is the name of a parameter describing the state of a resource.
- value is its value. There can be zero or more parameter/value pairs.
In general, all Sun ONE Calendar Server events start with the following:
enp:///ics
The Sun ONE Messaging Server notification plug-in iBiff uses the following scheme and resource by default:
enp://127.0.0.1/store
Note
Although the event reference has a URI syntax, the scheme, authority, and resource have no special significance. They are merely used as strings with no further interpretation in ENS.
Sun ONE Calendar Server Event Reference Example
The following is an example event reference URI to subscribe to all event alarms with a calendar ID of jac:
enp:///ics/alarm?calid=jac
Sun ONE Messaging Server Event Reference Example
The following is an example event reference that requests a subscription to all NewMsg events for a user whose user ID is blim:
enp://127.0.0.1/store?evtType=NewMsg&mailboxName=blim
When using ENS with Sun ONE Messaging Server, the user ID you specify is case sensitive.
ENS Connection Pooling
The connection pooling feature of ENS enables a pool of subscribers to receive notifications from a single event reference. For every event, ENS chooses one subscriber from the pool to send the notification to. Thus, only one subscriber in the pool receives the notification. The ENS server balances sending of notifications among the subscribers. This enables the client to have a pool of subscribers that work together to receive all notifications from a single event reference.
For example, if notifications are being published to the event reference enp://127.0.0.1/store, a subscriber will normally subscribe to this event reference to receive notifications. To have a pool of subscribers receive all the notifications to this event reference, each subscriber in the pool only needs to subscribe to the event reference enp+pool://127.0.0.1/store instead. The ENS server chooses one subscriber from the pool to send the notification to.
Note
The publisher still sends notifications to the simple event reference, in the example above enp://127.0.0.1/store, that is, the publisher has no knowledge of the subscriber pool.
Multiple Pool Extension
Connection pooling can support multiple pools of subscribers. That is, you can have two pools of subscribers, each pool receiving all the notifications from the event reference. The syntax of the event reference for the subscriber is:
enp+pool[.poolid]://domain/event
where poolid is a string using only base64 alphabet. (See RFC1521, Table 1, for what the base64 alphabet contains.) So, for example, to have two pools of subscribers to the event reference enp://127.0.0.1/store, each pool could subscribe to the following event references:
enp+pool.1://127.0.0.1/store – for first pool of subscribers enp+pool.2://127.0.0.1/store – for second pool of subscribers
Event Notification Service ArchitectureOn the Solaris platform, ENS runs as a daemon, enpd, along with other daemons in various calendar or messaging server configurations, to collect and dispatch events that occur to properties of resources. On Windows platforms, ENS runs as a service, enpd.exe.
For ENS, an event is a change that happens to a resource, while a resource is an entity such as a calendar or inbox. For example, adding an entry to a calendar (the resource) generates an event, which is stored by ENS. This event can then be subscribed to, and a notification would then be sent to the subscriber.
The ENS architecture enables the following three things to occur:
- Notification - This is a message that describes an event occurrence. Sent by the event publisher, it contains a reference to the event, as well as any additional parameter/value pairs added to the URI, and optional data (the payload) used by the event consumers, but opaque to the notification service. Whoever is interested in the event can subscribe to it.
- Subscription - This is a message sent to subscribe to an event. It contains an event reference, a client-side request identifier, and optional parameter/value pairs added to the URI. The subscription applies to upcoming events (that is, a subscriber asks to be notified of upcoming events).
- Unsubscription - This message cancels (unsubscribes) an existing subscription. An event subscriber tells ENS to stop relaying notifications for the specified event.
Notify
ENS notifies its subscribers of an event by sending a notification. Notify is also referred to as “publish.” A notification can contain the following items:
The optional application-specific data is referred to as the “payload.”
There are two kinds of notifications:
- Unreliable notification - Notification sent from an event publisher to a notification server. If the publisher does not know nor care about whether there are any consumers, or whether they get the notification, this request does not absolutely need to be acknowledged. However, a publisher and a subscriber, who are mutually aware of each other, can agree to set up a reliable event notification link (RENL) between themselves. In this case, once the subscriber has processed the publisher’s notification, it sends an acknowledgment notification back to the publisher.
- Reliable notification - Notification sent from a server to a subscriber as a result of a subscription. This type of notification should be acknowledged. A reliable notification contains the same attributes as an unreliable notification.
See "Publisher API" for more information.
Subscribe
ENS receives a request to be notified of events. The request sent by the event subscriber is a subscription. The subscription is valid during the life of the session, or until it is cancelled (unsubscribed).
A subscription can contain the following items:
See "Subscriber API" for more information.
Unsubscribe
ENS receives a request to cancel an existing subscription. See "Subscriber API" for more information.
How Sun ONE Calendar Server Interacts with ENS
Figure 1-1 shows how ENS interacts with Sun ONE Calendar Server through the alarm queue and two daemons, csadmind and csnotifyd.
Figure 1-1 ENS in Sun ONE Calendar Server Overview
Sun ONE Calendar Server Alarm Queue
ENS is an alarm dispatcher. This decouples alarm delivery from alarm generation. It also enables the use of multiple delivery methods, such as email and wireless communication. The csadmind daemon detects events by sensing changes in the state of the alarm queue. The alarm queue’s state changes every time an alarm is placed in the queue. An alarm is queued when a calendar event generates an alarm. The following URIs represent these kind of events:
for events:
enp:///ics/eventalarm?calid=calid&uid=uid&rid=rid&aid=aid
for todos (tasks):
enp:///ics/todoalarm?calid=calid&uid=uid&rid=rid&aid=aid
where:
The publisher csadmind dequeues the alarms and sends notifications to enpd. The enpd daemon then checks to see if anyone is subscribed to this kind of event and sends notifications to the subscriber, csnotifyd, for any subscriptions it finds. Other subscribers to alarm notifications (reminders) can be created and deployed within an Sun ONE Calendar Server installation. These three daemons interacting together implement event notification for Sun ONE Calendar Server.
Sun ONE Calendar Server Daemons
Sun ONE Calendar Server includes two daemons that communicate to the ENS daemon, enpd:
The csadmind daemon contains a publisher that submits notifications to the notification service by sending alarm events to ENS. It manages the Sun ONE Calendar Server alarm queue. It implements a scheduler, which lets it know when an alarm has to be generated. At such a point, csadmind publishes an event. ENS receives and dispatches the event notification.
To ensure alarm transfer reliability, csadmind requires acknowledgment for certain events or event types. (See "Alarm Transfer Reliability".) The csadmind daemon uses Reliable Event Notification Links (RENLs) to accomplish acknowledgment.
The csnotifyd daemon is the subscriber that expresses interest in particular events (subscribes), and receives notifications about these subscribed-to events from ENS, and sends notice of these events and todos (tasks) to its clients by email.
Though the ability to unsubscribe is part of the ENS architecture, csnotifyd does not bother to unsubscribe to events for the following two reasons: there is no need to unsubscribe or resubscribe during normal runtime; and due to the temporary nature of the subscriptions store (it is held in memory), all subscriptions are implicitly unsubscribed when the connection to ENS is shutdown.
The csnotifyd daemon subscribes to enp:///ics/alarm/. The todo (task) or event is specified in a parameter.
Alarm Transfer Reliability
To ensure that no alarm ever gets lost, csadmind and csnotifyd use the RENL feature of ENS for certain types of alarms. For these alarms, csadmind requests an end-to-end acknowledgment for each notification it sends, while csnotifyd, after successfully processing it, generates a notification acknowledgment for each RENL alarm notifications it receives.
For these RENL alarms, should the network, the ENS daemon, or csnotifyd fail to handle a notification, csadmind will not receive any acknowledgment, and will not remove the alarm from the alarm queue. The alarm will, therefore, be published again after a timeout.
Sun ONE Calendar Server Example
A typical ENS publish and subscribe cycle for Sun ONE Calendar Server resembles the following:
- The event subscriber, csnotifyd, expresses interest in an event (subscribes).
- The event publisher, csadmind, detects events and sends notification (publishes).
- ENS publishes the event to the subscriber.
- The event subscriber cancels interest in the event (unsubscribes). This step happens implicitly when the connection to ENS is shutdown.
Figure 1-2 illustrates this cycle and Table 1-1 provides the narrative for the figure.
Figure 1-2 Example Event Notification Service Publish and Subscribe Cycle for Sun ONE Calendar Server
How Sun ONE Messaging Server Interacts with ENS
Figure 1-3 shows how ENS interacts with Sun ONE Messaging Server. In this figure, each oval represents a process, and each rectangle represents a host computer running the enclosed processes.
The ENS server delivers notifications from the Sun ONE Messaging Server notification plug-in to ENS clients (that is, iBiff subscribers). There is no guarantee of the order of notification prior to the ENS server because the events are coming from different processes (MTA, stored, and imapd).
Notifications flow from the iBiff plug-in in the MTA, stored, and imap processes to ENS enpd. The ENS client subscribes to the ENS, and receives notifications. When iBiff is enabled, Sun ONE Messaging Server publishes the notifications with the iBiff plug-in, but no Sun ONE Messaging Server services subscribe to these notifications. A customer-provided ENS subscriber or client should be written to consume the notifications and do whatever is necessary. That is, Sun ONE Messaging Server itself does not depend on or use the notifications for its functions, and this is why ENS and iBiff are not enabled by default when you install Sun ONE Messaging Server.
The Sun ONE Messaging Server architecture enforces that a given set of mailboxes is served by a given host computer. A given mailbox is not served by multiple host computers. There are several processes manipulating a given mailbox but only one computer host serving a given mailbox. Thus, to receive notifications, end-users only need to subscribe to the ENS daemon that serves the mailbox they are interested in.
Sun ONE Messaging Server enables you to have either one ENS server for all mailboxes—that is, one ENS server for all the computer hosts servicing the message store—or multiple ENS servers, perhaps one ENS server per computer host. The second scenario is more scalable. Also, in this scenario, end users must subscribe to multiple ENS servers to get the events for mailboxes they are interested in.
Thus, the architecture requires an ENS server per computer host. The ENS servers and the client processes do not have to be co-located with each other or with messaging servers.
Figure 1-3 ENS in Sun ONE Messaging Server Overview
Event Notification Service API OverviewThis section provides an overview of the two APIs for ENS, a C API and a Java API, which is a subset of the Java Messaging Service (JMS) API. Two sample Java subscribers are provided using the JMS API.
For detailed information on the Java (JMS) API, see Chapter 3, "Event Notification Service Java (JMS) API Reference." For JMS documentation, use the following URL:
http://java.sun.com/products/jms/docs.html
For detailed information on the ENS C API, see Chapter 2, "Event Notification Service C API Reference."
ENS C API Overview
ENS implements the following three APIs:
A publisher sends notification of a subscribed-to event to ENS, which then distributes it to the subscribers. Optionally, in Sun ONE Calendar Server, the application can request acknowledgment of receipt of the notification. To do this, a Reliable Event Notification Link (RENL) is necessary. An RENL has a publisher, a subscriber, and a unique ID, which identify notifications that are subject to acknowledgment. The publisher informs the application of the receipt of an acknowledgment by invoking the end2end_ack callback passed to publish_a. Currently, only Sun ONE Calendar Server supports RENL.
A subscriber is a client to the notification service which expresses interest in particular events. When the notification service receives a notification about one of these events from a publisher, it relays the notification to the subscriber.
A subscriber may also unsubscribe, which cancels an active subscription.
In Sun ONE Calendar Server, to enable an RENL, the subscriber declares its existence to ENS, which then transparently generates notification acknowledgment on behalf of the subscriber application. The subscriber can revoke the RENL at any time.
When an asynchronous publisher is used, ENS needs to borrow threads from a thread pool in order to invoke callbacks. The application can either choose to create its own thread pool and pass it to ENS, or it can let ENS create and manage its own thread pool. In either case, ENS creates and uses a dispatcher object to instantiate the dispatcher used (pas_dispatcher_t).
GDisp (libasync) is the dispatcher supported.
ENS Java API Overview
The Java API for ENS uses a subset of the standard JMS API, with the addition of two new proprietary methods:
The following list of JMS object classes is used in the Java API for ENS:
Building and Running Custom Applications
To assist you in building your own custom publisher and subscriber applications, Sun ONE Messaging Server and Sun ONE Calendar Server include sample code. This section tells you where to find the sample code, where the APIs’ include (header) files are located, and where the libraries are that you need to build and run your custom programs.
Location of Sample Code
Sun ONE Calendar Server
Sun ONE Calendar Server includes four simple sample programs to help you get started. The code for these samples resides in the following directory:
cal_server_base/cal/csapi/samples/ens
Sun ONE Messaging Server
Sun ONE Messaging Server 5.1 and higher contains sample programs to help you learn how to receive notifications. These sample programs are located in the following directory:
msg_server_base/examples
Location of Include Files
Sun ONE Calendar Server
The include (header) files for the publisher and subscriber APIs are: publisher.h, suscriber.h, and pasdisp.h (publish and subscribe dispatcher). They are located in the CSAPI include directory. The default include path is:
cal_server_base/cal/csapi/include
Sun ONE Messaging Server
The default include path for Sun ONE Messaging Server is:
msg_server_base/bin/msg/enssdk/include
Dynamically Linked/Shared Libraries
Sun ONE Calendar Server
Your custom code must be linked with the dynamically linked library libens, which implements the publisher and subscriber APIs. On some platforms all the dependencies of libens must be provided as part of the link directive. These dependencies, in order, are:
Sun ONE Calendar Server uses these libraries; therefore, they are located in the server’s bin directory. The default libens path is:
/opt/cal_server_base/cal/bin
Sun ONE Messaging Server
The libraries for Sun ONE Messaging Server are located in the following directory:
msg_server_base/bin/msg/lib
Refer to msg_server_base/bin/msg/enssdk/examples/Makefile.sample to help determine what libraries are needed.This makefile contains instructions on how to compile and run the apub and asub programs. This file also describes what libraries are needed, and what the LD_LIBRARY_PATH should be. Figure 1-4 shows a sample makefile.sample file.
Figure 1-4 Makefile.sample File
Note
The Windows distribution includes the following additional files:
msg_server_base\bin\msg\enssdk\examples
bin\msg\enssdk\examples\libens.lib
bin\msg\enssdk\examples\libgap.lib
bin\msg\enssdk\examples\libxenp.lib
bin\msg\enssdk\examples\libcyrus.lib
bin\msg\enssdk\examples\libchartable.lib
bin\msg\enssdk\examples\libyasr.lib
bin\msg\enssdk\examples\libasync.lib
bin\msg\enssdk\examples\asub.dsw
bin\msg\enssdk\examples\apub.dsp
bin\msg\enssdk\examples\asub.dsp
To build on Windows platforms:
- A sample VC++ workspace is provided in asub.dsw. It has two projects in it: asub.dsp and apub.dsp.
The required .lib files to link is in the same directory as asub.c and apub.c.
- To run, it requires that the following DLLs are in your path.
libens.dll
libgap.dll
libxenp.dll
libcyrus.dll
libchartable.dll
libyasr.dll
libasync.dllThe simplest way to accomplish this is to include msg_server_base in\msg\lib in your PATH.
Runtime Library Path Variable
Sun ONE Calendar Server
In order for your custom programs to find the necessary runtime libraries, which are located in the /opt/SUNWics5/cal/bin directory, make sure your environment’s runtime library path variable includes this directory. The name of the variable is platform dependent:
Sun ONE Messaging Server
For Sun ONE Messaging Server, you need to set your LD_LIBRARY_PATH to msg_server_base/bin/msg/lib.