List of usage examples for java.util.concurrent.atomic AtomicLong get
public final long get()
From source file:org.apache.activemq.artemis.tests.integration.persistence.metrics.JournalPendingMessageTest.java
@Test public void testQueueMessageSizeNonPersistent() throws Exception { AtomicLong publishedMessageSize = new AtomicLong(); publishTestQueueMessages(200, DeliveryMode.NON_PERSISTENT, publishedMessageSize); verifyPendingStats(defaultQueueName, 200, publishedMessageSize.get()); verifyPendingDurableStats(defaultQueueName, 0, 0); }
From source file:org.apache.hadoop.hbase.client.TestAsyncTable.java
@Test public void testAppend() throws InterruptedException, ExecutionException { AsyncTableBase table = getTable.get(); int count = 10; CountDownLatch latch = new CountDownLatch(count); char suffix = ':'; AtomicLong suffixCount = new AtomicLong(0L); IntStream.range(0, count).forEachOrdered(i -> table .append(new Append(row).add(FAMILY, QUALIFIER, Bytes.toBytes("" + i + suffix))).thenAccept(r -> { suffixCount.addAndGet(//from w w w. j a v a2 s . c om Bytes.toString(r.getValue(FAMILY, QUALIFIER)).chars().filter(x -> x == suffix).count()); latch.countDown(); })); latch.await(); assertEquals((1 + count) * count / 2, suffixCount.get()); String value = Bytes .toString(table.get(new Get(row).addColumn(FAMILY, QUALIFIER)).get().getValue(FAMILY, QUALIFIER)); int[] actual = Arrays.asList(value.split("" + suffix)).stream().mapToInt(Integer::parseInt).sorted() .toArray(); assertArrayEquals(IntStream.range(0, count).toArray(), actual); }
From source file:org.apache.activemq.artemis.tests.integration.persistence.metrics.JournalPendingMessageTest.java
@Test public void testQueueMessageSizeAfterConsumptionNonPersistent() throws Exception { AtomicLong publishedMessageSize = new AtomicLong(); publishTestQueueMessages(200, DeliveryMode.NON_PERSISTENT, publishedMessageSize); verifyPendingStats(defaultQueueName, 200, publishedMessageSize.get()); consumeTestQueueMessages(200);/* www .j av a2 s. co m*/ verifyPendingStats(defaultQueueName, 0, 0); verifyPendingDurableStats(defaultQueueName, 0, 0); }
From source file:org.jsfr.json.JacksonParserTest.java
@Test public void testLargeJsonJackson() throws Exception { final AtomicLong counter = new AtomicLong(); ObjectMapper om = new ObjectMapper(); JsonFactory f = new JsonFactory(); JsonParser jp = f.createParser(read("allthethings.json")); long start = System.currentTimeMillis(); jp.nextToken();/* w w w . j a v a 2 s. c o m*/ jp.nextToken(); jp.nextToken(); while (jp.nextToken() == JsonToken.FIELD_NAME) { if (jp.nextToken() == JsonToken.START_OBJECT) { TreeNode tree = om.readTree(jp); counter.incrementAndGet(); LOGGER.trace("value: {}", tree); } } jp.close(); LOGGER.info("Jackson processes {} value in {} millisecond", counter.get(), System.currentTimeMillis() - start); }
From source file:org.apache.activemq.artemis.tests.integration.persistence.metrics.JournalPendingMessageTest.java
@Test public void testQueueBrowserMessageSize() throws Exception { AtomicLong publishedMessageSize = new AtomicLong(); publishTestQueueMessages(200, publishedMessageSize); browseTestQueueMessages(defaultQueueName); verifyPendingStats(defaultQueueName, 200, publishedMessageSize.get()); verifyPendingDurableStats(defaultQueueName, 200, publishedMessageSize.get()); }
From source file:it.polimi.diceH2020.SPACE4CloudWS.core.CoarseGrainedOptimizer.java
void hillClimbing(Solution solution) { logger.info(/* w w w. j a v a2 s . c om*/ String.format("---------- Starting hill climbing for instance %s ----------", solution.getId())); Technology technology = solverChecker.enforceSolverSettings(solution.getLstSolutions()); List<SolutionPerJob> lst = solution.getLstSolutions(); Stream<SolutionPerJob> strm = settings.isParallel() ? lst.parallelStream() : lst.stream(); AtomicLong executionTime = new AtomicLong(); boolean overallSuccess = strm.map(s -> { Instant first = Instant.now(); boolean success = hillClimbing(s, technology); Instant after = Instant.now(); executionTime.addAndGet(Duration.between(first, after).toMillis()); return success; }).reduce(true, Boolean::logicalAnd); if (!overallSuccess) stateHandler.sendEvent(Events.STOP); else { solution.setEvaluated(false); evaluator.evaluate(solution); Phase phase = new Phase(); phase.setId(PhaseID.OPTIMIZATION); phase.setDuration(executionTime.get()); solution.addPhase(phase); } }
From source file:org.apache.drill.exec.expr.fn.FunctionImplementationRegistry.java
private DrillFuncHolder findExactMatchingDrillFunction(String name, List<MajorType> argTypes, MajorType returnType, boolean retry) { AtomicLong version = new AtomicLong(); for (DrillFuncHolder h : localFunctionRegistry.getMethods(name, version)) { if (h.matches(returnType, argTypes)) { return h; }/*from www. j av a2s .c o m*/ } if (retry && optionManager != null && optionManager.getOption(ExecConstants.DYNAMIC_UDF_SUPPORT_ENABLED).bool_val) { if (loadRemoteFunctions(version.get())) { return findExactMatchingDrillFunction(name, argTypes, returnType, false); } } return null; }
From source file:com.github.brandtg.switchboard.LogPuller.java
@Override public void run() { HttpClient httpClient = HttpClients.createDefault(); AtomicLong currentIndex = new AtomicLong(lastIndex); HttpHost host = new HttpHost(sourceAddress.getAddress(), sourceAddress.getPort()); boolean firstLoop = true; while (!isShutdown.get()) { // Build URI StringBuilder sb = new StringBuilder(); try {// w w w . ja v a 2s .c o m if (firstLoop) { sb.append("/log/metadata/header?target=").append(sinkAddress.getHostName()).append(":") .append(sinkAddress.getPort()); firstLoop = false; } else { sb.append("/log/").append(URLEncoder.encode(collection, ENCODING)).append("/") .append(currentIndex.get()).append("?target=").append(sinkAddress.getHostName()) .append(":").append(sinkAddress.getPort()); } } catch (Exception e) { throw new RuntimeException(e); } // TODO: Clean this up a little bit int resStatus = -1; synchronized (this) { HttpEntity entity = null; try { // Get data URI uri = URI.create(sb.toString()); HttpGet req = new HttpGet(uri); HttpResponse res = httpClient.execute(host, req); entity = res.getEntity(); resStatus = res.getStatusLine().getStatusCode(); if (resStatus == 200) { // Wait for data to be consumed // n.b. This object will be registered as a listener wait(); // Update position InputStream inputStream = res.getEntity().getContent(); LogRegionResponse metadata = OBJECT_MAPPER.readValue(inputStream, LogRegionResponse.class); currentIndex .set(metadata.getLogRegions().get(metadata.getLogRegions().size() - 1).getIndex()); for (LogRegion logRegion : metadata.getLogRegions()) { LOG.info("Received {}", logRegion); } } } catch (Exception e) { LOG.error("Error", e); } finally { if (entity != null) { try { EntityUtils.consume(entity); } catch (IOException e) { LOG.error("Error", e); } } } } // Sleep if did not get data if (resStatus != 200) { try { LOG.debug("No data available, sleeping 1000 ms"); Thread.sleep(1000); } catch (InterruptedException e) { LOG.warn("Error while sleeping for more data", e); } } } }
From source file:com.alibaba.napoli.metamorphosis.client.extension.producer.LocalMessageStorageManager.java
/** * ????,?(???????)/*from ww w . j a v a 2s.c o m*/ * * @param topic * @param partition * @param recoverer * ????? * @return ????? * */ @Override public boolean recover(final String topic, final Partition partition, final MessageRecoverer recoverer) { final String name = this.generateKey(topic, partition); final FutureTask<Boolean> recoverTask = new FutureTask<Boolean>(new Callable<Boolean>() { @Override public Boolean call() throws Exception { final AtomicLong count = new AtomicLong(0); try { final Store store = LocalMessageStorageManager.this.getOrCreateStore(topic, partition); this.innerRecover(store, recoverer, count, name); } catch (final Throwable e) { log.error("SendRecover?????,name=" + name, e); } finally { log.info("SendRecover????,name=" + name + ",???" + count.get() + "?"); LocalMessageStorageManager.this.topicRecoverTaskMap.remove(name); } return true; } private void innerRecover(final Store store, final MessageRecoverer recoverer, final AtomicLong count, final String name) throws IOException, Exception { final Iterator<byte[]> it = store.iterator(); while (it.hasNext()) { final byte[] key = it.next(); final Message msg = (Message) LocalMessageStorageManager.this.deserializer .decodeObject(store.get(key)); recoverer.handle(msg); try { store.remove(key); count.incrementAndGet(); if (count.get() % 20000 == 0) { log.info("SendRecover " + name + "????:" + count.get()); } } catch (final IOException e) { log.error("SendRecover remove message failed", e); } } } }); final FutureTask<Boolean> ret = this.topicRecoverTaskMap.putIfAbsent(name, recoverTask); if (ret == null) { this.threadPoolExecutor.submit(recoverTask); return true; } else { if (log.isDebugEnabled()) { log.debug("SendRecover?????,????,name=" + name); } return false; } }
From source file:org.apache.drill.exec.expr.fn.FunctionImplementationRegistry.java
private DrillFuncHolder findDrillFunction(FunctionResolver functionResolver, FunctionCall functionCall, boolean retry) { AtomicLong version = new AtomicLong(); DrillFuncHolder holder = functionResolver.getBestMatch( localFunctionRegistry.getMethods(functionReplacement(functionCall), version), functionCall); if (holder == null && retry) { if (optionManager != null && optionManager.getOption(ExecConstants.DYNAMIC_UDF_SUPPORT_ENABLED).bool_val) { if (loadRemoteFunctions(version.get())) { return findDrillFunction(functionResolver, functionCall, false); }//from w w w .j a v a 2 s.c o m } } return holder; }