List of usage examples for java.util.concurrent.atomic AtomicBoolean get
public final boolean get()
From source file:com.github.lynxdb.server.core.repository.TimeSerieRepo.java
public ChainableIterator<TimeSerie> find(UUID _vhost, String _name, Map<String, String> _tags, long _start, long _end) { return findRows(_vhost, _name, _tags, _start, _end).map( (ChainableIterator.Func1<ChainableIterator<TS>, TimeSerie>) (ChainableIterator<TS> _source) -> { Map<String, String> tags = new HashMap<>(); AtomicBoolean tagsLoaded = new AtomicBoolean(false); return new TimeSerie(_name, tags, new ChainableIterator<Entry>() { Iterator<Row> current = null; @Override// ww w. jav a 2s. c om public boolean hasNext() { if (current != null && current.hasNext()) { return true; } while (_source.hasNext()) { TS newTS = _source.next(); if (!tagsLoaded.get()) { tagsLoaded.set(true); tags.putAll(newTS.tags); } long start = System.currentTimeMillis(); current = ct.query(QueryBuilder.select("time", "value").from("series") .where(QueryBuilder.eq("vhostid", _vhost)) .and(QueryBuilder.eq("name", _name)) .and(QueryBuilder.eq("tags", newTS.serialized)) .and(QueryBuilder.eq("group", newTS.group)) .and(QueryBuilder.gte("time", _start)).and(QueryBuilder.lte("time", _end)) .orderBy(QueryBuilder.desc("time"))).iterator(); csMonit.tsFetchQueryTime.add((int) (System.currentTimeMillis() - start)); csMonit.queryFetchCount.incrementAndGet(); if (current.hasNext()) { return true; } } return false; } @Override public Entry next() { Row r = current.next(); return new Entry(r.getInt("time"), r.getDouble("value")); } }); }); }
From source file:de.speexx.jira.jan.command.transition.IssueTransitionFetcher.java
void exportAsCsv(final List<IssueInfo> issues, final AtomicBoolean doHeader) { try {//from w w w. j a va2s. c o m final CSVPrinter csvPrinter = new CSVPrinter(new OutputStreamWriter(System.out, StandardCharsets.UTF_8), RFC4180); final String[] header = new String[] { "issue-key", "type", "issue-creation-datetime", "priority", "resolution", "from-stage", "stage", "stage-enter-datetime", "stage-duration" }; if (!doHeader.get()) { csvPrinter.printRecord((Object[]) header); doHeader.set(true); } issues.forEach(info -> { info.stageInfoAsDuration().forEach(stageDuration -> { final String[] values = new String[header.length]; values[0] = info.key; values[1] = info.issueType; values[2] = DateTimeFormatter.ISO_DATE_TIME.format(info.created); values[3] = info.priority; values[4] = resolutionAdjustment(info); values[5] = stageDuration.fromStageName != null ? "" + stageDuration.fromStageName : ""; values[6] = "" + stageDuration.stageName; values[7] = DateTimeFormatter.ISO_DATE_TIME.format(stageDuration.stageStart); values[8] = "" + stageDuration.getDurationSeconds(); try { csvPrinter.printRecord((Object[]) values); } catch (final IOException e) { throw new JiraAnalyzeException(e); } }); }); csvPrinter.flush(); } catch (final IOException e) { throw new JiraAnalyzeException(e); } }
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 w w w.ja v a2 s . c om*/ 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:de.acosix.alfresco.site.hierarchy.repo.integration.ManagementViaWebScriptsTest.java
protected void checkSiteInTopLevelSites(final WebTarget webTarget, final Object ticket, final String siteShortName, final boolean expectation) { final TopLevelSites topLevelSites = webTarget.path("/acosix/api/sites/topLevelSites") .queryParam("alf_ticket", ticket).request(MediaType.APPLICATION_JSON).get(TopLevelSites.class); Assert.assertNotNull("List of top-level sites should never be null", topLevelSites.getSites()); if (expectation) { Assert.assertFalse("List of top-level sites should not be empty", topLevelSites.getSites().isEmpty()); }// w w w . j a v a 2s .com final AtomicBoolean containsSite = new AtomicBoolean(false); topLevelSites.getSites().forEach(site -> { if (site.getShortName().equals(siteShortName)) { containsSite.set(true); } }); Assert.assertEquals("Site top-level status listing does not match expectation", expectation, containsSite.get()); }
From source file:com.corundumstudio.socketio.annotation.SpringAnnotationScanner.java
@Override public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { final AtomicBoolean add = new AtomicBoolean(); ReflectionUtils.doWithMethods(bean.getClass(), new MethodCallback() { @Override//from w w w. j a v a 2s . c o m public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException { add.set(true); } }, new MethodFilter() { @Override public boolean matches(Method method) { for (Class<? extends Annotation> annotationClass : annotations) { if (method.isAnnotationPresent(annotationClass)) { return true; } } return false; } }); if (add.get()) { originalBeanClass = bean.getClass(); } return bean; }
From source file:net.mwplay.cocostudio.ui.junit.LibgdxRunner.java
@Override protected void runChild(final FrameworkMethod method, final RunNotifier notifier) { final Description description = describeChild(method); if (description.getAnnotation(NeedGL.class) != null) { final AtomicBoolean running = new AtomicBoolean(true); Gdx.app.postRunnable(new Runnable() { @Override//from w w w . jav a2s .c o m public void run() { if (LibgdxRunner.this.isIgnored(method)) { notifier.fireTestIgnored(description); } else { LibgdxRunner.this.runLeaf(methodBlock(method), description, notifier); } running.set(false); } }); ConditionWaiter.wait(new Condition() { @Override public Boolean check() { return !running.get(); } }, description, 30, new Runnable() { @Override public void run() { LibgdxRunner.this.closeGdxApplication(); } }); } else { runLeaf(methodBlock(method), description, notifier); } }
From source file:net.sourceforge.ganttproject.io.CsvImportTest.java
public void testBasic() throws Exception { String header = "A, B"; String data = "a1, b1"; final AtomicBoolean wasCalled = new AtomicBoolean(false); GanttCSVOpen.RecordGroup recordGroup = new GanttCSVOpen.RecordGroup("AB", ImmutableSet.<String>of("A", "B")) { @Override// w ww . jav a 2 s . c o m protected boolean doProcess(CSVRecord record) { wasCalled.set(true); assertEquals("a1", record.get("A")); assertEquals("b1", record.get("B")); return true; } }; GanttCSVOpen importer = new GanttCSVOpen(createSupplier(Joiner.on('\n').join(header, data)), recordGroup); importer.load(); assertTrue(wasCalled.get()); // Now test with one empty line between header and data wasCalled.set(false); importer = new GanttCSVOpen(createSupplier(Joiner.on('\n').join(header, "", data)), recordGroup); importer.load(); assertTrue(wasCalled.get()); }
From source file:ch.cyberduck.core.sftp.auth.SFTPPublicKeyAuthenticationTest.java
@Test(expected = LoginFailureException.class) public void testAuthenticateOpenSSHKeyWithPassword() throws Exception { final Credentials credentials = new Credentials(System.getProperties().getProperty("sftp.user"), ""); final Local key = new Local(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString()); try {/*ww w .jav a 2 s . c om*/ credentials.setIdentity(key); new DefaultLocalTouchFeature().touch(key); IOUtils.copy(new StringReader(System.getProperties().getProperty("sftp.key.openssh.rsa")), key.getOutputStream(false), Charset.forName("UTF-8")); final Host host = new Host(new SFTPProtocol(), "test.cyberduck.ch", credentials); final SFTPSession session = new SFTPSession(host); session.open(new DisabledHostKeyCallback()); final AtomicBoolean b = new AtomicBoolean(); assertTrue(new SFTPPublicKeyAuthentication(session).authenticate(host, new DisabledPasswordStore(), new DisabledLoginCallback() { @Override public Credentials prompt(final Host bookmark, String username, String title, String reason, LoginOptions options) throws LoginCanceledException { b.set(true); throw new LoginCanceledException(); } }, new DisabledCancelCallback())); assertTrue(b.get()); session.close(); } finally { key.delete(); } }
From source file:ch.cyberduck.core.sftp.auth.SFTPPublicKeyAuthenticationTest.java
@Test(expected = LoginFailureException.class) public void testAuthenticatePuTTYKeyWithWrongPassword() throws Exception { final Credentials credentials = new Credentials(System.getProperties().getProperty("sftp.user"), ""); final Local key = new Local(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString()); try {//from www . j a v a 2 s . c o m credentials.setIdentity(key); new DefaultLocalTouchFeature().touch(key); IOUtils.copy(new StringReader(System.getProperties().getProperty("sftp.key.putty")), key.getOutputStream(false), Charset.forName("UTF-8")); final Host host = new Host(new SFTPProtocol(), "test.cyberduck.ch", credentials); final SFTPSession session = new SFTPSession(host); session.open(new DisabledHostKeyCallback()); final AtomicBoolean p = new AtomicBoolean(); assertFalse(new SFTPPublicKeyAuthentication(session).authenticate(host, new DisabledPasswordStore(), new DisabledLoginCallback() { @Override public Credentials prompt(final Host bookmark, String username, String title, String reason, LoginOptions options) throws LoginCanceledException { p.set(true); throw new LoginCanceledException(); } }, new DisabledCancelCallback())); assertTrue(p.get()); session.close(); } finally { key.delete(); } }
From source file:org.apache.hadoop.hdfs.TestFileConcurrentReader.java
@Test public void testImmediateReadOfNewFile() throws IOException { final int blockSize = 64 * 1024; final int writeSize = 10 * blockSize; Configuration conf = new Configuration(); conf.setLong(DFSConfigKeys.DFS_BLOCK_SIZE_KEY, blockSize); init(conf);// w w w.ja v a 2 s . c o m final int requiredSuccessfulOpens = 100; final Path file = new Path("/file1"); final AtomicBoolean openerDone = new AtomicBoolean(false); final AtomicReference<String> errorMessage = new AtomicReference<>(); final FSDataOutputStream out = fileSystem.create(file); final Thread writer = new Thread(new Runnable() { @Override public void run() { try { while (!openerDone.get()) { out.write(DFSTestUtil.generateSequentialBytes(0, writeSize)); out.hflush(); } } catch (IOException e) { LOG.warn("error in writer", e); } finally { try { out.close(); } catch (IOException e) { LOG.error("unable to close file"); } } } }); Thread opener = new Thread(new Runnable() { @Override public void run() { try { for (int i = 0; i < requiredSuccessfulOpens; i++) { fileSystem.open(file).close(); } openerDone.set(true); } catch (IOException e) { openerDone.set(true); errorMessage.set(String.format("got exception : %s", StringUtils.stringifyException(e))); } catch (Exception e) { openerDone.set(true); errorMessage.set(String.format("got exception : %s", StringUtils.stringifyException(e))); writer.interrupt(); fail("here"); } } }); writer.start(); opener.start(); try { writer.join(); opener.join(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } assertNull(errorMessage.get(), errorMessage.get()); }