![]() ![]() ![]() ![]() |
Event Notification |
The LDAP version 3 (LDAP v3, RFC 2251) defines an unsolicited notification, which is a message that is sent by an LDAP server to the client without any provocation from the client. An unsolicited notification is represented in the JNDI by the UnsolicitedNotificationinterface.
Because unsolicited notifications are sent asynchronous by the server, we can use the same event model that we used for receiving notifications about namespace changes and object content changes. You register interest in receiving unsolicited notifications by registering a UnsolicitedNotificationListener
with an EventContext
or EventDirContext
.
Here is an example of an UnsolicitedNotificationListener:
public class UnsolListener implements UnsolicitedNotificationListener { public void notificationReceived(UnsolicitedNotificationEvent evt) { System.out.println("received: " + evt); } public void namingExceptionThrown(NamingExceptionEvent evt) { System.out.println(">>> UnsolListener got an exception"); evt.getException().printStackTrace(); } }Here is an example that registers an implementation of UnsolicitedNotificationListener with an event source. Note that only the listener argument to EventContext.addNamingListener()
is relevant. The name and scope parameters are not relevant to unsolicited notifications.
When you run this program, you need to point it at an LDAP server that can generate unsolicited notifications and prod the server to emit the notification. Otherwise, the program will exit silently after one minute.// Get event context for registering listener EventContext ctx = (EventContext) (new InitialContext(env).lookup("ou=People")); // Create listener NamingListener listener = new UnsolListener(); // Register listener with context (all targets equivalent) ctx.addNamingListener("", EventContext.ONELEVEL_SCOPE, listener);A listener that implements UnsolicitedNotificationListener can also implement other NamingListener
interfaces, such as NamespaceChangeListener
, or ObjectChangeListener
.
Event Notification: End of Lesson
![]()
![]()
What's next? Now you can:
- Continue on in this trail to learn about URLs.
- Go to the Federation
lesson to learn about federation.
- Go to the Miscellaneous
lesson to read up on miscellaneous topics such as class loading and link references.
![]() ![]() ![]() ![]() |
Event Notification |