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

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

Introduction

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

Prototype

@Deprecated
@GwtIncompatible("TODO")
public static ListeningExecutorService sameThreadExecutor() 

Source Link

Document

Creates an executor service that runs each task in the thread that invokes execute/submit , as in CallerRunsPolicy .

Usage

From source file:io.druid.server.coordination.broker.DruidBroker.java

@Inject
public DruidBroker(final ServerInventoryView serverInventoryView, final @Self DruidNode self,
        final ServiceAnnouncer serviceAnnouncer) {
    this.self = self;
    this.serviceAnnouncer = serviceAnnouncer;

    serverInventoryView.registerSegmentCallback(MoreExecutors.sameThreadExecutor(),
            new ServerView.BaseSegmentCallback() {
                @Override//  ww  w.  j  a va  2s  .c o  m
                public ServerView.CallbackAction segmentViewInitialized() {
                    serviceAnnouncer.announce(self);
                    return ServerView.CallbackAction.UNREGISTER;
                }
            });
}

From source file:org.netxilia.api.impl.model.WorkbookEventSupport.java

public WorkbookEventSupport() {
    // TODO is multithreading ok here !?
    super(MoreExecutors.sameThreadExecutor());
    // super(Executors.newSingleThreadExecutor());
}

From source file:dropship.agent.statsd.Snitch.java

@Inject
Snitch(List<SnitchService> snitches) {
    this.snitches = new ServiceManager(snitches);

    this.snitches.addListener(new ServiceManager.Listener() {
        @Override//from   w  w  w  . j a  v  a2  s  .com
        public void healthy() {
        }

        @Override
        public void stopped() {
        }

        @Override
        public void failure(Service service) {
            System.err.format("StatsdAgent service failed: %s, cause: %s", service,
                    Throwables.getStackTraceAsString(service.failureCause()));
        }
    }, MoreExecutors.sameThreadExecutor());
}

From source file:io.druid.server.QueryManager.java

public void registerQuery(Query query, final ListenableFuture future) {
    final String id = query.getId();
    queries.put(id, future);//from  w ww.ja  va2s  .  c  o m
    future.addListener(new Runnable() {
        @Override
        public void run() {
            queries.remove(id, future);
        }
    }, MoreExecutors.sameThreadExecutor());
}

From source file:org.jalphanode.notification.AbstractListener.java

/**
 * Initializes internal fields.//w  w w. j  a  v a2s .  c  om
 *
 * @param  asyncExecutor  asynchronous executor
 */
public AbstractListener(final Executor asyncExecutor) {
    this.asyncExecutor = Preconditions.checkNotNull(asyncExecutor, "asyncExecutor");
    this.syncExecutor = MoreExecutors.sameThreadExecutor();
}

From source file:org.apache.druid.server.coordination.broker.DruidBroker.java

@Inject
public DruidBroker(final FilteredServerInventoryView serverInventoryView, final @Self DruidNode self,
        final ServiceAnnouncer serviceAnnouncer) {
    this.self = self;
    this.serviceAnnouncer = serviceAnnouncer;

    serverInventoryView.registerSegmentCallback(MoreExecutors.sameThreadExecutor(),
            new ServerView.BaseSegmentCallback() {
                @Override/* ww  w . j av  a  2  s  .  c  o m*/
                public ServerView.CallbackAction segmentViewInitialized() {
                    serviceAnnouncer.announce(self);
                    return ServerView.CallbackAction.UNREGISTER;
                }
            },
            // We are not interested in any segment callbacks except view initialization
            Predicates.alwaysFalse());
}

From source file:com.android.builder.internal.packaging.zip.ZFileOptions.java

/**
 * Creates a new options object. All options are set to their defaults.
 *///from   w ww. ja  v  a 2s  . c  om
public ZFileOptions() {
    mTracker = new ByteTracker();
    mCompressor = new DeflateExecutionCompressor(MoreExecutors.sameThreadExecutor(), mTracker,
            Deflater.DEFAULT_COMPRESSION);
    mAlignmentRule = AlignmentRules.compose();
}

From source file:com.google.gerrit.server.git.ReceiveCommitsExecutorModule.java

@Provides
@Singleton//  www. j  ava2s .c o m
@ChangeUpdateExecutor
public ListeningExecutorService createChangeUpdateExecutor(@GerritServerConfig Config config) {
    int poolSize = config.getInt("receive", null, "changeUpdateThreads", 1);
    if (poolSize <= 1) {
        return MoreExecutors.sameThreadExecutor();
    }
    return MoreExecutors.listeningDecorator(MoreExecutors.getExitingExecutorService(new ThreadPoolExecutor(1,
            poolSize, 10, TimeUnit.MINUTES, new ArrayBlockingQueue<Runnable>(poolSize),
            new ThreadFactoryBuilder().setNameFormat("ChangeUpdate-%d").setDaemon(true).build(),
            new ThreadPoolExecutor.CallerRunsPolicy())));
}

From source file:org.trinity.foundation.api.shared.AsyncListenableEventBus.java

/**
 * {@inheritDoc}/*  w ww.  j  a  v a2 s  .co  m*/
 * <p>
 *
 * @see EventBus#register(Object)
 */
@Override
public void register(@Nonnull final Object object) {
    register(object, MoreExecutors.sameThreadExecutor());
}

From source file:com.googlecode.blaisemath.graph.layout.IterativeGraphLayoutService.java

IterativeGraphLayoutService(IterativeGraphLayoutManager mgr, int loopDelay) {
    this.manager = mgr;
    this.loopDelay = loopDelay;
    addListener(new Listener() {
        @Override/*  ww  w  .  j a  va2  s  . c o  m*/
        public void failed(Service.State from, Throwable failure) {
            LOG.log(Level.SEVERE, "Layout service failed", failure);
        }
    }, MoreExecutors.sameThreadExecutor());
}