List of usage examples for java.util.concurrent CountDownLatch await
public void await() throws InterruptedException
From source file:org.kurento.tutorial.helloworld.HelloWorldController.java
@RequestMapping(value = "/helloworld", method = RequestMethod.POST) private String processRequest(@RequestBody String sdpOffer) { final CountDownLatch eventReceived = new CountDownLatch(1); // Media Logic MediaPipeline pipeline = kurento.createMediaPipeline(); WebRtcEndpoint webRtcEndpoint = new WebRtcEndpoint.Builder(pipeline).build(); webRtcEndpoint.addOnIceGatheringDoneListener(new EventListener<OnIceGatheringDoneEvent>() { @Override//from www. j a v a 2 s . c om public void onEvent(OnIceGatheringDoneEvent event) { eventReceived.countDown(); } }); webRtcEndpoint.connect(webRtcEndpoint); webRtcEndpoint.processOffer(sdpOffer); webRtcEndpoint.gatherCandidates(); try { eventReceived.await(); } catch (InterruptedException e) { } // SDP negotiation (offer and answer) String responseSdp = webRtcEndpoint.getLocalSessionDescriptor(); return responseSdp; }
From source file:com.github.oscerd.camel.cassandra.embedded.CassandraBaseTest.java
@Override public void doPostSetup() { String id = RandomStringUtils.random(12, "0123456789abcdefghijklmnopqrstuvwxyz"); fs = new Farsandra(); fs.withVersion("2.0.3"); fs.withCleanInstanceOnStart(true);/* w w w . j a va 2 s .c o m*/ fs.withInstanceName("target" + File.separator + id); fs.withCreateConfigurationFiles(true); fs.withHost("localhost"); fs.withSeeds(Arrays.asList("localhost")); final CountDownLatch started = new CountDownLatch(1); fs.getManager().addOutLineHandler(new LineHandler() { @Override public void handleLine(String line) { if (line.contains("Listening for thrift clients...")) { started.countDown(); } } }); fs.getManager().addProcessHandler(new ProcessHandler() { @Override public void handleTermination(int exitValue) { started.countDown(); } }); fs.start(); try { started.await(); Thread.sleep(3000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } Cluster cluster = Cluster.builder().addContactPoint("127.0.0.1").build(); Session session = cluster.connect(); session.execute("CREATE KEYSPACE IF NOT EXISTS simplex WITH replication " + "= {'class':'SimpleStrategy', 'replication_factor':3};"); session.execute("CREATE TABLE IF NOT EXISTS simplex.airport (" + "id int PRIMARY KEY," + "ident text," + "type text," + "name text," + "latitude_deg float," + "longitude_deg float," + "elevation_ft int," + "continent text," + "iso_country text," + "iso_region text," + "municipality text," + "scheduled_service text," + "gps_code text," + "iata_code text," + "local_code text," + "home_link text," + "wikipedia_link text," + "keywords text," + ");"); session.execute("CREATE INDEX IF NOT EXISTS name_idx ON simplex.airport(name);"); session.execute("CREATE INDEX IF NOT EXISTS continent_idx ON simplex.airport(continent);"); session.close(); cluster.close(); try { Thread.sleep(5 * 1000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.github.oscerd.component.cassandra.embedded.CassandraBaseCounterTest.java
@Override public void doPostSetup() { String id = RandomStringUtils.random(12, "0123456789abcdefghijklmnopqrstuvwxyz"); fs = new Farsandra(); fs.withVersion("2.0.3"); fs.withCleanInstanceOnStart(true);//w ww .j av a2s. c o m fs.withInstanceName("target" + File.separator + id); fs.withCreateConfigurationFiles(true); fs.withHost("localhost"); fs.withSeeds(Arrays.asList("localhost")); final CountDownLatch started = new CountDownLatch(1); fs.getManager().addOutLineHandler(new LineHandler() { @Override public void handleLine(String line) { if (line.contains("Listening for thrift clients...")) { started.countDown(); } } }); fs.getManager().addProcessHandler(new ProcessHandler() { @Override public void handleTermination(int exitValue) { started.countDown(); } }); fs.start(); try { started.await(); Thread.sleep(3000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } Cluster cluster = Cluster.builder().addContactPoint("127.0.0.1").build(); Session session = cluster.connect(); session.execute("CREATE KEYSPACE IF NOT EXISTS simplex WITH replication " + "= {'class':'SimpleStrategy', 'replication_factor':3};"); session.execute( "CREATE TABLE IF NOT EXISTS simplex.counter (" + "like counter, " + "id int PRIMARY KEY" + ");"); session.close(); session = cluster.connect("simplex"); Where update = QueryBuilder.update("counter").with(QueryBuilder.incr("like", 1)) .where(QueryBuilder.eq("id", 1)); session.execute(update); session.close(); cluster.close(); try { Thread.sleep(5 * 1000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.onyxscheduler.domain.SchedulerIT.java
private void waitJobWithPastDateWithName(String jobName) throws Scheduler.DuplicateJobKeyException, InterruptedException { CountDownLatch latch = new CountDownLatch(1); latchProvider.setLatch(latch);// www.j a v a 2 s .c om CountDownJob existingJob = CountDownJob.buildFromGroupAndNameAndTriggers(JOB_GROUP, jobName, ImmutableSet.of(Trigger.fromFixedTime(buildPastDate()))); scheduler.scheduleJob(existingJob); latch.await(); }
From source file:io.fabric8.maven.core.service.openshift.OpenshiftBuildService.java
private void waitUntilBuildFinished(CountDownLatch latch) { while (latch.getCount() > 0L) { try {//from w ww .j a v a2s. c o m latch.await(); } catch (InterruptedException e) { // ignore } } }
From source file:com.vladmihalcea.OptimisticLockingTest.java
@Test public void testRetries() throws InterruptedException { final Product product = productService.newProduct(); assertEquals(0, product.getVersion()); Product savedProduct = productService.updateName(product.getId(), "name"); assertEquals(1, savedProduct.getVersion()); final int threadsNumber = 10; final AtomicInteger atomicInteger = new AtomicInteger(); final CountDownLatch startLatch = new CountDownLatch(threadsNumber + 1); final CountDownLatch endLatch = new CountDownLatch(threadsNumber + 1); for (; atomicInteger.get() < threadsNumber; atomicInteger.incrementAndGet()) { final long index = (long) atomicInteger.get() * threadsNumber; LOGGER.info("Scheduling thread index {}", index); Thread testThread = new Thread(new Runnable() { @Override/*from w ww .j a va 2 s . com*/ public void run() { try { startLatch.countDown(); startLatch.await(); productService.updateName(product.getId(), UUID.randomUUID().toString()); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } catch (Exception e) { LOGGER.error("Exception thrown!", e); } finally { endLatch.countDown(); } } }); testThread.start(); } startLatch.countDown(); LOGGER.info("Waiting for threads to be done"); endLatch.countDown(); endLatch.await(); LOGGER.info("Threads are done"); }
From source file:info.archinnov.achilles.it.TestJSONCall.java
@Test public void should_insert_json_if_not_exists() throws Exception { //Given// ww w . j av a 2s . com final long id = RandomUtils.nextLong(0L, Long.MAX_VALUE); //When String json = "{\"id\": " + id + ", \"clust\": 1, \"value\": \"val\", " + "\"liststring\": [\"one\"], " + "\"setstring\": [\"two\"], " + "\"mapstring\": {\"3\": \"three\"}" + "}"; AtomicBoolean success = new AtomicBoolean(false); final CountDownLatch latch = new CountDownLatch(1); manager.crud().insertJSON(json).ifNotExists().withLwtResultListener(new LWTResultListener() { @Override public void onSuccess() { success.getAndSet(true); latch.countDown(); } @Override public void onError(LWTResult lwtResult) { latch.countDown(); } }).execute(); //Then latch.await(); assertThat(success.get()).isTrue(); final Row row = session.execute( "SELECT * FROM achilles_embedded.entity_for_json_function_call WHERE id = " + id + "AND clust = 1") .one(); assertThat(row).isNotNull(); assertThat(row.getString("value")).isEqualTo("val"); assertThat(row.getList("liststring", String.class)).containsExactly("one"); assertThat(row.getSet("setstring", String.class)).containsExactly("two"); assertThat(row.getMap("mapstring", Integer.class, String.class)).hasSize(1).containsEntry(3, "three"); }
From source file:example.springdata.mongodb.people.ReactiveMongoTemplateIntegrationTest.java
/** * This sample performs a count, inserts data and performs a count again using reactive operator chaining. It prints * the two counts ({@code 4} and {@code 6}) to the console. */// w w w. j a va2 s. c om @Test public void shouldInsertAndCountData() throws Exception { CountDownLatch countDownLatch = new CountDownLatch(1); template.count(new Query(), Person.class) // .doOnNext(System.out::println) // .thenMany(template.save(Flux.just(new Person("Hank", "Schrader", 43), // new Person("Mike", "Ehrmantraut", 62)))) // .last() // .flatMap(v -> template.count(new Query(), Person.class)) // .doOnNext(System.out::println) // .doOnSuccess(it -> countDownLatch.countDown()) // .doOnError(throwable -> countDownLatch.countDown()) // .subscribe(); countDownLatch.await(); }
From source file:info.archinnov.achilles.it.TestAsyncDSLSimpleEntity.java
@Test public void should_dsl_delete_async() throws Exception { //Given/*from w w w. j a va 2s . c o m*/ final long id = RandomUtils.nextLong(0L, Long.MAX_VALUE); final Date date = buildDateKey(); scriptExecutor.executeScriptTemplate("SimpleEntity/insert_single_row.cql", ImmutableMap.of("id", id, "table", "simple")); final CountDownLatch latch = new CountDownLatch(1); final CassandraLogAsserter logAsserter = new CassandraLogAsserter(); logAsserter.prepareLogLevel(ASYNC_LOGGER_STRING, "%msg - [%thread]%n"); //When manager.dsl().delete().consistencyList().simpleMap().fromBaseTable().where().id_Eq(id).date_Eq(date) .withResultSetAsyncListener(rs -> { LOGGER.info(CALLED); latch.countDown(); return rs; }).withTracing().executeAsync(); //Then latch.await(); logAsserter.assertContains("Called - "); }