Example usage for com.google.common.collect Queues newConcurrentLinkedQueue

List of usage examples for com.google.common.collect Queues newConcurrentLinkedQueue

Introduction

In this page you can find the example usage for com.google.common.collect Queues newConcurrentLinkedQueue.

Prototype

public static <E> ConcurrentLinkedQueue<E> newConcurrentLinkedQueue() 

Source Link

Document

Creates an empty ConcurrentLinkedQueue .

Usage

From source file:org.apache.bookkeeper.mledger.impl.ManagedLedgerImpl.java

public ManagedLedgerImpl(ManagedLedgerFactoryImpl factory, BookKeeper bookKeeper, MetaStore store,
        ManagedLedgerConfig config, ScheduledExecutorService scheduledExecutor,
        OrderedSafeExecutor orderedExecutor, final String name) {
    this.factory = factory;
    this.bookKeeper = bookKeeper;
    this.config = config;
    this.store = store;
    this.name = name;
    this.scheduledExecutor = scheduledExecutor;
    this.executor = orderedExecutor;
    TOTAL_SIZE_UPDATER.set(this, 0);
    NUMBER_OF_ENTRIES_UPDATER.set(this, 0);
    ENTRIES_ADDED_COUNTER_UPDATER.set(this, 0);
    STATE_UPDATER.set(this, State.None);
    this.ledgersStat = null;
    this.mbean = new ManagedLedgerMBeanImpl(this);
    this.entryCache = factory.getEntryCacheManager().getEntryCache(this);
    this.waitingCursors = Queues.newConcurrentLinkedQueue();
    this.uninitializedCursors = Maps.newHashMap();
    this.updateCursorRateLimit = RateLimiter.create(1);

    // Get the next rollover time. Add a random value upto 5% to avoid rollover multiple ledgers at the same time
    this.maximumRolloverTimeMs = (long) (config.getMaximumRolloverTimeMs()
            * (1 + random.nextDouble() * 5 / 100.0));
}

From source file:dk.ilios.spanner.internal.ExperimentingSpannerRun.java

public static <T> ImmutableList<ListenableFuture<T>> inCompletionOrder(
        Iterable<? extends ListenableFuture<? extends T>> futures) {
    final ConcurrentLinkedQueue<SettableFuture<T>> delegates = Queues.newConcurrentLinkedQueue();
    ImmutableList.Builder<ListenableFuture<T>> listBuilder = ImmutableList.builder();
    Executor executor = MoreExecutors.sameThreadExecutor();
    for (final ListenableFuture<? extends T> future : futures) {
        SettableFuture<T> delegate = SettableFuture.create();
        // Must make sure to add the delegate to the queue first in case the future is already done
        delegates.add(delegate);/*from  www .  j av a2  s.c  o m*/
        future.addListener(new Runnable() {
            @Override
            public void run() {
                SettableFuture<T> delegate = delegates.remove();
                try {
                    delegate.set(Uninterruptibles.getUninterruptibly(future));
                } catch (ExecutionException e) {
                    delegate.setException(e.getCause());
                } catch (CancellationException e) {
                    delegate.cancel(true);
                }
            }
        }, executor);
        listBuilder.add(delegate);
    }
    return listBuilder.build();
}

From source file:com.cinchapi.concourse.importer.cli.ImportCli.java

/**
 * Recursively scan and collect all the files in the directory defined by
 * {@code path}.//  ww  w  .j  av a2s  . c o m
 * 
 * @param path a {@link Path} that is already verified to
 *            {@link java.nio.file.Files#isDirectory(Path, java.nio.file.LinkOption...)
 *            to be a directory}.
 * @return the collection of files in the directory
 */
private static Queue<String> scan(Path path) {
    try (DirectoryStream<Path> stream = java.nio.file.Files.newDirectoryStream(path)) {
        Iterator<Path> it = stream.iterator();
        Queue<String> files = Queues.newConcurrentLinkedQueue();
        while (it.hasNext()) {
            Path thePath = it.next();
            if (java.nio.file.Files.isDirectory(thePath)) {
                files.addAll(scan(thePath));
            } else {
                files.add(thePath.toString());
            }
        }
        return files;
    } catch (IOException e) {
        throw Throwables.propagate(e);
    }
}

From source file:org.apache.drill.exec.expr.fn.registry.FunctionRegistryHolder.java

/**
 * Adds all function names and signatures to passed jar,
 * adds all function names, their signatures and holders to {@link #functions}.
 *
 * @param jar jar where function to be added
 * @param newFunctions collection of function holders, each contains function name, signature and holder.
 *//* w w  w . ja v  a2s .co  m*/
private void addFunctions(Map<String, Queue<String>> jar, List<FunctionHolder> newFunctions) {
    for (FunctionHolder function : newFunctions) {
        final String functionName = function.getName();
        Queue<String> jarFunctions = jar.get(functionName);
        if (jarFunctions == null) {
            jarFunctions = Queues.newConcurrentLinkedQueue();
            ;
            jar.put(functionName, jarFunctions);
        }
        final String functionSignature = function.getSignature();
        jarFunctions.add(functionSignature);

        Map<String, DrillFuncHolder> signatures = functions.get(functionName);
        if (signatures == null) {
            signatures = Maps.newConcurrentMap();
            functions.put(functionName, signatures);
        }
        signatures.put(functionSignature, function.getHolder());
    }
}

From source file:org.apache.gobblin.util.HadoopUtils.java

/**
 * This method is an additive implementation of the {@link FileSystem#rename(Path, Path)} method. It moves all the
 * files/directories under 'from' path to the 'to' path without overwriting existing directories in the 'to' path.
 *
 * <p>/* ww  w. j a va2  s.  co  m*/
 * The rename operation happens at the first non-existent sub-directory. If a directory at destination path already
 * exists, it recursively tries to move sub-directories. If all the sub-directories also exist at the destination,
 * a file level move is done
 * </p>
 *
 * @param fileSystem on which the data needs to be moved
 * @param from path of the data to be moved
 * @param to path of the data to be moved
 */
public static void renameRecursively(FileSystem fileSystem, Path from, Path to) throws IOException {

    log.info(String.format("Recursively renaming %s in %s to %s.", from, fileSystem.getUri(), to));

    FileSystem throttledFS = getOptionallyThrottledFileSystem(fileSystem, 10000);

    ExecutorService executorService = ScalingThreadPoolExecutor.newScalingThreadPool(1, 100, 100,
            ExecutorsUtils.newThreadFactory(Optional.of(log), Optional.of("rename-thread-%d")));
    Queue<Future<?>> futures = Queues.newConcurrentLinkedQueue();

    try {
        if (!fileSystem.exists(from)) {
            throw new IOException("Trying to rename a path that does not exist! " + from);
        }

        futures.add(executorService.submit(new RenameRecursively(throttledFS, fileSystem.getFileStatus(from),
                to, executorService, futures)));
        int futuresUsed = 0;
        while (!futures.isEmpty()) {
            try {
                futures.poll().get();
                futuresUsed++;
            } catch (ExecutionException | InterruptedException ee) {
                throw new IOException(ee.getCause());
            }
        }

        log.info(String.format("Recursive renaming of %s to %s. (details: used %d futures)", from, to,
                futuresUsed));

    } finally {
        ExecutorsUtils.shutdownExecutorService(executorService, Optional.of(log), 1, TimeUnit.SECONDS);
    }
}