List of usage examples for java.util.concurrent.atomic AtomicBoolean get
public final boolean get()
From source file:ductive.console.shell.EmbeddedGroovyShell.java
@Override public void execute(InteractiveTerminal terminal, TerminalUser user) throws IOException { Binding binding = new Binding(); if (context != null) for (Entry<String, Object> e : context.entrySet()) binding.setVariable(e.getKey(), e.getValue()); CompilerConfiguration config = new CompilerConfiguration(); binding.setProperty("out", new PrintStream(terminal.output(), true)); // binding.setProperty("in",new BufferedReader(new InputStreamReader(terminal.input()))); FIXME: GroovyInterpreter interpreter = new GroovyInterpreter(binding, config); try (ShellHistory history = historyProvider.history(HISTORY_KEY)) { final AtomicBoolean pending = new AtomicBoolean(false); ShellSettings settings = new StaticShellSettings(new Provider<Ansi>() { @Override/* w w w . java 2s. co m*/ public Ansi get() { return pending.get() ? pendingPrompt : standardPrompt; } }, new ReflectionCompleter(interpreter), history); terminal.updateSettings(settings); while (true) { pending.set(false); final String code; try { code = new CodeReader(terminal, pending).read(); } catch (UserInterruptException e) { continue; } if (code == null) { terminal.println(""); break; } if (StringUtils.isBlank(code)) continue; try { Object result = interpreter.interpret(code); terminal.println(String.format(resultMarker.toString(), result)); } catch (Throwable e) { // Unroll invoker exceptions if (e instanceof InvokerInvocationException) { e = e.getCause(); } PrintStream ps = new PrintStream(terminal.error()); e.printStackTrace(ps); ps.flush(); } } } }
From source file:com.navercorp.pinpoint.profiler.sender.NioUdpDataSenderTest.java
private boolean sendMessage_getLimit(TBase tbase, long waitTimeMillis) throws InterruptedException { final AtomicBoolean limitCounter = new AtomicBoolean(false); final CountDownLatch latch = new CountDownLatch(1); NioUDPDataSender sender = newNioUdpDataSender(); try {/*from w w w . ja va 2 s. c o m*/ sender.send(tbase); latch.await(waitTimeMillis, TimeUnit.MILLISECONDS); } finally { sender.stop(); } return limitCounter.get(); }
From source file:com.acme.ModuleConfigurationTest.java
@Test public void test() { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); Properties properties = new Properties(); properties.put("prefix", "foo"); properties.put("suffix", "bar"); context.getEnvironment().getPropertySources().addLast(new PropertiesPropertySource("options", properties)); context.register(TestConfiguration.class); context.refresh();// w w w. ja v a2s. c o m MessageChannel input = context.getBean("input", MessageChannel.class); SubscribableChannel output = context.getBean("output", SubscribableChannel.class); final AtomicBoolean handled = new AtomicBoolean(); output.subscribe(new MessageHandler() { @Override public void handleMessage(Message<?> message) throws MessagingException { handled.set(true); assertEquals("foohellobar", message.getPayload()); } }); input.send(new GenericMessage<String>("hello")); assertTrue(handled.get()); }
From source file:ch.cyberduck.core.sds.SDSMissingFileKeysSchedulerFeatureTest.java
@Test(expected = LoginCanceledException.class) public void testWrongPassword() throws Exception { final Host host = new Host(new SDSProtocol(), "duck.ssp-europe.eu", new Credentials( System.getProperties().getProperty("sds.user"), System.getProperties().getProperty("sds.key"))); final SDSSession session = new SDSSession(host, new DisabledX509TrustManager(), new DefaultX509KeyManager()); session.open(new DisabledHostKeyCallback()); session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback()); final SDSMissingFileKeysSchedulerFeature background = new SDSMissingFileKeysSchedulerFeature(session); final AtomicBoolean prompt = new AtomicBoolean(); final List<UserFileKeySetRequest> processed = background.operate(new PasswordCallback() { @Override// ww w . ja va2 s. c o m public Credentials prompt(final Host bookmark, final String title, final String reason, final LoginOptions options) throws LoginCanceledException { if (prompt.get()) { throw new LoginCanceledException(); } prompt.set(true); return new VaultCredentials("n"); } }, null); assertTrue(prompt.get()); session.close(); }
From source file:com.example.app.ui.DemoUserProfileEditor.java
@Override public boolean validateUIValue(final Notifiable notifiable) { final AtomicBoolean valid = new AtomicBoolean(true); _forEach(value -> valid.set(value.validateUIValue(notifiable) && valid.get())); return valid.get(); }
From source file:io.dropwizard.discovery.bundle.ServiceDiscoveryBundleCustomHostPortTest.java
@Before public void setup() throws Exception { when(jerseyEnvironment.getResourceConfig()).thenReturn(new DropwizardResourceConfig()); when(environment.jersey()).thenReturn(jerseyEnvironment); when(environment.lifecycle()).thenReturn(lifecycleEnvironment); when(environment.healthChecks()).thenReturn(healthChecks); when(environment.getObjectMapper()).thenReturn(new ObjectMapper()); AdminEnvironment adminEnvironment = mock(AdminEnvironment.class); doNothing().when(adminEnvironment).addTask(any()); when(environment.admin()).thenReturn(adminEnvironment); testingCluster.start();//from w w w.j a va 2 s. c om serviceDiscoveryConfiguration = ServiceDiscoveryConfiguration.builder() .zookeeper(testingCluster.getConnectString()).namespace("test").environment("testing") .connectionRetryIntervalMillis(5000).publishedHost("TestHost").publishedPort(8021) .initialRotationStatus(true).build(); bundle.initialize(bootstrap); bundle.run(configuration, environment); final AtomicBoolean started = new AtomicBoolean(false); executorService.submit(() -> lifecycleEnvironment.getManagedObjects().forEach(object -> { try { object.start(); started.set(true); } catch (Exception e) { e.printStackTrace(); } })); while (!started.get()) { Thread.sleep(1000); log.debug("Waiting for framework to start..."); } bundle.registerHealthcheck(() -> status); }
From source file:com.frostwire.platform.FileSystemWalkTest.java
@Test public void testAnyFile() { final AtomicBoolean b = new AtomicBoolean(false); fs.walk(new File("any.txt"), new FileFilter() { @Override// ww w. j a v a 2 s .com public boolean accept(File file) { return true; } @Override public void file(File file) { b.set(true); } }); assertFalse(b.get()); b.set(false); fs.walk(new File("any.txt"), new FileFilter() { @Override public boolean accept(File file) { return !file.isDirectory(); } @Override public void file(File file) { b.set(true); } }); assertFalse(b.get()); }
From source file:io.dropwizard.discovery.bundle.ServiceDiscoveryBundleRotationTest.java
@Before public void setup() throws Exception { when(jerseyEnvironment.getResourceConfig()).thenReturn(new DropwizardResourceConfig()); when(environment.jersey()).thenReturn(jerseyEnvironment); when(environment.lifecycle()).thenReturn(lifecycleEnvironment); when(environment.healthChecks()).thenReturn(healthChecks); when(environment.getObjectMapper()).thenReturn(new ObjectMapper()); AdminEnvironment adminEnvironment = mock(AdminEnvironment.class); doNothing().when(adminEnvironment).addTask(any()); when(environment.admin()).thenReturn(adminEnvironment); testingCluster.start();/* w ww . j av a2s . c om*/ serviceDiscoveryConfiguration = ServiceDiscoveryConfiguration.builder() .zookeeper(testingCluster.getConnectString()).namespace("test").environment("testing") .connectionRetryIntervalMillis(5000).publishedHost("TestHost").publishedPort(8021) .initialRotationStatus(true).build(); bundle.initialize(bootstrap); bundle.run(configuration, environment); rotationStatus = bundle.getRotationStatus(); final AtomicBoolean started = new AtomicBoolean(false); executorService.submit(() -> lifecycleEnvironment.getManagedObjects().forEach(object -> { try { object.start(); started.set(true); } catch (Exception e) { e.printStackTrace(); } })); while (!started.get()) { Thread.sleep(1000); log.debug("Waiting for framework to start..."); } }
From source file:com.netflix.curator.framework.recipes.atomic.TestDistributedAtomicLong.java
@Test public void testCompareAndSet() throws Exception { final CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1)); client.start();//w w w. j a v a2 s . c o m try { final AtomicBoolean doIncrement = new AtomicBoolean(false); DistributedAtomicLong dal = new DistributedAtomicLong(client, "/counter", new RetryOneTime(1)) { @Override public byte[] valueToBytes(Long newValue) { if (doIncrement.get()) { DistributedAtomicLong inc = new DistributedAtomicLong(client, "/counter", new RetryOneTime(1)); try { // this will force a bad version exception inc.increment(); } catch (Exception e) { throw new Error(e); } } return super.valueToBytes(newValue); } }; dal.forceSet(1L); Assert.assertTrue(dal.compareAndSet(1L, 5L).succeeded()); Assert.assertFalse(dal.compareAndSet(1L, 5L).succeeded()); doIncrement.set(true); Assert.assertFalse(dal.compareAndSet(5L, 10L).succeeded()); } finally { client.close(); } }
From source file:io.github.jeddict.jpa.modeler.properties.convert.OverrideConvertPanel.java
private boolean validateField() { // if (this.converter_EditorPane.getText().trim().length() <= 0 && !disableConversion_CheckBox.isSelected()) { // JOptionPane.showMessageDialog(this, getMessage(OverrideConvertPanel.class, "MSG_Validation"), "Invalid Value", javax.swing.JOptionPane.WARNING_MESSAGE); // return false; // }//from ww w .java 2 s .c om if (attribute_ComboBox.isEnabled() && this.attribute_ComboBox.getSelectedItem().toString().trim().length() <= 0 && !disableConversion_CheckBox.isSelected()) { JOptionPane.showMessageDialog(this, "Attribute name can't be empty", "Invalid Value", javax.swing.JOptionPane.WARNING_MESSAGE); return false; } AtomicBoolean validated = new AtomicBoolean(false); importAttributeConverter(converter_EditorPane.getText(), validated, modelerFile); return validated.get(); }