List of usage examples for java.util.concurrent.atomic AtomicBoolean set
public final void set(boolean newValue)
From source file:com.google.gdt.eclipse.designer.util.Utils.java
/** * @return <code>true</code> if given module inherits required, directly or indirectly. *///from w w w.j av a 2 s . c o m public static boolean inheritsModule(ModuleDescription moduleDescription, final String requiredModule) throws Exception { final AtomicBoolean result = new AtomicBoolean(); ModuleVisitor.accept(moduleDescription, new ModuleVisitor() { @Override public void endVisitModule(ModuleElement module) { if (requiredModule.equals(module.getId())) { result.set(true); } } }); return result.get(); }
From source file:com.clxcommunications.xms.ApiConnectionTest.java
@Test public void leavesExternalHttpClientAlone() throws Exception { final AtomicBoolean clientClosed = new AtomicBoolean(); ApiConnection conn = ApiConnection.builder().token("token").servicePlanId("spid") .httpClient(new DummyClient() { @Override/* w ww. jav a 2 s . co m*/ public void close() throws IOException { clientClosed.set(true); } }).build(); conn.start(); conn.close(); assertThat(clientClosed.get(), is(false)); }
From source file:de.taimos.pipeline.aws.cloudformation.EventPrinter.java
public void waitAndPrintStackEvents(String stack, Waiter<DescribeStacksRequest> waiter) { Date startDate = new Date(); final AtomicBoolean done = new AtomicBoolean(false); waiter.runAsync(new WaiterParameters<>(new DescribeStacksRequest().withStackName(stack)), new WaiterHandler() { @Override/*from w w w. java2s.c o m*/ public void onWaitSuccess(AmazonWebServiceRequest request) { done.set(true); } @Override public void onWaitFailure(Exception e) { done.set(true); } }); String lastEventId = null; this.printLine(); this.printStackName(stack); this.printLine(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); while (!done.get()) { try { DescribeStackEventsResult result = this.client .describeStackEvents(new DescribeStackEventsRequest().withStackName(stack)); List<StackEvent> stackEvents = new ArrayList<>(); for (StackEvent event : result.getStackEvents()) { if (event.getEventId().equals(lastEventId) || event.getTimestamp().before(startDate)) { break; } stackEvents.add(event); } if (!stackEvents.isEmpty()) { Collections.reverse(stackEvents); for (StackEvent event : stackEvents) { this.printEvent(sdf, event); this.printLine(); } lastEventId = stackEvents.get(stackEvents.size() - 1).getEventId(); } } catch (AmazonCloudFormationException e) { // suppress and continue } try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } }
From source file:io.vertx.config.vault.utils.VaultProcess.java
private void startServer() { String line = executable.getAbsolutePath() + " server -config=src/test/resources/config.json"; System.out.println(">> " + line); CommandLine parse = CommandLine.parse(line); DefaultExecutor executor = new DefaultExecutor(); DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler(); AtomicBoolean ready = new AtomicBoolean(); PumpStreamHandler pump = new PumpStreamHandler(new VaultOutputStream().addExtractor(l -> { if (l.contains("Vault server started!")) { ready.set(true); }/*from w w w. j av a 2 s. c o m*/ }), System.err); watchDog = new ExecuteWatchdog(ExecuteWatchdog.INFINITE_TIMEOUT); executor.setWatchdog(watchDog); executor.setStreamHandler(pump); try { executor.execute(parse, resultHandler); } catch (IOException e) { throw new RuntimeException(e); } await().untilAtomic(ready, is(true)); System.out.println("Vault Server ready - but not yet initialized"); }
From source file:com.github.thorbenlindhauer.math.MathUtil.java
public boolean isZeroMatrix() { final AtomicBoolean isZeroMatrix = new AtomicBoolean(true); // TODO: optimize to stop after first non-zero entry matrix.walkInOptimizedOrder(new DefaultRealMatrixPreservingVisitor() { @Override/* ww w . ja v a 2 s . co m*/ public void visit(int row, int column, double value) { if (value > DOUBLE_COMPARISON_OFFSET || value < -DOUBLE_COMPARISON_OFFSET) { isZeroMatrix.set(false); } } }); return isZeroMatrix.get(); }
From source file:io.spring.initializr.web.support.SpringBootMetadataReaderTests.java
@Test public void readAvailableVersions() throws IOException { this.server.expect(requestTo("https://spring.io/project_metadata/spring-boot")).andRespond( withSuccess(new ClassPathResource("metadata/sagan/spring-boot.json"), MediaType.APPLICATION_JSON)); List<DefaultMetadataElement> versions = new SpringBootMetadataReader(this.objectMapper, this.restTemplate, this.metadata.getConfiguration().getEnv().getSpringBootMetadataUrl()).getBootVersions(); assertThat(versions).as("spring boot versions should not be null").isNotNull(); AtomicBoolean defaultFound = new AtomicBoolean(false); versions.forEach((it) -> {/*w w w.ja va 2s .co m*/ assertThat(it.getId()).as("Id must be set").isNotNull(); assertThat(it.getName()).as("Name must be set").isNotNull(); if (it.isDefault()) { if (defaultFound.get()) { fail("One default version was already found " + it.getId()); } defaultFound.set(true); } }); this.server.verify(); }
From source file:com.baidu.oped.apm.profiler.sender.UdpDataSenderTest.java
private boolean sendMessage_getLimit(TBase tbase) throws InterruptedException { final AtomicBoolean limitCounter = new AtomicBoolean(false); final CountDownLatch latch = new CountDownLatch(1); UdpDataSender sender = new UdpDataSender("localhost", 9009, "test", 128, 1000, 1024 * 64 * 100) { @Override/*from ww w . j ava 2 s . com*/ protected boolean isLimit(int interBufferSize) { boolean limit = super.isLimit(interBufferSize); limitCounter.set(limit); latch.countDown(); return limit; } }; try { sender.send(tbase); latch.await(5000, TimeUnit.MILLISECONDS); } finally { sender.stop(); } return limitCounter.get(); }
From source file:com.spectralogic.ds3client.helpers.FileObjectGetter_Test.java
@Test public void testThatNamedPipeThrows() throws IOException, InterruptedException { Assume.assumeFalse(Platform.isWindows()); final String tempPathPrefix = null; final Path tempDirectory = Files.createTempDirectory(Paths.get("."), tempPathPrefix); final String FIFO_NAME = "bFifo"; final AtomicBoolean caughtException = new AtomicBoolean(false); try {// ww w .jav a2 s . co m Runtime.getRuntime().exec("mkfifo " + Paths.get(tempDirectory.toString(), FIFO_NAME)).waitFor(); new FileObjectGetter(tempDirectory).buildChannel(FIFO_NAME); } catch (final UnrecoverableIOException e) { assertTrue(e.getMessage().contains(FIFO_NAME)); caughtException.set(true); } finally { FileUtils.deleteDirectory(tempDirectory.toFile()); } assertTrue(caughtException.get()); }
From source file:com.jayway.restassured.path.xml.XmlPathObjectDeserializationTest.java
@Test public void xml_path_supports_custom_deserializer() { // Given/*www. jav a2s . c o m*/ final AtomicBoolean customDeserializerUsed = new AtomicBoolean(false); final XmlPath xmlPath = new XmlPath(COOL_GREETING) .using(xmlPathConfig().defaultObjectDeserializer(new XmlPathObjectDeserializer() { public <T> T deserialize(ObjectDeserializationContext ctx) { customDeserializerUsed.set(true); final String xml = ctx.getDataToDeserialize().asString(); final Greeting greeting = new Greeting(); greeting.setFirstName(StringUtils.substringBetween(xml, "<firstName>", "</firstName>")); greeting.setLastName(StringUtils.substringBetween(xml, "<lastName>", "</lastName>")); return (T) greeting; } })); // When final Greeting greeting = xmlPath.getObject("", Greeting.class); // Then assertThat(greeting.getFirstName(), equalTo("John")); assertThat(greeting.getLastName(), equalTo("Doe")); assertThat(customDeserializerUsed.get(), is(true)); }
From source file:io.pravega.client.stream.impl.ReaderGroupStateManager.java
void checkpoint(String checkpointName, PositionInternal lastPosition) throws ReinitializationRequiredException { AtomicBoolean reinitRequired = new AtomicBoolean(false); sync.updateState(state -> {/*from ww w . j ava 2s .co m*/ if (!state.isReaderOnline(readerId)) { reinitRequired.set(true); return null; } return Collections.singletonList( new CheckpointReader(checkpointName, readerId, lastPosition.getOwnedSegmentsWithOffsets())); }); if (reinitRequired.get()) { throw new ReinitializationRequiredException(); } }