List of usage examples for java.util.concurrent Executors newSingleThreadExecutor
public static ExecutorService newSingleThreadExecutor()
From source file:com.cognifide.actions.msg.push.active.PushClient.java
private void startLoops() { for (AgentConfig config : agentConfigManager.getConfigurations().values()) { if (config.isEnabled() && config.usedForReverseReplication()) { try { final PushClientRunnable loop = createLoop(config); Executors.newSingleThreadExecutor().execute(loop); loops.add(loop);// w ww . java 2 s . com } catch (URISyntaxException e) { LOG.error("Can't parse agent url: " + config.getTransportURI(), e); } } } }
From source file:com.streamsets.pipeline.stage.origin.s3.TestAmazonS3SourceDataFormats.java
@BeforeClass public static void setUpClass() throws IOException, InterruptedException { File dir = new File(new File("target", UUID.randomUUID().toString()), "fakes3_root").getAbsoluteFile(); Assert.assertTrue(dir.mkdirs());/*from w w w .j a v a 2s . com*/ fakeS3Root = dir.getAbsolutePath(); port = TestUtil.getFreePort(); fakeS3 = new FakeS3(fakeS3Root, port); Assume.assumeTrue("Please install fakes3 in your system", fakeS3.fakes3Installed()); //Start the fakes3 server executorService = Executors.newSingleThreadExecutor(); executorService.submit(fakeS3); populateFakes3(); }
From source file:de.dfki.iui.mmds.scxml.engine.SCXMLEngineActivator.java
public static void postScxmlOnExitEvent(final String id, final TransitionTarget state) { if (getEventAdmin() == null) return;/* w ww . j ava 2 s. c o m*/ Executors.newSingleThreadExecutor().execute(new Runnable() { @Override public void run() { getEventAdmin().postEvent(new SCXMLOnExitEvent(id, state)); } }); }
From source file:com.opengamma.web.server.AggregatedViewDefinitionManager.java
public AggregatedViewDefinitionManager(PositionSource positionSource, SecuritySource securitySource, ConfigSource combinedConfigSource, ConfigMaster userConfigMaster, PortfolioMaster userPortfolioMaster, PositionMaster userPositionMaster, Map<String, AggregationFunction<?>> portfolioAggregators) { _positionSource = positionSource;//w w w.j av a 2s .c o m _securitySource = securitySource; _combinedConfigSource = combinedConfigSource; _userConfigMaster = userConfigMaster; _userPortfolioMaster = userPortfolioMaster; _portfolioAggregators = portfolioAggregators; _portfolioSaver = new SavePortfolio(Executors.newSingleThreadExecutor(), userPortfolioMaster, userPositionMaster); }
From source file:com.spotify.reaper.unit.service.SegmentRunnerTest.java
@Test public void timeoutTest() throws InterruptedException, ReaperException, ExecutionException { final AppContext context = new AppContext(); context.storage = new MemoryStorage(); RepairUnit cf = context.storage//from ww w . j a va 2 s .c om .addRepairUnit(new RepairUnit.Builder("reaper", "reaper", Sets.newHashSet("reaper"))); RepairRun run = context.storage.addRepairRun( new RepairRun.Builder("reaper", cf.getId(), DateTime.now(), 0.5, 1, RepairParallelism.PARALLEL)); context.storage.addRepairSegments(Collections.singleton( new RepairSegment.Builder(run.getId(), new RingRange(BigInteger.ONE, BigInteger.ZERO), cf.getId())), run.getId()); final long segmentId = context.storage.getNextFreeSegment(run.getId()).get().getId(); final ExecutorService executor = Executors.newSingleThreadExecutor(); final MutableObject<Future<?>> future = new MutableObject<>(); context.jmxConnectionFactory = new JmxConnectionFactory() { @Override public JmxProxy connect(final Optional<RepairStatusHandler> handler, String host) { JmxProxy jmx = mock(JmxProxy.class); when(jmx.getClusterName()).thenReturn("reaper"); when(jmx.isConnectionAlive()).thenReturn(true); when(jmx.tokenRangeToEndpoint(anyString(), any(RingRange.class))) .thenReturn(Lists.newArrayList("")); when(jmx.triggerRepair(any(BigInteger.class), any(BigInteger.class), anyString(), Matchers.<RepairParallelism>any(), Sets.newHashSet(anyString()))) .then(new Answer<Integer>() { @Override public Integer answer(InvocationOnMock invocation) { assertEquals(RepairSegment.State.NOT_STARTED, context.storage.getRepairSegment(segmentId).get().getState()); future.setValue(executor.submit(new Thread() { @Override public void run() { handler.get().handle(1, ActiveRepairService.Status.STARTED, "Repair command 1 has started"); assertEquals(RepairSegment.State.RUNNING, context.storage .getRepairSegment(segmentId).get().getState()); } })); return 1; } }); return jmx; } }; RepairRunner rr = mock(RepairRunner.class); RepairUnit ru = mock(RepairUnit.class); SegmentRunner sr = new SegmentRunner(context, segmentId, Collections.singleton(""), 100, 0.5, RepairParallelism.PARALLEL, "reaper", ru, rr); sr.run(); future.getValue().get(); executor.shutdown(); assertEquals(RepairSegment.State.NOT_STARTED, context.storage.getRepairSegment(segmentId).get().getState()); assertEquals(1, context.storage.getRepairSegment(segmentId).get().getFailCount()); }
From source file:com.xeiam.xchange.examples.mtgox.v2.service.trade.streaming.MtGoxWebSocketTradeDemo.java
public void start() throws ExecutionException, InterruptedException { // Use the default MtGox settings Exchange mtGoxExchange = MtGoxV2ExamplesUtils.createExchange(); ExchangeStreamingConfiguration exchangeStreamingConfiguration = new MtGoxStreamingConfiguration(10, 10000, 60000, false, null);/* w ww . j ava 2s . c om*/ // Interested in the public streaming market data feed (no authentication) StreamingExchangeService streamingExchangeService = mtGoxExchange .getStreamingExchangeService(exchangeStreamingConfiguration); // Open the connections to the exchange streamingExchangeService.connect(); ExecutorService executorService = Executors.newSingleThreadExecutor(); Future<?> mtGoxMarketDataFuture = executorService .submit(new TradeDataRunnable(streamingExchangeService, mtGoxExchange)); // the thread waits here until the Runnable is done. mtGoxMarketDataFuture.get(); executorService.shutdown(); // Disconnect and exit System.out.println(Thread.currentThread().getName() + ": Disconnecting..."); streamingExchangeService.disconnect(); }
From source file:arlocros.ArMarkerPoseEstimator.java
private ArMarkerPoseEstimator(final ConnectedNode connectedNode, Parameter parameter, Publisher<PoseStamped> posePublisher) { mostRecentPose = new AtomicReference<>(); this.parameter = parameter; this.posePublisher = posePublisher; Executors.newSingleThreadExecutor().submit(new Runnable() { @Override//from w w w.j a v a 2s. co m public void run() { start(connectedNode); } }); }
From source file:com.google.cloud.speech.grpc.demos.NonStreamingRecognizeClient.java
/** * Construct client connecting to Cloud Speech server at {@code host:port}. *///from ww w.j a v a 2s . c om public NonStreamingRecognizeClient(String host, int port, URI input, int samplingRate) throws IOException { this.host = host; this.port = port; this.input = input; this.samplingRate = samplingRate; GoogleCredentials creds = GoogleCredentials.getApplicationDefault(); creds = creds.createScoped(OAUTH2_SCOPES); channel = NettyChannelBuilder.forAddress(host, port).negotiationType(NegotiationType.TLS) .intercept(new ClientAuthInterceptor(creds, Executors.newSingleThreadExecutor())).build(); blockingStub = SpeechGrpc.newBlockingStub(channel); logger.info("Created blockingStub for " + host + ":" + port); }
From source file:com.srotya.sidewinder.cluster.storage.ClusteredMemStorageEngine.java
@Override public void connect() throws IOException { this.local.connect(); Executors.newSingleThreadExecutor().submit(columbus); while (columbus.getWorkerCount() < clusterSize) { try {/*from w w w .ja v a 2 s . c o m*/ Thread.sleep(2000); } catch (InterruptedException e) { break; } logger.info("Waiting for worker discovery"); } this.clients = new HashMap<>(); for (Entry<Integer, WorkerEntry> entry : columbus.getWorkerMap().entrySet()) { if (entry.getKey() != columbus.getSelfWorkerId()) { TCPClient client = new TCPClient(entry.getValue()); clients.put(entry.getKey(), client); client.connect(); logger.info("Connected to " + entry.getValue().getWorkerAddress()); } } logger.info("All worker connections initialized"); }
From source file:net.java.html.charts.ChartsTest.java
/** * * @throws InterruptedException//from ww w . j a va2 s .c om */ @BeforeMethod public void initializePresenter() throws InterruptedException { animationComplete = false; final CountDownLatch initialized = new CountDownLatch(1); final BrowserBuilder builder = BrowserBuilder.newBrowser().loadPage("charts.html").loadFinished(() -> { presenter = Fn.activePresenter(); initialized.countDown(); }); Executors.newSingleThreadExecutor().execute(builder::showAndWait); initialized.await(); assertNotNull(presenter, "We have the presenter"); }