LDAPv3PersistentSearch.java revision ccf9d4a5c6453fa9f8b839baeee25147865fbb7d
/*
* The contents of this file are subject to the terms of the Common Development and
* Distribution License (the License). You may not use this file except in compliance with the
* License.
*
* You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
* specific language governing permission and limitations under the License.
*
* When distributing Covered Software, include this CDDL Header Notice in each file and include
* the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
* Header, with the fields enclosed by brackets [] replaced by your own identifying
* information: "Portions copyright [year] [name of copyright owner]".
*
* Copyright 2015-2016 ForgeRock AS.
*/
public abstract class LDAPv3PersistentSearch<T, H> {
private static final boolean CHANGES_ONLY = true;
private static final boolean RETURN_CONTROLS = true;
private static final boolean IS_CRITICAL = true;
private static final List<String> AD_DEFAULT_ATTRIBUTES = Collections.unmodifiableList(Arrays.asList(
private final ConnectionFactory factory;
private final int retryInterval;
private final DN searchBaseDN;
private final Filter searchFilter;
private final SearchScope searchScope;
private volatile boolean shutdown = false;
private volatile Connection conn;
private PersistentSearchMode mode;
private enum PersistentSearchMode {
}
this.retryInterval = retryInterval;
this.searchBaseDN = searchBaseDN;
this.searchFilter = searchFilter;
this.searchScope = searchScope;
}
} else {
}
if (DEBUG.messageEnabled()) {
}
}
/**
* Adds an {@link IdRepoListener} object, which needs to be notified about persistent search results.
* The caller must ensure that calls to addListener/removeListener/hasListeners invocations are synchronized
* correctly.
*
* @param idRepoListener The {@link IdRepoListener} instance that needs to be notified about changes.
* @param supportedTypes The supported {@link IdType}s for which events needs to be generated.
*/
}
/**
* Removes an {@link IdRepoListener} if it was registered to persistent search notifications.
* The caller must ensure that calls to addListener/removeListener/hasListeners invocations are synchronized
* correctly.
*
* @param idRepoListener The {@link IdRepoListener} instance that needs to be notified about changes.
*/
public void removeListener(T idRepoListener) {
}
/**
* Checks if there are any registered listeners for this persistent search connection.
* The caller must ensure that calls to addListener/removeListener/hasListeners invocations are synchronized
* correctly.
*/
public boolean hasListeners() {
}
/**
* Starts the persistent search connection against the directory. The caller must ensure that calls made to
* startPSearch and stopPsearch are properly synchronized.
*/
public void startSearch() {
try {
} catch (LdapException ere) {
}
}
}
//mode shouldn't be null here, if something failed during the detection it should've resulted in an
//exception already.
switch (mode) {
case NONE: {
DEBUG.error("Persistent search is not supported by the directory, persistent search will be disabled");
return;
}
case STANDARD: {
}
break;
case AD: {
}
}
SearchRequest searchRequest = LDAPRequests.newSearchRequest(searchBaseDN, searchScope, searchFilter, attrs);
if (DEBUG.messageEnabled()) {
}
//since psearch wasn't running until now, let's clear the caches to make sure that if something got into the
//cache, while PS was stopped, those gets cleared out and we start with a clean cache.
clearCaches();
}
/**
* Stops the persistent search request, and terminates the LDAP connection. The caller must ensure that calls made
* to startPSearch and stopPsearch are properly synchronized.
*/
public void stopSearch() {
if (DEBUG.messageEnabled()) {
}
if (hasListeners()) {
throw new IllegalStateException("Persistent search has assigned listeners, unable to stop.");
}
shutdown = true;
if (futureResult != null) {
futureResult.cancel(true);
}
}
}
private void restartSearch() {
//just to be really sure
if (!shutdown) {
//we shouldn't try to restart psearch if we are in shutdown mode.
try {
// Schedules the task for the exact second without any non-zero milliseconds
} catch (IllegalMonitorStateException e) {
}
}
}
protected abstract void clearCaches();
protected Map<T, H> getListeners() {
}
protected interface SearchResultEntryHandler {
}
protected abstract SearchResultEntryHandler getSearchResultEntryHandler();
private class PersistentSearchResultHandler implements SearchResultHandler {
if (DEBUG.messageEnabled()) {
}
switch (mode) {
case STANDARD: {
try {
}
type = changeType;
}
} catch (DecodeException de) {
}
}
break;
case AD: {
boolean isDeleted = false;
}
if (isDeleted) {
} else {
if (whenCreated == null) {
if (DEBUG.warningEnabled()) {
}
//advance to the next entry and ignore this one
return true;
}
if (whenChanged == null) {
if (DEBUG.warningEnabled()) {
}
//advance to the next entry and ignore this one
return true;
}
} else {
}
}
}
break;
default:
}
}
//ignoring references
return true;
}
if (!shutdown) {
clearCaches();
} else {
}
}
}
}
private class RetryTask extends GeneralTaskRunnable {
private long runPeriod;
private long lastLogged = 0;
public RetryTask() {
}
return false;
}
return false;
}
public boolean isEmpty() {
return true;
}
public long getRunPeriod() {
return runPeriod;
}
public void run() {
try {
//everything seems to work, let's disable retryTask and reset the debug limit
runPeriod = -1;
lastLogged = 0;
long now = currentTimeMillis();
lastLogged = now;
}
}
}
}
}