use of com.unboundid.ldif.LDIFDeleteChangeRecord in project ldapsdk by pingidentity.
the class ParallelUpdateOperationQueue method getChangeRecord.
/**
* Retrieves the next LDIF change record to be processed. This method will
* block if the queue is currently empty but the end of the LDIF file has not
* yet been reached, or if all of the operations currently held in the queue
* are dependent upon an operation in progress.
*
* @param completedDNs The DNs of the entries targeted by the last change.
* It should be empty for the first request processed by
* a thread, should have a single element if the last
* change was an add, delete, or modify, and should have
* two elements if the last change was a modify DN.
*
* @return The next LDIF change record to be processed, or {@code null} if
* there are no more change records to process and the end of the
* LDIF file has been reached.
*/
@Nullable()
LDIFChangeRecord getChangeRecord(@NotNull final DN... completedDNs) {
synchronized (queueLock) {
for (final DN dn : completedDNs) {
activeChanges.remove(dn);
}
while (!(endOfLDIF && opQueue.isEmpty())) {
if (opQueue.isEmpty()) {
try {
queueLock.wait(1000L);
} catch (final InterruptedException e) {
Debug.debugException(e);
}
continue;
}
final Iterator<LDIFChangeRecord> iterator = opQueue.iterator();
iteratorLoop: while (iterator.hasNext()) {
final LDIFChangeRecord r = iterator.next();
// Get the parsed target DN for the change record.
final DN targetDN;
try {
targetDN = r.getParsedDN();
} catch (final LDAPException e) {
// This should never happen, but if it does then reject the change.
parallelUpdate.reject(r, e);
iterator.remove();
size--;
continue;
}
// conflict with any active operations.
if (!activeChanges.isEmpty()) {
for (final DN activeDN : activeChanges) {
if (activeDN.isAncestorOf(targetDN, true)) {
continue iteratorLoop;
}
}
if (r instanceof LDIFDeleteChangeRecord) {
for (final DN activeDN : activeChanges) {
if (activeDN.isDescendantOf(targetDN, false)) {
continue iteratorLoop;
}
}
} else if (r instanceof LDIFModifyDNChangeRecord) {
final LDIFModifyDNChangeRecord modDNRecord = (LDIFModifyDNChangeRecord) r;
final DN newDN;
try {
newDN = modDNRecord.getNewDN();
} catch (final LDAPException e) {
// We could not parse the new DN, so reject the change.
parallelUpdate.reject(r, e);
iterator.remove();
size--;
continue iteratorLoop;
}
for (final DN activeDN : activeChanges) {
if (activeDN.isDescendantOf(targetDN, false) || activeDN.isAncestorOf(newDN, true) || activeDN.isDescendantOf(newDN, false)) {
continue iteratorLoop;
}
}
// At this point, we know that the modify DN will be processed so
// reserve the new DN as well. The target DN will be reserved
// below.
activeChanges.add(newDN);
}
}
// At this point, the change will be processed so remove it from the
// queue and add it to the list of active changes. Also, notify any
// threads that might be waiting on the queue lock in case
// addChangeRecord is waiting on available space.
activeChanges.add(targetDN);
iterator.remove();
size--;
queueLock.notifyAll();
return r;
}
// complete before trying again.
try {
queueLock.wait(1000L);
} catch (final InterruptedException e) {
Debug.debugException(e);
}
}
}
// If we've gotten here, then there is no more data to be processed.
return null;
}
use of com.unboundid.ldif.LDIFDeleteChangeRecord in project ldapsdk by pingidentity.
the class ParallelUpdateOperationThread method run.
/**
* Operates in a loop, retrieving changes from the operation queue and
* processing them.
*/
@Override()
public void run() {
LDIFChangeRecord r = opQueue.getChangeRecord();
// Various controls that might be present on the requests.
final Control undeleteRequestControl = new UndeleteRequestControl();
while (r != null) {
if (rateLimiter != null) {
rateLimiter.await();
}
DN parsedDN = null;
DN parsedNewDN = null;
final long startTime = System.currentTimeMillis();
try {
parsedDN = r.getParsedDN();
if (r instanceof LDIFAddChangeRecord) {
final AddRequest addRequest = ((LDIFAddChangeRecord) r).toAddRequest();
addRequest.addControls(addControls);
if (allowUndelete && addRequest.hasAttribute(ATTR_UNDELETE_FROM_DN)) {
addRequest.addControl(undeleteRequestControl);
}
connectionPool.add(addRequest);
parallelUpdate.opCompletedSuccessfully(r, (System.currentTimeMillis() - startTime));
} else if (r instanceof LDIFDeleteChangeRecord) {
final DeleteRequest deleteRequest = ((LDIFDeleteChangeRecord) r).toDeleteRequest();
deleteRequest.addControls(deleteControls);
connectionPool.delete(deleteRequest);
parallelUpdate.opCompletedSuccessfully(r, (System.currentTimeMillis() - startTime));
} else if (r instanceof LDIFModifyChangeRecord) {
final ModifyRequest modifyRequest = ((LDIFModifyChangeRecord) r).toModifyRequest();
modifyRequest.addControls(modifyControls);
connectionPool.modify(modifyRequest);
parallelUpdate.opCompletedSuccessfully(r, (System.currentTimeMillis() - startTime));
} else if (r instanceof LDIFModifyDNChangeRecord) {
final LDIFModifyDNChangeRecord modifyDNChangeRecord = (LDIFModifyDNChangeRecord) r;
parsedNewDN = modifyDNChangeRecord.getNewDN();
final ModifyDNRequest modifyDNRequest = modifyDNChangeRecord.toModifyDNRequest();
modifyDNRequest.addControls(modifyDNControls);
connectionPool.modifyDN(modifyDNRequest);
parallelUpdate.opCompletedSuccessfully(r, (System.currentTimeMillis() - startTime));
} else {
// This should never happen.
r.processChange(connectionPool);
parallelUpdate.opCompletedSuccessfully(r, (System.currentTimeMillis() - startTime));
}
} catch (final LDAPException e) {
Debug.debugException(e);
parallelUpdate.opFailed(r, e, (System.currentTimeMillis() - startTime));
}
if (parsedNewDN == null) {
r = opQueue.getChangeRecord(parsedDN);
} else {
r = opQueue.getChangeRecord(parsedDN, parsedNewDN);
}
}
}
Aggregations