Example usage for java.util Set wait

List of usage examples for java.util Set wait

Introduction

In this page you can find the example usage for java.util Set wait.

Prototype

public final void wait() throws InterruptedException 

Source Link

Document

Causes the current thread to wait until it is awakened, typically by being notified or interrupted.

Usage

From source file:org.apache.accumulo.server.util.RemoveEntriesForMissingFiles.java

private static int checkTable(ClientContext context, String table, Range range, boolean fix) throws Exception {

    @SuppressWarnings({ "rawtypes" })
    Map cache = new LRUMap(100000);
    Set<Path> processing = new HashSet<Path>();
    ExecutorService threadPool = Executors.newFixedThreadPool(16);

    System.out.printf("Scanning : %s %s\n", table, range);

    VolumeManager fs = VolumeManagerImpl.get();
    Connector connector = context.getConnector();
    Scanner metadata = connector.createScanner(table, Authorizations.EMPTY);
    metadata.setRange(range);/* www .  j a  v  a 2  s .c  om*/
    metadata.fetchColumnFamily(DataFileColumnFamily.NAME);
    int count = 0;
    AtomicInteger missing = new AtomicInteger(0);
    AtomicReference<Exception> exceptionRef = new AtomicReference<Exception>(null);
    BatchWriter writer = null;

    if (fix)
        writer = connector.createBatchWriter(MetadataTable.NAME, new BatchWriterConfig());

    for (Entry<Key, Value> entry : metadata) {
        if (exceptionRef.get() != null)
            break;

        count++;
        Key key = entry.getKey();
        Path map = fs.getFullPath(key);

        synchronized (processing) {
            while (processing.size() >= 64 || processing.contains(map))
                processing.wait();

            if (cache.get(map) != null) {
                continue;
            }

            processing.add(map);
        }

        threadPool.submit(new CheckFileTask(cache, fs, missing, writer, key, map, processing, exceptionRef));
    }

    threadPool.shutdown();

    synchronized (processing) {
        while (processing.size() > 0)
            processing.wait();
    }

    if (exceptionRef.get() != null)
        throw new AccumuloException(exceptionRef.get());

    if (writer != null && missing.get() > 0)
        writer.close();

    System.out.printf("Scan finished, %d files of %d missing\n\n", missing.get(), count);

    return missing.get();
}