Example usage for com.google.common.util.concurrent ListenableFutureTask create

List of usage examples for com.google.common.util.concurrent ListenableFutureTask create

Introduction

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

Prototype

public static <V> ListenableFutureTask<V> create(Callable<V> callable) 

Source Link

Document

Creates a ListenableFutureTask that will upon running, execute the given Callable .

Usage

From source file:org.opendaylight.vtn.manager.it.ofmock.impl.Barrier.java

/**
 * Create a new future task associated with the send-barrier RPC task.
 *
 * @return  The future task associated with the send-barrier RPC task.
 *///ww w  . ja  v  a  2s .  c om
public static ListenableFutureTask<RpcResult<Void>> create() {
    return ListenableFutureTask.create(new Barrier());
}

From source file:androidx.room.guava.GuavaRoom.java

/**
 * Returns a {@link ListenableFuture<T>} created by submitting the input {@code callable} to
 * {@link ArchTaskExecutor}'s background-threaded Executor.
 *///  ww w.  j  a va  2 s  . c om
public static <T> ListenableFuture<T> createListenableFuture(final Callable<T> callable,
        final RoomSQLiteQuery query, final boolean releaseQuery) {
    ListenableFutureTask<T> listenableFutureTask = ListenableFutureTask.create(callable);
    ArchTaskExecutor.getInstance().executeOnDiskIO(listenableFutureTask);

    if (releaseQuery) {
        Futures.addCallback(listenableFutureTask, new FutureCallback<T>() {
            @Override
            public void onSuccess(T t) {
                query.release();
            }

            @Override
            public void onFailure(Throwable throwable) {
                query.release();
            }
        }, directExecutor());
    }

    return listenableFutureTask;
}

From source file:org.opendaylight.vtn.manager.it.ofmock.impl.GetFlowStatsTask.java

/**
 * Create a new future task associated with the get-flow-statistics
 * RPC task./*from   w w w  . ja  v a2s . c o  m*/
 *
 * @param node   The target switch.
 * @param match  The flow matcher to select flow entries.
 * @return  The future task associated with the get-flow-statistics RPC
 *          task.
 */
public static ListenableFutureTask<RpcResult<GetFlowStatisticsOutput>> create(OfNode node, FlowMatcher match) {
    return ListenableFutureTask.create(new GetFlowStatsTask(node, match));
}

From source file:org.waveprotocol.box.server.waveserver.WaveMap.java

/**
 * Returns a future whose result is the ids of stored wavelets in the given wave.
 * Any failure is reported as a {@link PersistenceException}.
 *///from w w w  .j  a va2 s. co  m
private static ListenableFuture<ImmutableSet<WaveletId>> lookupWavelets(final WaveId waveId,
        final WaveletStore<?> waveletStore, Executor lookupExecutor) {
    ListenableFutureTask<ImmutableSet<WaveletId>> task = ListenableFutureTask
            .create(new Callable<ImmutableSet<WaveletId>>() {
                @Override
                public ImmutableSet<WaveletId> call() throws PersistenceException {
                    return waveletStore.lookup(waveId);
                }
            });
    lookupExecutor.execute(task);
    return task;
}

From source file:org.pentaho.di.trans.dataservice.optimization.StepOptimization.java

public ListenableFuture<Boolean> activate(final DataServiceExecutor executor,
        final PushDownOptimizationMeta meta) {
    ListenableFutureTask<Boolean> future = ListenableFutureTask.create(new Callable<Boolean>() {
        @Override/*from   w  ww .j a va2s  . c om*/
        public Boolean call() throws Exception {
            StepInterface stepInterface = executor.getServiceTrans().findRunThread(meta.getStepName());
            return activate(executor, stepInterface);
        }
    });
    executor.getListenerMap().put(DataServiceExecutor.ExecutionPoint.OPTIMIZE, future);
    return future;
}

From source file:org.trinity.shellplugin.widget.impl.view.qt.AbstractQWidgetViewProvider.java

@Override
public T get() {//from w w  w  . j av a 2s  . co m
    final ListenableFutureTask<T> futureTask = ListenableFutureTask.create(new Callable<T>() {
        @Override
        public T call() {
            final T view = createView();
            view.setWindowFlags(WindowType.X11BypassWindowManagerHint);
            view.setAttribute(WidgetAttribute.WA_DeleteOnClose, true);
            view.setAttribute(WidgetAttribute.WA_DontCreateNativeAncestors, true);
            return view;
        }
    });
    QApplication.invokeLater(futureTask);
    try {
        return futureTask.get();
    } catch (final InterruptedException e) {
        throw new Error(e);
    } catch (final ExecutionException e) {
        throw new Error(e);
    }
}

From source file:org.trinity.foundation.render.qt.impl.binding.view.delegate.PropertySlotInvocatorDelegateImpl.java

@Override
public ListenableFuture<Void> invoke(final Object view, final Method viewMethod, final Object argument) {
    final ListenableFutureTask<Void> invokeTask = ListenableFutureTask.create(new Callable<Void>() {
        @Override/*from ww  w  . ja  v a 2 s.c  om*/
        public Void call() throws Exception {
            viewMethod.invoke(view, argument);
            return null;
        }
    });

    QApplication.invokeLater(invokeTask);
    return invokeTask;
}

From source file:org.fcrepo.indexer.AsynchIndexer.java

@Override
public ListenableFuture<Result> update(final URI identifier, final Content content) throws IOException {
    LOGGER.debug("Received update for identifier: {}", identifier);

    final ListenableFutureTask<Result> task = ListenableFutureTask.create(updateSynch(identifier, content));
    task.addListener(new Runnable() {
        @Override//from   w  w w.j a va2s.c  om
        public void run() {
            synchronized (this) {
                notifyAll();
            }
        }
    }, executorService());
    executorService().submit(task);
    LOGGER.debug("Issued task to execution pool for identifier: {}", identifier);
    return task;
}

From source file:com.sk89q.guavabackport.cache.CacheLoader.java

@Beta
@GwtIncompatible("Executor + Futures")
public static <K, V> CacheLoader<K, V> asyncReloading(final CacheLoader<K, V> loader, final Executor executor) {
    Preconditions.checkNotNull((Object) loader);
    Preconditions.checkNotNull((Object) executor);
    return new CacheLoader<K, V>() {
        @Override/*from w  ww .j ava2s . co m*/
        public V load(final K key) throws Exception {
            return loader.load(key);
        }

        @Override
        public ListenableFuture<V> reload(final K key, final V oldValue) throws Exception {
            final ListenableFutureTask<V> task = (ListenableFutureTask<V>) ListenableFutureTask
                    .create((Callable) new Callable<V>() {
                        @Override
                        public V call() throws Exception {
                            return (V) loader.reload(key, oldValue).get();
                        }
                    });
            executor.execute((Runnable) task);
            return (ListenableFuture<V>) task;
        }

        @Override
        public Map<K, V> loadAll(final Iterable<? extends K> keys) throws Exception {
            return loader.loadAll(keys);
        }
    };
}

From source file:com.addthis.hydra.query.FileRefCacheLoader.java

@Override
public ListenableFuture<SetMultimap<Integer, FileReference>> reload(String key,
        SetMultimap<Integer, FileReference> oldValue) {
    ListenableFutureTask<SetMultimap<Integer, FileReference>> task = ListenableFutureTask
            .create(() -> loadFileReferencesForJob(key));
    fileReferenceCacheReloader.submit(task);
    return task;/*from   w ww . j  av a2s . co  m*/
}