Sun logo      Previous      Contents      Index      Next     

Sun Java System Communications Services 6 2004Q2 Event Notification Service Guide

Chapter 1
Introduction to Event Notification Service

This 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 Overview

The Event Notification Service (ENS) is the underlying publish-and-subscribe service available in the following Sun Java™ System communications products:

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:

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 Calendar Server

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 in Messaging Server

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:

See Appendix C in the Messaging Server Administration Guide for further instructions.

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

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&param2=value2&param3=value3]


In general, all Calendar Server events start with the following:


The Messaging Server notification plug-in iBiff uses the following scheme and resource by default:



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.

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:



This URI is not meant to be used by end users.

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:


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.

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://, 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:// 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://, 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:


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://, each pool could subscribe to the following event references:

enp+pool.1:// – for first pool of subscribers enp+pool.2:// – for second pool of subscribers

Event Notification Service Architecture

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:


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:

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:

See Subscriber API for more information.


ENS receives a request to cancel an existing subscription. See Subscriber API for more information.

How Calendar Server Interacts with ENS

Figure 1-1 shows how ENS interacts with Calendar Server through the alarm queue and two daemons, csadmind and csnotifyd.

Figure 1-1  ENS in Calendar Server Overview

csnotifyd subscribes to alarms. enpd stores the subscriptions in memory. csadmind sends notifications of alarms to enpd. If enpd has subscriptions to any of these alarms, it sends notifications about them to csnotifyd.

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:


for todos (tasks):



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 Daemons

Calendar Server includes two daemons that communicate to the ENS daemon, enpd:

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.

Calendar Server Example

A typical ENS publish and subscribe cycle for Calendar Server resembles the following:

  1. The event subscriber, csnotifyd, expresses interest in an event (subscribes).
  2. The event publisher, csadmind, detects events and sends notification (publishes).
  3. ENS publishes the event to the subscriber.
  4. 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 Calendar Server

csnotifyd is the event subscriber. csadmind is the event publisher. enpd holds subscriptions and relays notifications.

Table 1-1  Sample ENS Publish and Subscribe Cycle


ENS Response

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.

How Messaging Server Interacts with ENS

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.

Figure 1-3  ENS in Messaging Server Overview

ENS clients subscribe to notifications and receives (consumes) them. Notifications flow from the iBiff plug-in in the MTA, stored, and imap processes.

Event Notification Service API Overview

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 C API Overview

ENS implements the following three APIs:

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, 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.

Location of Sample Code

Calendar Server

Calendar Server includes four simple sample programs to help you get started. The code for these samples resides in the following directory:


Messaging Server

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:


Location of Include Files

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:


Messaging Server

The default include path for Messaging Server is:


Dynamically Linked/Shared Libraries

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:

  1. libgap
  2. libcyrus
  3. libyasr
  4. libasync
  5. libnspr3
  6. libplsd4
  7. libplc3

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:


Messaging Server

The libraries for Messaging Server are located in the following directory:


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


# Sample makefile


# your C compiler

CC = gcc


# Your library path should include <msg_server_base>/bin/msg/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)


@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:

  1. A sample VC++ workspace is provided in asub.dsw. It has two projects in it: asub.dsp and apub.dsp.
  2. The required .lib files to link is in the same directory as asub.c and apub.c.

  3. To run, it requires that the following DLLs are in your path.
  4. libens.dll

    The simplest way to accomplish this is to include msg_server_base in\msg\lib in your PATH.

Runtime Library Path Variable

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:

Messaging Server

For Messaging Server, you need to set your LD_LIBRARY_PATH to msg_server_base/bin/msg/lib.

Previous      Contents      Index      Next     

Copyright 2004 Sun Microsystems, Inc. All rights reserved.