use of com.unboundid.ldap.sdk.extensions.CancelExtendedRequest in project ldapsdk by pingidentity.
the class InternalSDKHelper method cancel.
/**
* Sends an LDAP cancel extended request to the server over the provided
* connection without waiting for the response. This is intended for use when
* it is necessary to send a cancel request over a connection operating in
* synchronous mode.
*
* @param connection The connection over which to send the cancel
* request.
* @param targetMessageID The message ID of the request to cancel.
* @param controls The set of controls to include in the request.
*
* @throws LDAPException If a problem occurs while sending the cancel
* request.
*/
@InternalUseOnly()
public static void cancel(@NotNull final LDAPConnection connection, final int targetMessageID, @Nullable final Control... controls) throws LDAPException {
final int messageID = connection.nextMessageID();
final CancelExtendedRequest cancelRequest = new CancelExtendedRequest(targetMessageID);
Debug.debugLDAPRequest(Level.INFO, cancelRequest, messageID, connection);
final LDAPConnectionLogger logger = connection.getConnectionOptions().getConnectionLogger();
if (logger != null) {
logger.logExtendedRequest(connection, messageID, cancelRequest);
}
connection.sendMessage(new LDAPMessage(messageID, new ExtendedRequest(cancelRequest), controls), connection.getConnectionOptions().getExtendedOperationResponseTimeoutMillis(CancelExtendedRequest.CANCEL_REQUEST_OID));
}
use of com.unboundid.ldap.sdk.extensions.CancelExtendedRequest in project ldapsdk by pingidentity.
the class IdentifyUniqueAttributeConflicts method searchEntryReturned.
/**
* Indicates that the provided search result entry has been returned by the
* server and may be processed by this search result listener.
*
* @param searchEntry The search result entry that has been returned by the
* server.
*/
@Override()
public void searchEntryReturned(@NotNull final SearchResultEntry searchEntry) {
// bother processing any more entries.
if (timeLimitExceeded.get()) {
return;
}
if (uniqueInCombination) {
checkForConflictsInCombination(searchEntry);
return;
}
try {
// first.
if (!allowConflictsInSameEntry) {
boolean conflictFound = false;
for (int i = 0; i < attributes.length; i++) {
final List<Attribute> l1 = searchEntry.getAttributesWithOptions(attributes[i], null);
if (l1 != null) {
for (int j = i + 1; j < attributes.length; j++) {
final List<Attribute> l2 = searchEntry.getAttributesWithOptions(attributes[j], null);
if (l2 != null) {
for (final Attribute a1 : l1) {
for (final String value : a1.getValues()) {
for (final Attribute a2 : l2) {
if (a2.hasValue(value)) {
err("Value '", value, "' in attribute ", a1.getName(), " of entry '", searchEntry.getDN(), " is also present in attribute ", a2.getName(), " of the same entry.");
conflictFound = true;
conflictCounts.get(attributes[i]).incrementAndGet();
}
}
}
}
}
}
}
}
if (conflictFound) {
return;
}
}
// efficient in the common case.
for (final String attrName : attributes) {
final List<Attribute> attrList = searchEntry.getAttributesWithOptions(attrName, null);
for (final Attribute a : attrList) {
for (final String value : a.getValues()) {
Filter filter;
if (uniqueAcrossAttributes) {
final Filter[] orComps = new Filter[attributes.length];
for (int i = 0; i < attributes.length; i++) {
orComps[i] = Filter.createEqualityFilter(attributes[i], value);
}
filter = Filter.createORFilter(orComps);
} else {
filter = Filter.createEqualityFilter(attrName, value);
}
if (filterArgument.isPresent()) {
filter = Filter.createANDFilter(filterArgument.getValue(), filter);
}
baseDNLoop: for (final String baseDN : baseDNs) {
SearchResult searchResult;
final SearchRequest searchRequest = new SearchRequest(baseDN, SearchScope.SUB, DereferencePolicy.NEVER, 2, timeLimitArgument.getValue(), false, filter, "1.1");
try {
searchResult = findConflictsPool.search(searchRequest);
} catch (final LDAPSearchException lse) {
Debug.debugException(lse);
if (lse.getResultCode() == ResultCode.TIME_LIMIT_EXCEEDED) {
// The server spent more time than the configured time limit
// to process the search. This almost certainly means that
// the search is unindexed, and we don't want to continue.
// Indicate that the time limit has been exceeded, cancel the
// outer search, and display an error message to the user.
timeLimitExceeded.set(true);
try {
findConflictsPool.processExtendedOperation(new CancelExtendedRequest(searchEntry.getMessageID()));
} catch (final Exception e) {
Debug.debugException(e);
}
err("A server-side time limit was exceeded when searching " + "below base DN '" + baseDN + "' with filter '" + filter + "', which likely means that the search " + "request is not indexed in the server. Check the " + "server configuration to ensure that any appropriate " + "indexes are in place. To indicate that searches " + "should not request any time limit, use the " + timeLimitArgument.getIdentifierString() + " to indicate a time limit of zero seconds.");
return;
} else if (lse.getResultCode().isConnectionUsable()) {
searchResult = lse.getSearchResult();
} else {
try {
searchResult = findConflictsPool.search(searchRequest);
} catch (final LDAPSearchException lse2) {
Debug.debugException(lse2);
searchResult = lse2.getSearchResult();
}
}
}
for (final SearchResultEntry e : searchResult.getSearchEntries()) {
try {
if (DN.equals(searchEntry.getDN(), e.getDN())) {
continue;
}
} catch (final Exception ex) {
Debug.debugException(ex);
}
err("Value '", value, "' in attribute ", a.getName(), " of entry '" + searchEntry.getDN(), "' is also present in entry '", e.getDN(), "'.");
conflictCounts.get(attrName).incrementAndGet();
break baseDNLoop;
}
if (searchResult.getResultCode() != ResultCode.SUCCESS) {
err("An error occurred while attempting to search for " + "conflicts with " + a.getName() + " value '" + value + "' (as found in entry '" + searchEntry.getDN() + "') below '" + baseDN + "': " + searchResult.getDiagnosticMessage());
conflictCounts.get(attrName).incrementAndGet();
break baseDNLoop;
}
}
}
}
}
} finally {
final long count = entriesExamined.incrementAndGet();
if ((count % 1000L) == 0L) {
out(count, " entries examined");
}
}
}
Aggregations