Search in sources :

Example 1 with ReaperQuery

use of org.forgerock.openam.cts.impl.query.reaper.ReaperQuery in project OpenAM by OpenRock.

the class CTSReaper method run.

/**
     * Performs the query against the directory by selecting the Token IDs for all Tokens
     * that have expired. These Token IDs are then scheduled for deletion. The task will
     * not complete until all of the delete operations have returned.
     */
public void run() {
    debug("Reaper starting");
    // Timers for debugging
    StopWatch query = new StopWatch();
    StopWatch waiting = new StopWatch();
    // Latches will track deletion of each page of results
    List<CountDownLatch> latches = new ArrayList<CountDownLatch>();
    ReaperQuery reaperQuery = queryFactory.getQuery();
    try {
        long total = 0;
        query.start();
        for (Collection<String> ids = reaperQuery.nextPage(); ids != null; ids = reaperQuery.nextPage()) {
            // If the thread has been interrupted, exit all processing.
            if (Thread.interrupted()) {
                Thread.currentThread().interrupt();
                debug("Interrupted, returning");
                return;
            }
            total += ids.size();
            debug("Queried {0} tokens", Long.toString(total));
            // Latch will track the deletions of the page
            latches.add(tokenDeletion.deleteBatch(ids));
        }
        query.stop();
        waiting.start();
        debug("Expired Token Query Time: {0}ms", Long.toString(query.getTime()));
        // Wait stage
        for (CountDownLatch latch : latches) {
            try {
                latch.await();
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
        }
        waiting.stop();
        monitoringStore.addReaperRun(query.getStartTime(), query.getTime() + waiting.getTime(), total);
        debug("Worker threads Time: {0}ms", Long.toString(waiting.getTime()));
    } catch (CoreTokenException e) {
        debug.error("CTS Reaper failed", e);
    }
    debug("Reaper complete");
}
Also used : ArrayList(java.util.ArrayList) CoreTokenException(org.forgerock.openam.cts.exceptions.CoreTokenException) CountDownLatch(java.util.concurrent.CountDownLatch) StopWatch(org.apache.commons.lang.time.StopWatch) ReaperQuery(org.forgerock.openam.cts.impl.query.reaper.ReaperQuery)

Aggregations

ArrayList (java.util.ArrayList)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 StopWatch (org.apache.commons.lang.time.StopWatch)1 CoreTokenException (org.forgerock.openam.cts.exceptions.CoreTokenException)1 ReaperQuery (org.forgerock.openam.cts.impl.query.reaper.ReaperQuery)1