List of usage examples for java.util.concurrent CountDownLatch countDown
public void countDown()
From source file:com.perfect.autosdk.core.JsonProxy.java
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { String addr = service.serverUrl + AddressUtil.getJsonAddr(interfaces) + '/' + method.getName(); JsonConnection conn = new GZIPJsonConnection(addr); conn.setConnectTimeout(service.connectTimeoutMills); conn.setReadTimeout(service.readTimeoutMills); JsonEnvelop request = makeRequest(args[0]); conn.sendRequest(request);// w w w. j a v a 2 s . com JsonEnvelop<ResHeader, ?> response = conn.readResponse(ResHeader.class, method.getReturnType()); ResHeader resHeader = response.getHeader(); if (!resHeader.getFailures().isEmpty()) { if (log.isErrorEnabled()) { log.error("Call Error: Head info = " + resHeader + "\n" + "account info = " + service.getUsername() + "\n" + "request info = " + addr + "\n" + "request param = " + args[0]); } if (resHeader.getFailures().get(0).getCode() == 8904) { Timer timer = new Timer("waitLock"); final CountDownLatch latch = new CountDownLatch(1); timer.schedule(new TimerTask() { @Override public void run() { System.out.println("waiting...."); latch.countDown(); } }, 15000); latch.await(); } } ResHeaderUtil.resHeader.set(response.getHeader()); BaiduApiQuota.setQuota(service.username, response.getHeader().getQuota()); return response.getBody(); }
From source file:ninja.eivind.hotsreplayuploader.files.tempwatcher.RecursiveTempWatcherTest.java
@Before public void setUp() throws Exception { directories = platformService.getBattleLobbyTempDirectories(); if (!(directories.getRoot().exists() || directories.getRoot().mkdirs())) { fail("Could not create tmp root"); }/*w w w .j ava 2 s .c o m*/ // give file creation some time to complete Thread.sleep(250); tempWatcher = new RecursiveTempWatcher(directories); CountDownLatch latch = new CountDownLatch(1); Platform.runLater(new Runnable() { @Override public void run() { tempWatcher.start(); latch.countDown(); } }); if (!latch.await(1, TimeUnit.SECONDS)) { fail("Service did not start."); } // give watchers some time to wind up Thread.sleep(250); }
From source file:com.espertech.esper.dataflow.core.EPDataFlowInstanceImpl.java
public synchronized void completed() { if (state != EPDataFlowState.CANCELLED) { setState(EPDataFlowState.COMPLETE); }//www .ja v a2 s . co m callOperatorClose(); if (joinedThreadLatches != null) { for (CountDownLatch joinedThread : joinedThreadLatches) { joinedThread.countDown(); } } }
From source file:example.springdata.cassandra.people.ReactivePersonRepositoryIntegrationTest.java
/** * Result set {@link com.datastax.driver.core.Row}s are converted to entities as they are emitted. Reactive pull and * prefetch define the amount of fetched records. *//*from w w w . j a v a 2 s . c o m*/ @Test public void shouldPerformConversionBeforeResultProcessing() throws Exception { CountDownLatch countDownLatch = new CountDownLatch(1); repository.findAll() // .doOnNext(System.out::println) // .doOnComplete(countDownLatch::countDown) // .doOnError(throwable -> countDownLatch.countDown()) // .subscribe(); countDownLatch.await(); }
From source file:com.vmware.photon.controller.api.client.resource.SystemStatusApiTest.java
@Test public void testGetVmAsync() throws IOException, InterruptedException { final SystemStatus systemStatus = new SystemStatus(); systemStatus.setStatus(StatusType.READY); ObjectMapper mapper = new ObjectMapper(); String serialized = mapper.writeValueAsString(systemStatus); setupMocks(serialized, HttpStatus.SC_OK); SystemStatusApi systemStatusApi = new SystemStatusApi(restClient); final CountDownLatch latch = new CountDownLatch(1); systemStatusApi.getSystemStatusAsync(new FutureCallback<SystemStatus>() { @Override/* ww w.j av a 2s. c om*/ public void onSuccess(@Nullable SystemStatus result) { assertEquals(result, systemStatus); latch.countDown(); } @Override public void onFailure(Throwable t) { fail(t.toString()); latch.countDown(); } }); assertThat(latch.await(COUNTDOWNLATCH_AWAIT_TIMEOUT, TimeUnit.SECONDS), is(true)); }
From source file:com.vmware.photon.controller.api.client.resource.SystemStatusRestApiTest.java
@Test public void testGetVmAsync() throws IOException, InterruptedException { final SystemStatus systemStatus = new SystemStatus(); systemStatus.setStatus(StatusType.READY); ObjectMapper mapper = new ObjectMapper(); String serialized = mapper.writeValueAsString(systemStatus); setupMocks(serialized, HttpStatus.SC_OK); SystemStatusApi systemStatusApi = new SystemStatusRestApi(restClient); final CountDownLatch latch = new CountDownLatch(1); systemStatusApi.getSystemStatusAsync(new FutureCallback<SystemStatus>() { @Override//from w ww. j a va 2 s . c o m public void onSuccess(@Nullable SystemStatus result) { assertEquals(result, systemStatus); latch.countDown(); } @Override public void onFailure(Throwable t) { fail(t.toString()); latch.countDown(); } }); assertThat(latch.await(COUNTDOWNLATCH_AWAIT_TIMEOUT, TimeUnit.SECONDS), is(true)); }
From source file:com.fusesource.forge.jmstest.executor.BenchmarkController.java
@Override synchronized public void stop() { coordinator.release();// ww w . j a v a 2 s. c om super.stop(); log().info("BenchmarkController going down in 5 Seconds"); final CountDownLatch brokerStopLatch = new CountDownLatch(1); final ScheduledThreadPoolExecutor waiter = new ScheduledThreadPoolExecutor(1); waiter.schedule(new Runnable() { public void run() { brokerStopLatch.countDown(); waiter.shutdown(); } }, 5, TimeUnit.SECONDS); try { brokerStopLatch.await(); } catch (InterruptedException e1) { } if (broker != null) { log().info("Stopping embedded broker for Benchmark framework: "); try { broker.stop(); } catch (Exception e) { // log().error("Embedded broker could not be stopped.", e); } } }
From source file:dstrelec.nats.listener.DefaultNatsListenerContainer.java
@Override public final void stop() { final CountDownLatch latch = new CountDownLatch(1); stop(new Runnable() { @Override//w w w. j a v a 2 s. com public void run() { latch.countDown(); } }); try { latch.await(this.containerProperties.getShutdownTimeout(), TimeUnit.MILLISECONDS); } catch (InterruptedException e) { // } }
From source file:com.github.jguaneri.notifications.web.controller.NotificationController.java
/** * @since 1.0/*from ww w .j a v a 2 s . c om*/ * @param channel * @param resource */ @RequestMapping(value = "/subscribe/{channel}", method = RequestMethod.GET) @ResponseBody public void subscribe(@PathVariable("channel") final String channel, final AtmosphereResource resource, Principal principal) throws Exception { final CountDownLatch countDownLatch = new CountDownLatch(1); resource.addEventListener(new AtmosphereResourceEventListenerAdapter() { @Override public void onSuspend(AtmosphereResourceEvent event) { countDownLatch.countDown(); LOGGER.info("Suspending Client..." + resource.uuid()); resource.removeEventListener(this); } @Override public void onDisconnect(AtmosphereResourceEvent event) { LOGGER.info("Disconnecting Client..." + resource.uuid()); super.onDisconnect(event); } @Override public void onBroadcast(AtmosphereResourceEvent event) { LOGGER.info("Client is broadcasting..." + resource.uuid()); super.onBroadcast(event); } }); if (AtmosphereResource.TRANSPORT.LONG_POLLING.equals(resource.transport())) { resource.resumeOnBroadcast(true).suspend(-1); } else { resource.suspend(-1); } try { countDownLatch.await(); } catch (InterruptedException e) { LOGGER.error("Interrupted while trying to suspend resource {}", resource); } if (LOGGER.isDebugEnabled()) { LOGGER.debug("Subscribing to channel: {}", channel); } final Client client = new Client(); client.setSubscriptionId(resource.uuid()); channelService.subscribe(client, channel); }
From source file:com.yahoo.gondola.container.ZookeeperRegistryClientTest.java
@Test public void testAddListener() throws Exception { ArgumentCaptor<RegistryClient.Entry> args = ArgumentCaptor.forClass(RegistryClient.Entry.class); InetSocketAddress addr = new InetSocketAddress(1234); CountDownLatch latch = new CountDownLatch(1); registryClient.addListener(entry1 -> { if (entry1.gondolaAddress.equals(addr)) { latch.countDown(); }// w w w . jav a 2 s. c om }); String hostId = registryClient.register(SITE_1_HOST_1_CLUSTER, addr, URI.create("https://api1.yahoo.com:4443")); latch.await(); verify(listener, times(1)).accept(args.capture()); RegistryClient.Entry entry = args.getValue(); assertEquals(entry.hostId, hostId); }