|
17 | 17 |
|
18 | 18 | package com.iplanet.services.ldap.event; |
19 | 19 |
|
20 | | -import static org.forgerock.openam.ldap.LDAPConstants.*; |
21 | | -import static org.forgerock.openam.utils.Time.*; |
| 20 | +import static org.forgerock.openam.ldap.LDAPConstants.AD_IS_DELETED_ATTR; |
| 21 | +import static org.forgerock.openam.ldap.LDAPConstants.AD_NOTIFICATION_OID; |
| 22 | +import static org.forgerock.openam.ldap.LDAPConstants.AD_WHEN_CHANGED_ATTR; |
| 23 | +import static org.forgerock.openam.ldap.LDAPConstants.AD_WHEN_CREATED_ATTR; |
| 24 | +import static org.forgerock.openam.ldap.LDAPConstants.DN_ATTR; |
| 25 | +import static org.forgerock.openam.utils.Time.currentTimeMillis; |
22 | 26 |
|
| 27 | +import com.sun.identity.common.GeneralTaskRunnable; |
| 28 | +import com.sun.identity.common.SystemTimerPool; |
| 29 | +import com.sun.identity.idm.IdRepoListener; |
| 30 | +import com.sun.identity.idm.IdType; |
| 31 | +import com.sun.identity.shared.debug.Debug; |
23 | 32 | import java.util.ArrayList; |
24 | 33 | import java.util.Arrays; |
25 | 34 | import java.util.Collection; |
|
29 | 38 | import java.util.List; |
30 | 39 | import java.util.Map; |
31 | 40 | import java.util.concurrent.ConcurrentHashMap; |
32 | | - |
33 | 41 | import org.forgerock.openam.ldap.LDAPRequests; |
34 | 42 | import org.forgerock.openam.sm.datalayer.api.ConnectionFactory; |
35 | 43 | import org.forgerock.openam.sm.datalayer.api.DataLayerException; |
36 | 44 | import org.forgerock.openam.utils.IOUtils; |
37 | 45 | import org.forgerock.opendj.ldap.Attribute; |
38 | 46 | import org.forgerock.opendj.ldap.Connection; |
39 | | -import org.forgerock.opendj.ldap.ConnectionEventListener; |
40 | 47 | import org.forgerock.opendj.ldap.DN; |
41 | 48 | import org.forgerock.opendj.ldap.DecodeException; |
42 | 49 | import org.forgerock.opendj.ldap.DecodeOptions; |
|
52 | 59 | import org.forgerock.opendj.ldap.controls.PersistentSearchChangeType; |
53 | 60 | import org.forgerock.opendj.ldap.controls.PersistentSearchRequestControl; |
54 | 61 | import org.forgerock.opendj.ldap.requests.SearchRequest; |
55 | | -import org.forgerock.opendj.ldap.responses.ExtendedResult; |
56 | 62 | import org.forgerock.opendj.ldap.responses.Result; |
57 | 63 | import org.forgerock.opendj.ldap.responses.SearchResultEntry; |
58 | 64 | import org.forgerock.opendj.ldap.responses.SearchResultReference; |
59 | 65 | import org.forgerock.util.annotations.VisibleForTesting; |
60 | 66 |
|
61 | | -import com.sun.identity.common.GeneralTaskRunnable; |
62 | | -import com.sun.identity.common.SystemTimerPool; |
63 | | -import com.sun.identity.idm.IdRepoListener; |
64 | | -import com.sun.identity.idm.IdType; |
65 | | -import com.sun.identity.shared.debug.Debug; |
66 | | - |
67 | 67 | /** |
68 | 68 | * An abstract implementation of LDAPv3 persistent searches. |
69 | 69 | * |
@@ -188,7 +188,6 @@ private void logError(Throwable t) { |
188 | 188 | } |
189 | 189 |
|
190 | 190 | private void startSearch(Connection conn) throws LdapException { |
191 | | - conn.addConnectionEventListener(new ConnectionRestartListener()); |
192 | 191 | if (mode == null) { |
193 | 192 | detectPersistentSearchMode(conn); |
194 | 193 | } |
@@ -227,7 +226,13 @@ private void startSearch(Connection conn) throws LdapException { |
227 | 226 | //since psearch wasn't running until now, let's clear the caches to make sure that if something got into the |
228 | 227 | //cache, while PS was stopped, those gets cleared out and we start with a clean cache. |
229 | 228 | clearCaches(); |
230 | | - futureResult = conn.searchAsync(searchRequest, null, new PersistentSearchResultHandler()); |
| 229 | + futureResult = conn.searchAsync(searchRequest, null, new PersistentSearchResultHandler()) |
| 230 | + .thenOnException(e -> { |
| 231 | + if (!shutdown) { |
| 232 | + DEBUG.error("Persistent search against base DN {} has failed: {}", searchBaseDN, e.getMessage()); |
| 233 | + restartSearch(); |
| 234 | + } |
| 235 | + }); |
231 | 236 | } |
232 | 237 |
|
233 | 238 | /** |
@@ -407,23 +412,6 @@ public void run() { |
407 | 412 | } |
408 | 413 | } |
409 | 414 |
|
410 | | - private class ConnectionRestartListener implements ConnectionEventListener { |
411 | | - |
412 | | - @Override |
413 | | - public void handleConnectionClosed() { |
414 | | - } |
415 | | - |
416 | | - @Override |
417 | | - public void handleConnectionError(boolean isDisconnectNotification, LdapException e) { |
418 | | - DEBUG.error("An error occurred while executing persistent search against base DN: {}", searchBaseDN, e); |
419 | | - restartSearch(); |
420 | | - } |
421 | | - |
422 | | - @Override |
423 | | - public void handleUnsolicitedNotification(ExtendedResult notification) { |
424 | | - } |
425 | | - } |
426 | | - |
427 | 415 | @VisibleForTesting |
428 | 416 | protected boolean isShutdown() { |
429 | 417 | return shutdown; |
|
0 commit comments