The following example explains the use of PsearchEventSource
source = new PsearchEventSource();
//Create a instance
listener = new SearchEventListener();
//Some implementation of PSearchListener
//register for search with no attributes returned
source.registerforEvent(
connection, //Connection to connect to server.
searchBase,// container to search
LDAPConnection.SCOPE_SUB,// search container's subtree
"(objectClass=*)",
// search filter, all objects
LDAPConnection.NO_ATTRS, // don't return attributes
true,// return attrs and values, ignored
null, // use default search queue
EventConstant.LDAP_PSEARCH_ANY, // use default search constraints
true, //return change only
listener); //PsearchListener for receiving events.
// process the events in the listener.
//In the end, remove the listener
source.removeListener(listener);