This chapter provides an overview of the Event Notification Service (ENS) components, architecture, and Application Programming Interfaces (APIs).
This chapter contains these sections:
The Event Notification Service (ENS) is the underlying publish-and-subscribe service available in the following Sun JavaTM System communications products:
See Appendix B, Administering Event Notification Service in Messaging Server, in Sun Java System Messaging Server 6.3 Administration Guide for instructions on enabling and administering ENS in Messaging Server.
ENS acts as a dispatcher used by Sun Java System 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:
Arrival of new mail to a user’s inbox
User’s mailbox has exceeded its quota
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.
By default, ENS is enabled in Calendar Server. For 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 Calendar Server needs to write a subscriber.
Sample ENS C publisher and subscriber code is bundled with Calendar Server. (See ENS Sample Code for Calendar Server.) Once Calendar Server is installed, the code can be found in the following directory:
ENS and iBiff (the ENS publisher for Messaging Server, also referred to as the notification plug-in to Messaging Server) are bundled in 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 Messaging Server host:
Load the iBiff notification plug-in
Stop and restart the messaging server
A user who wants to subscribe to Messaging Server notifications needs to write a subscriber to the ENS API. To do so, the subscriber needs to know what the various Messaging Server notifications are. See Chapter 4, Messaging Server Specific Information for that information.
Messaging Server comes bundled with sample ENS C publisher and subscriber code. See Sample Code for more information.
Sample Messaging Server code is provided with the product in the following directory:
Event references identify an event handled by ENS. Event references use the following URI syntax (as specified by RFC 2396):
scheme is the access method, such as http, imap, ftp, or wcap.
For Calendar Server and Messaging Server, the ENS scheme is enp.
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 Calendar Server events start with the following:
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.
The following is an example event reference URI to subscribe to all event alarms with a calendar ID of jac:
This URI is not meant to be used by end users.
The following is an example event reference that requests a subscription to all NewMsg events for a user whose user ID is blim:
When using ENS with Messaging Server, the user ID you specify is case sensitive.
This URI is not meant to be used by end users.
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.
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.
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:
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
On 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).
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:
An event reference (which, optionally, can contain parameter/value pairs)
Optional application-specific data (“opaque” for ENS, but the publisher and subscriber agree apriori to the format of the data)
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.
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:
An event reference (which, optionally, can contain parameter/value pairs)
A request identifier
See Subscriber API for more information.
ENS receives a request to cancel an existing subscription. See Subscriber API for more information.
Figure 1–1 shows how ENS interacts with Calendar Server through the alarm queue and two daemons, csadmind and csnotifyd.
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 todos (tasks):
calid is the calendar ID.
uid is the event/todo (task) ID within the calendar.
rid is the recurrence id for a recurring event/todo (task).
aid is the alarm ID within the event/todo (task). In case there are multiple alarms, the aid identifies the correct alarm.
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 Calendar Server installation. These three daemons interacting together implement event notification for Calendar Server.
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 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.
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.
A typical ENS publish and subscribe cycle for 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 shut down.
1. The csnotifyd daemon sends a subscription request to ENS.
ENS stores the subscription in the subscriptions database.
2. The csadmind daemon sends a notification request to ENS.
ENS queries the subscriptions database for subscriptions matching the notification.
3. The csnotifyd daemon receives a notification from ENS.
When ENS receives a notification from a publisher, it looks up its internal subscription table to find subscriptions matching the event reference of the notification. Then for each subscription, it relays a copy of the notification to the subscriber who owns this subscription.
4. Currently, csnotifyd does not bother sending cancellation requests to ENS.
Because the subscriptions store is in memory only (not in a database), all subscriptions are implicitly unsubscribed when the connection to ENS is shutdown.
Figure 1–3 shows how ENS interacts with 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 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, Messaging Server publishes the notifications with the iBiff plug-in, but no 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, 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 Messaging Server.
The 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.
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.
This 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:
For detailed information on the ENS C API, see Chapter 2, Event Notification Service C API Reference.
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 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 Calendar Server supports RENL.
Unreliable Publisher API
A publisher sends notification of an event to ENS, which distributes it to the subscribers. The term “unreliable” means that the API does not indicate whether a published event was successfully sent or received by a subscriber.
This communication model is suitable for some applications, but not for others. If you are concerned about transfer reliability, use the full-blown publisher API (publisher.h) instead. However, the Unreliable Publisher API has the merit of being easier to use if transfer reliability is not a concern.
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 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.
Publish and Subscribe Dispatcher API
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.
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:
The Java API for ENS does not implement all the JMS object classes. When customizing, use only the object classes found on this list.
To assist you in building your own custom publisher and subscriber applications, Messaging Server and 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.
This section applies to the C API only.
Calendar Server includes four simple sample programs to help you get started. The code for these samples resides in the following directory:
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:
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:
The default include path for Messaging Server is:
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:
Calendar Server uses these libraries; therefore, they are located in the server’s bin directory. The default libens path is:
For Windows, in order to build publisher and subscriber applications, you also need the archive files (.lib files) corresponding to all the earlier mentioned libraries. These are located in the CSAPI library directory, lib. The default lib path is:
The libraries for Messaging Server are located in the following directory:
Refer to msg-server-base/examples/enssdk/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. The following listing shows a sample makefile.sample file.
# # Sample makefile # # your C compiler CC = gcc # LIBS # Your library path should include <msg-server-base>/lib LIBS = -lens -lgap -lxenp -lcyrus -lchartable -lyasr -lasync all: apub asub apub: apub.c $(CC) -o apub -I ../include apub.c $(LIBS) asub: asub.c $(CC) -o asub -I ../include asub.c $(LIBS) run: @echo ’run <msg-server-base>/start-ens’ @echo run asub localhost 7997 @echo run apub localhost 7997
The Windows distribution includes the following additional files:
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.dll
The simplest way to accomplish this is to include msg-server-base in\msg\lib in your PATH.
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:
SunOS and Linux: LD_LIBRARY_PATH
For Messaging Server, you need to set your LD_LIBRARY_PATH to msg-server-base/lib.