List of usage examples for com.google.common.util.concurrent MoreExecutors sameThreadExecutor
@Deprecated @GwtIncompatible("TODO") public static ListeningExecutorService sameThreadExecutor()
From source file:pl.com.bottega.acceptance.erp.SpringEnabledScenarioRunnerIT.java
public SpringEnabledScenarioRunnerIT() { configuredEmbedder().useExecutorService(MoreExecutors.sameThreadExecutor()); configuredEmbedder().useMetaFilters(Arrays.asList("-skip")); WebDriverProvider driverProvider = new PropertyWebDriverProvider(); SeleniumContext context = new SeleniumContext(); ContextView contextView = new LocalFrameContextView().sized(500, 100); Class<? extends Embeddable> embeddableClass = this.getClass(); configuration = new SeleniumConfiguration().useSeleniumContext(context).useWebDriverProvider(driverProvider) .useStepMonitor(new SeleniumStepMonitor(contextView, context, new SilentStepMonitor())) .useStoryLoader(new LoadFromClasspath(embeddableClass)) .useStoryReporterBuilder(new StoryReporterBuilder() .withCodeLocation(CodeLocations.codeLocationFromClass(embeddableClass)).withDefaultFormats() .withFormats(Format.CONSOLE, Format.TXT, Format.HTML, Format.XML)); }
From source file:co.cask.tephra.DefaultTransactionExecutor.java
public DefaultTransactionExecutor(TransactionSystemClient txClient, Iterable<TransactionAware> txAwares, RetryStrategy retryStrategy) {//from w w w .j ava 2s.c o m super(MoreExecutors.sameThreadExecutor()); this.txAwares = ImmutableList.copyOf(txAwares); this.txClient = txClient; this.retryStrategy = retryStrategy; }
From source file:org.androidtransfuse.transaction.TransactionProcessorPool.java
/** * Executes the submitted work and if all transactions complete, executes the aggregate on the aggregateWorker. *//* w ww. j a v a2 s. c om*/ public void execute() { ExecutorService executorService = MoreExecutors.sameThreadExecutor(); for (Transaction<V, R> transaction : transactions) { if (!transaction.isComplete()) { executorService.execute(transaction); } } try { executorService.shutdown(); executorService.awaitTermination(Long.MAX_VALUE, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { throw new TransfuseTransactionException("Pool executor interrupted", e); } }
From source file:com.android.camera.one.v2.sharedimagereader.ringbuffer.DynamicRingBufferFactory.java
public DynamicRingBufferFactory(Lifetime lifetime, TicketPool rootTicketPool, final Observable<Integer> maxRingBufferSize) { final DynamicRingBuffer ringBuffer = new DynamicRingBuffer(rootTicketPool); lifetime.add(ringBuffer);/*ww w.j a v a2s .co m*/ lifetime.add(maxRingBufferSize.addCallback(new Runnable() { @Override public void run() { ringBuffer.setMaxSize(Math.max(0, maxRingBufferSize.get())); } }, MoreExecutors.sameThreadExecutor())); ringBuffer.setMaxSize(Math.max(0, maxRingBufferSize.get())); mOutputTicketPool = ringBuffer; mRingBufferInput = ringBuffer; mRingBufferOutput = ringBuffer; }
From source file:co.cask.cdap.data2.transaction.DynamicTransactionExecutor.java
public DynamicTransactionExecutor(Supplier<TransactionContext> txContextSupplier, RetryStrategy retryStrategy) { super(MoreExecutors.sameThreadExecutor()); this.txContextSupplier = txContextSupplier; this.retryStrategy = retryStrategy; }
From source file:bjss.jplay.testing.JPlayWebStories.java
public JPlayWebStories() { super();/*from ww w . jav a2s. c om*/ if (lifecycleSteps instanceof PerStoriesWebDriverSteps) { configuredEmbedder().useExecutorService(MoreExecutors.sameThreadExecutor()); configuredEmbedder().useMetaFilters(asList("-skip")); } }
From source file:bjss.jplay.testing.JPlayWebStories_google.java
public JPlayWebStories_google() { super();/*from ww w . ja v a 2 s .c om*/ if (lifecycleSteps instanceof PerStoriesWebDriverSteps) { configuredEmbedder().useExecutorService(MoreExecutors.sameThreadExecutor()); configuredEmbedder().useMetaFilters(asList("-skip")); } }
From source file:org.asoem.greyfish.cli.GreyfishCLIApplication.java
public static void main(final String[] args) { final Optional<String> commitHash = getCommitHash(GreyfishCLIApplication.class); if (commitHash.isPresent()) { logger.debug("Git Commit Hash for current Jar: %s", commitHash.get()); }// w w w.j av a2s.c om Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { try { closer.close(); } catch (IOException e) { logger.warn("Exception while closing resources", e); } } }); try { final OptionSet optionSet = optionParser.parse(args); if (optionSet.has(helpOptionSpec)) { printHelp(); System.exit(0); } final Module commandLineModule = createCommandLineModule(optionSet); final RandomGenerator randomGenerator = RandomGenerators .threadLocalGenerator(new Supplier<RandomGenerator>() { @Override public RandomGenerator get() { return new Well19937c(); } }); final EventBus eventBus = new EventBus(new SubscriberExceptionHandler() { @Override public void handleException(final Throwable exception, final SubscriberExceptionContext context) { context.getEventBus() .post(new AssertionError("The EventBus could not dispatch event: " + context.getSubscriber() + " to " + context.getSubscriberMethod(), exception.getCause())); } }); final Module coreModule = new CoreModule(randomGenerator, eventBus); final Injector injector = Guice.createInjector(coreModule, commandLineModule); final ExperimentExecutionService experimentExecutionService = injector .getInstance(ExperimentExecutionService.class); if (!optionSet.has(quietOptionSpec)) { final ExperimentMonitorService monitorService = new ExperimentMonitorService(System.out, eventBus); monitorService.addListener(new Service.Listener() { @Override public void starting() { } @Override public void running() { } @Override public void stopping(final Service.State from) { } @Override public void terminated(final Service.State from) { } @Override public void failed(final Service.State from, final Throwable failure) { logger.error("Monitor service failed", failure); } }, MoreExecutors.sameThreadExecutor()); experimentExecutionService.addListener(new MonitorServiceController(monitorService), MoreExecutors.sameThreadExecutor()); } // start getSimulation experimentExecutionService.startAsync(); // stop getSimulation on shutdown request (^C) Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { if (experimentExecutionService.isRunning()) { experimentExecutionService.stopAsync().awaitTerminated(); } } }); try { experimentExecutionService.awaitTerminated(); } catch (IllegalStateException e) { exitWithErrorMessage("Simulation execution failed", e); } } catch (OptionException e) { exitWithErrorMessage("Failed parsing options: ", e, true); } catch (Throwable e) { exitWithErrorMessage(String.format( "Exception during simulation execution: %s\n" + "Check log file for a stack trace.", e.getCause() != null ? e.getCause().getMessage() : e.getMessage()), e); } System.exit(0); }
From source file:org.opendaylight.controller.md.sal.dom.store.impl.replica.InMemoryDOMDataStoreFactory.java
/** * Creates an InMemoryDOMDataStore instance. * * @param name the name of the data store * @param schemaService the SchemaService to which to register the data store. * @param debugTransactions enable transaction debugging * @param properties configuration properties for the InMemoryDOMDataStore instance. If null, * default property values are used. * @return an InMemoryDOMDataStore instance *//*from w ww . ja v a2 s .c o m*/ public static InMemoryDOMDataStore create(final String name, @Nullable final SchemaService schemaService, final boolean debugTransactions, @Nullable final InMemoryDOMDataStoreConfigProperties properties) { InMemoryDOMDataStoreConfigProperties actualProperties = properties; if (actualProperties == null) { actualProperties = InMemoryDOMDataStoreConfigProperties.getDefault(); } // For DataChangeListener notifications we use an executor that provides the fastest // task execution time to get higher throughput as DataChangeListeners typically provide // much of the business logic for a data model. If the executor queue size limit is reached, // subsequent submitted notifications will block the calling thread. int dclExecutorMaxQueueSize = actualProperties.getMaxDataChangeExecutorQueueSize(); int dclExecutorMaxPoolSize = actualProperties.getMaxDataChangeExecutorPoolSize(); ExecutorService dataChangeListenerExecutor = SpecialExecutors .newBlockingBoundedFastThreadPool(dclExecutorMaxPoolSize, dclExecutorMaxQueueSize, name + "-DCL"); final ListeningExecutorService commitExecutor = MoreExecutors.sameThreadExecutor(); final InMemoryDOMDataStore dataStore = new InMemoryDOMDataStore(name, commitExecutor, dataChangeListenerExecutor, actualProperties.getMaxDataChangeListenerQueueSize(), debugTransactions); if (schemaService != null) { schemaService.registerSchemaContextListener(dataStore); } return dataStore; }
From source file:com.thjug.bgile.story.SeleniumStory.java
public SeleniumStory() { if (lifecycleSteps instanceof PerStoriesWebDriverSteps) { configuredEmbedder().useExecutorService(MoreExecutors.sameThreadExecutor()); } }