Example usage for com.google.common.util.concurrent MoreExecutors directExecutor

List of usage examples for com.google.common.util.concurrent MoreExecutors directExecutor

Introduction

In this page you can find the example usage for com.google.common.util.concurrent MoreExecutors directExecutor.

Prototype

public static Executor directExecutor() 

Source Link

Document

Returns an Executor that runs each task in the thread that invokes Executor#execute execute , as in CallerRunsPolicy .

Usage

From source file:com.orangerhymelabs.helenus.cassandra.table.TableService.java

public void read(String database, String table, FutureCallback<Table> callback) {
    Futures.addCallback(read(database, table), callback, MoreExecutors.directExecutor());
}

From source file:io.atomix.core.collection.impl.CachingAsyncDistributedCollection.java

/**
 * Constructor to configure cache size./*from   w  w  w  . j a  v a  2s. c  o m*/
 *
 * @param backingCollection a distributed collection for backing
 * @param cacheConfig       the cache configuration
 */
public CachingAsyncDistributedCollection(AsyncDistributedCollection<E> backingCollection,
        CacheConfig cacheConfig) {
    super(backingCollection);
    cache = CacheBuilder.newBuilder().maximumSize(cacheConfig.getSize())
            .build(CacheLoader.from(CachingAsyncDistributedCollection.super::contains));
    cacheUpdater = event -> {
        cache.invalidate(event.element());
        eventListeners.forEach((listener, executor) -> executor.execute(() -> listener.event(event)));
    };
    statusListener = status -> {
        log.debug("{} status changed to {}", this.name(), status);
        // If the status of the underlying map is SUSPENDED or INACTIVE
        // we can no longer guarantee that the cache will be in sync.
        if (status == PrimitiveState.SUSPENDED || status == PrimitiveState.CLOSED) {
            cache.invalidateAll();
        }
    };
    super.addListener(cacheUpdater, MoreExecutors.directExecutor());
    super.addStateChangeListener(statusListener);
}

From source file:com.facebook.buck.remoteexecution.grpc.GrpcAsyncBlobFetcher.java

private <T> ListenableFuture<T> closeScopeWhenFutureCompletes(Scope scope, ListenableFuture<T> future) {
    future.addListener(() -> scope.close(), MoreExecutors.directExecutor());
    return future;
}

From source file:org.teiid.translator.cassandra.CassandraQueryExecution.java

protected void execute(String cql) {
    LogManager.logDetail(LogConstants.CTX_CONNECTOR, "Source-Query:", cql); //$NON-NLS-1$
    this.executionContext.logCommand(cql);
    resultSetFuture = connection.executeQuery(cql);
    resultSetFuture.addListener(new Runnable() {

        @Override//from   w  ww  .j ava2  s .  co  m
        public void run() {
            executionContext.dataAvailable();
        }
    }, MoreExecutors.directExecutor());
}

From source file:com.orangerhymelabs.helenus.cassandra.database.DatabaseService.java

public void delete(String name, FutureCallback<Boolean> callback) {
    Futures.addCallback(delete(name), callback, MoreExecutors.directExecutor());
}

From source file:io.v.v23.InputChannels.java

/**
 * Returns a new {@link ListenableFuture} whose result is available when the provided
 * {@link InputChannel} has exhausted all of its elements.
 * <p>/* ww w .j a  v  a  2  s.c om*/
 * The returned future will be executed on a
 * {@link MoreExecutors#directExecutor() direct executor}.
 */
@CheckReturnValue
public static <T> ListenableFuture<Void> asDone(final InputChannel<T> channel) {
    return asDone(channel, MoreExecutors.directExecutor());
}

From source file:com.orangerhymelabs.helenus.cassandra.view.ViewService.java

public void readAll(String database, String table, FutureCallback<List<View>> callback) {
    Futures.addCallback(readAll(database, table), callback, MoreExecutors.directExecutor());
}

From source file:com.facebook.buck.distributed.RemoteExecutionStorageService.java

@Override
public ListenableFuture<ByteBuffer> fetch(Digest digest) {
    try {//  w w w  .  j  a  v  a2  s  .c o m
        try (ByteArrayOutputStream outStream = new ByteArrayOutputStream()) {
            return Futures.transform(fetchToStreamInternal(digest, outStream),
                    future -> ByteBuffer.wrap(outStream.toByteArray()), MoreExecutors.directExecutor());
        }
    } catch (IOException e) {
        return Futures.immediateFailedFuture(e);
    }
}

From source file:io.atomix.core.tree.impl.CachingAsyncAtomicDocumentTree.java

/**
 * Constructor to configure cache size./*w  w  w .j a v  a2  s .  c  o  m*/
 *
 * @param backingTree a distributed, strongly consistent map for backing
 * @param cacheConfig the cache configuration
 */
public CachingAsyncAtomicDocumentTree(AsyncAtomicDocumentTree<V> backingTree, CacheConfig cacheConfig) {
    super(backingTree);
    cache = CacheBuilder.newBuilder().maximumSize(cacheConfig.getSize())
            .build(CacheLoader.from(CachingAsyncAtomicDocumentTree.super::get));
    cacheUpdater = event -> {
        if (!event.newValue().isPresent()) {
            cache.invalidate(event.path());
        } else {
            cache.put(event.path(), CompletableFuture.completedFuture(event.newValue().get()));
        }
        eventListeners.values().forEach(listener -> listener.event(event));
    };
    stateListener = status -> {
        log.debug("{} status changed to {}", this.name(), status);
        // If the status of the underlying map is SUSPENDED or INACTIVE
        // we can no longer guarantee that the cache will be in sync.
        if (status == SUSPENDED || status == CLOSED) {
            cache.invalidateAll();
        }
    };
    super.addListener(cacheUpdater, MoreExecutors.directExecutor());
    super.addStateChangeListener(stateListener);
}

From source file:com.navercorp.nbasearc.gcp.Gateway.java

ListenableFuture<?> unuse(Set<VirtualConnection> vcConcurrentSet) {
    state = UNUSED;/*www  .  j  a v  a2  s .c o  m*/

    final SettableFuture<?> sf = SettableFuture.create();
    final AtomicInteger closedConCnt = new AtomicInteger(cons.length);
    for (PhysicalConnection con : cons) {
        con.unuse(vcConcurrentSet).addListener(new Runnable() {
            @Override
            public void run() {
                if (closedConCnt.decrementAndGet() == 0) {
                    sf.set(null);
                }
            }
        }, MoreExecutors.directExecutor());
    }

    return sf;
}