The Java Tutorials have been written for JDK 8.Java教程是为JDK 8编写的。Examples and practices described in this page don't take advantage of improvements introduced in later releases and might use technology no longer available.本页中描述的示例和实践没有利用后续版本中引入的改进,并且可能使用不再可用的技术。See Java Language Changes for a summary of updated language features in Java SE 9 and subsequent releases.有关Java SE 9及其后续版本中更新的语言特性的摘要,请参阅Java语言更改。
See JDK Release Notes for information about new features, enhancements, and removed or deprecated options for all JDK releases.有关所有JDK版本的新功能、增强功能以及已删除或不推荐的选项的信息,请参阅JDK发行说明。
The LDAP v3 ( RFC 2251) defines an unsolicited notification, 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 UnsolicitedNotification interface.
Because unsolicited notifications are sent asynchronously by the server, you can use the same event model used for receiving notifications about namespace changes and object content changes. You register interest in receiving unsolicited notifications by registering an 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(); } }
Following 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.
// Get the event context for registering the listener EventContext ctx = (EventContext) (new InitialContext(env).lookup("ou=People")); // Create the listener NamingListener listener = new UnsolListener(); // Register the listener with the context (all targets equivalent) ctx.addNamingListener("", EventContext.ONELEVEL_SCOPE, listener);
When running 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, after one minute the program will exit silently.
A listener that implements UnsolicitedNotificationListener can also implement other NamingListener interfaces, such as NamespaceChangeListener and ObjectChangeListener.