List of usage examples for java.util.concurrent.atomic AtomicInteger get
public final int get()
From source file:Main.java
public static int ThrsafeIncrementSizeUpToLimit(AtomicInteger storagePointer, int limitValue) { // size_t resultValue; // while (true) { // resultValue = *storagePointer; // if (resultValue == limitValue) { // break; // } // if (ThrsafeCompareExchangePointer((volatile atomicptr *)storagePointer, (atomicptr)resultValue, (atomicptr)(resultValue + 1))) { // break; // } // }//from w ww . j a v a2 s. c om // return resultValue; int resultValue; while (true) { resultValue = storagePointer.get(); if (resultValue == limitValue) { break; } //if (ThrsafeCompareExchangePointer((volatile atomicptr *)storagePointer, (atomicptr)resultValue, (atomicptr)(resultValue + 1))) { //TODO (TZ) //System.out.println("Is this right? Using Int instead of Pointer?"); if (ThrsafeCompareExchange(storagePointer, resultValue, (resultValue + 1))) { break; } } return resultValue; }
From source file:com.raphfrk.craftproxyclient.gui.GUIManager.java
public static JSONObject getPreviousLoginDetails() { JSONObject loginInfo = AuthManager.refreshAccessToken(); if (loginInfo == null) { return null; }/* w w w .j a v a2 s . c o m*/ final AtomicInteger option = new AtomicInteger(); Runnable r = new Runnable() { public void run() { option.set(JOptionPane.showConfirmDialog(CraftProxyClient.getGUI(), "Login as " + AuthManager.getUsername() + "?", "Login", JOptionPane.YES_NO_OPTION)); } }; if (SwingUtilities.isEventDispatchThread()) { r.run(); } else { try { SwingUtilities.invokeAndWait(r); } catch (InvocationTargetException | InterruptedException e) { return null; } } if (option.get() == 0) { return loginInfo; } else { return null; } }
From source file:org.talend.dataprep.command.CommandHelper.java
/** * Return a Publisher of type T out of the the hystrix command. * * @param clazz the wanted stream type.//from w ww .j ava2 s .c o m * @param mapper the object mapper used to parse objects. * @param command the hystrix command to deal with. * @param <T> the type of objects to stream. * @return a Publisher<T></T> out of the hystrix command response body. */ public static <T> Publisher<T> toPublisher(final Class<T> clazz, final ObjectMapper mapper, final HystrixCommand<InputStream> command) { AtomicInteger count = new AtomicInteger(0); return Flux.create(sink -> { final Observable<InputStream> observable = command.toObservable(); observable.map(i -> { try { return mapper.readerFor(clazz).<T>readValues(i); } catch (IOException e) { throw new TDPException(CommonErrorCodes.UNEXPECTED_EXCEPTION, e); } }) // .doOnCompleted(() -> LOGGER.debug("Completed command '{}' (emits '{}') with '{}' records.", command.getClass().getName(), clazz.getName(), count.get())) // .toBlocking() // .forEach(s -> { while (s.hasNext()) { sink.next(s.next()); count.incrementAndGet(); } sink.complete(); }); }, FluxSink.OverflowStrategy.BUFFER); }
From source file:edu.umd.umiacs.clip.tools.math.StatisticalTests.java
private static Triple<Double, Double, Double> pRecPrecF1(int pos, int tpboth, int tp0only, int tp1only, int fpboth, int fp0only, int fp1only) { double delta_f1 = Math.abs(f1(tp0only + tpboth, fp0only + fpboth, pos - (tp0only + tpboth)) - f1(tp1only + tpboth, fp1only + fpboth, pos - (tp1only + tpboth))); double delta_rec = Math.abs( rec(tp0only + tpboth, pos - (tp0only + tpboth)) - rec(tp1only + tpboth, pos - (tp1only + tpboth))); double delta_prec = Math .abs(prec(tp0only + tpboth, fp0only + fpboth) - prec(tp1only + tpboth, fp1only + fpboth)); AtomicInteger nc_f1 = new AtomicInteger(); AtomicInteger nc_rec = new AtomicInteger(); AtomicInteger nc_prec = new AtomicInteger(); range(0, NT).forEach(j -> {/*from w ww. j a v a2s .c o m*/ int tp[] = nextPair(tp0only, tp1only, tpboth); int fp[] = nextPair(fp0only, fp1only, fpboth); if (Math.abs(f1(tp[0], fp[0], pos - tp[0]) - f1(tp[1], fp[1], pos - tp[1])) > delta_f1) { nc_f1.incrementAndGet(); } if (Math.abs(rec(tp[0], pos - tp[0]) - rec(tp[1], pos - tp[1])) > delta_rec) { nc_rec.incrementAndGet(); } if (Math.abs(prec(tp[0], fp[0]) - prec(tp[1], fp[1])) > delta_prec) { nc_prec.incrementAndGet(); } }); return Triple.of((nc_rec.get() + 1.) / (NT + 1), (nc_prec.get() + 1.) / (NT + 1), (nc_f1.get() + 1.) / (NT + 1)); }
From source file:fr.landel.utils.assertor.utils.AssertorIterable.java
private static <I extends Iterable<T>, T> boolean hasInOrder(final I iterable1, final Iterable<T> iterable2, final boolean not, final EnumAnalysisMode analysisMode) { long found = 0; final int size1 = IterableUtils.size(iterable1); final int size2 = IterableUtils.size(iterable2); if (size1 < size2) { return not; } else if (size1 == size2) { return not ^ iterable1.equals(iterable2); }/*from www . j a v a 2s . c om*/ if (EnumAnalysisMode.STANDARD.equals(analysisMode)) { final Iterator<T> iterator1 = iterable1.iterator(); Iterator<T> iterator2 = iterable2.iterator(); // not empty pre-check, so we call next directly T value2 = iterator2.next(); while (iterator1.hasNext() && found < size2) { if (Objects.equals(iterator1.next(), value2)) { ++found; if (iterator2.hasNext()) { value2 = iterator2.next(); } } else if (found > 0) { found = 0; iterator2 = iterable2.iterator(); value2 = iterator2.next(); } } } else { final AtomicInteger count = new AtomicInteger(0); final List<T> list2 = IterableUtils.toList(iterable2); StreamSupport.stream(iterable1.spliterator(), EnumAnalysisMode.PARALLEL.equals(analysisMode)) .forEachOrdered(o -> { int inc = count.get(); if (inc < size2) { if (Objects.equals(o, list2.get(inc))) { count.incrementAndGet(); } else if (inc > 0) { count.set(0); } } }); found = count.get(); } return not ^ (found == size2); }
From source file:io.apiman.gateway.engine.vertx.polling.URILoadingRegistry.java
public static void reloadData(IAsyncHandler<Void> doneHandler) { synchronized (URILoadingRegistry.class) { if (instance == null) { doneHandler.handle((Void) null); return; }//from w w w. java 2 s . com Map<URILoadingRegistry, IAsyncResultHandler<Void>> regs = instance.handlers; Vertx vertx = instance.vertx; URI uri = instance.uri; Map<String, String> config = instance.config; AtomicInteger ctr = new AtomicInteger(regs.size()); OneShotURILoader newLoader = new OneShotURILoader(vertx, uri, config); regs.entrySet().stream().forEach(pair -> { // Clear the registrys' internal maps to prepare for reload. // NB: If we add production hot reloading, we'll need to work around this (e.g. clone?). pair.getKey().getMap().clear(); // Re-subscribe the registry. newLoader.subscribe(pair.getKey(), result -> { checkAndFlip(ctr.decrementAndGet(), newLoader, doneHandler); }); }); checkAndFlip(ctr.get(), newLoader, doneHandler); } }
From source file:ai.grakn.graql.GraqlShell.java
private static void sendBatchRequest(BatchMutatorClient batchMutatorClient, String graqlPath, Optional<Integer> activeTasks, Optional<Integer> batchSize) throws IOException { AtomicInteger numberBatchesCompleted = new AtomicInteger(0); activeTasks.ifPresent(batchMutatorClient::setNumberActiveTasks); batchSize.ifPresent(batchMutatorClient::setBatchSize); batchMutatorClient.setTaskCompletionConsumer((json) -> { TaskStatus status = TaskStatus.valueOf(json.at("status").asString()); numberBatchesCompleted.incrementAndGet(); System.out.println(format("Status of batch: %s", status)); System.out.println(format("Number batches completed: %s", numberBatchesCompleted.get())); System.out.println(format("Approximate queries executed: %s", numberBatchesCompleted.get() * batchMutatorClient.getBatchSize())); });/*from ww w . ja v a 2 s . co m*/ String queries = loadQuery(graqlPath); Graql.parseList(queries).forEach(batchMutatorClient::add); batchMutatorClient.waitToFinish(); }
From source file:com.epam.reportportal.auth.event.UiAuthenticationFailureEventHandler.java
public boolean isBlocked(HttpServletRequest request) { AtomicInteger attempts = failures.getIfPresent(getClientIP(request)); return null != attempts && attempts.get() > MAX_ATTEMPTS; }
From source file:org.apache.camel.impl.DefaultInflightRepository.java
public int size(Endpoint endpoint) { AtomicInteger answer = endpointCount.get(endpoint.getEndpointKey()); return answer != null ? answer.get() : 0; }
From source file:net.sourceforge.pmd.PMD.java
/** * This method is the main entry point for command line usage. * * @param configuration//from ww w . j av a 2s . c om * the configure to use * @return number of violations found. */ public static int doPMD(PMDConfiguration configuration) { // Load the RuleSets RuleSetFactory ruleSetFactory = RulesetsFactoryUtils.getRulesetFactory(configuration); RuleSets ruleSets = RulesetsFactoryUtils.getRuleSetsWithBenchmark(configuration.getRuleSets(), ruleSetFactory); if (ruleSets == null) { return 0; } Set<Language> languages = getApplicableLanguages(configuration, ruleSets); List<DataSource> files = getApplicableFiles(configuration, languages); long reportStart = System.nanoTime(); try { Renderer renderer = configuration.createRenderer(); List<Renderer> renderers = Collections.singletonList(renderer); renderer.setWriter(IOUtil.createWriter(configuration.getReportFile())); renderer.start(); Benchmarker.mark(Benchmark.Reporting, System.nanoTime() - reportStart, 0); RuleContext ctx = new RuleContext(); final AtomicInteger violations = new AtomicInteger(0); ctx.getReport().addListener(new ReportListener() { @Override public void ruleViolationAdded(RuleViolation ruleViolation) { violations.incrementAndGet(); } @Override public void metricAdded(Metric metric) { } }); processFiles(configuration, ruleSetFactory, files, ctx, renderers); reportStart = System.nanoTime(); renderer.end(); renderer.flush(); return violations.get(); } catch (Exception e) { String message = e.getMessage(); if (message != null) { LOG.severe(message); } else { LOG.log(Level.SEVERE, "Exception during processing", e); } LOG.log(Level.FINE, "Exception during processing", e); LOG.info(PMDCommandLineInterface.buildUsageText()); return 0; } finally { Benchmarker.mark(Benchmark.Reporting, System.nanoTime() - reportStart, 0); } }