Example usage for java.util.concurrent.atomic AtomicInteger getAndIncrement

List of usage examples for java.util.concurrent.atomic AtomicInteger getAndIncrement

Introduction

In this page you can find the example usage for java.util.concurrent.atomic AtomicInteger getAndIncrement.

Prototype

public final int getAndIncrement() 

Source Link

Document

Atomically increments the current value, with memory effects as specified by VarHandle#getAndAdd .

Usage

From source file:com.gsinnovations.howdah.AbstractJob.java

protected static boolean shouldRunNextPhase(Map<String, String> args, AtomicInteger currentPhase) {
    int phase = currentPhase.getAndIncrement();
    String startPhase = args.get("--startPhase");
    String endPhase = args.get("--endPhase");
    boolean phaseSkipped = (startPhase != null && phase < Integer.parseInt(startPhase))
            || (endPhase != null && phase > Integer.parseInt(endPhase));
    if (phaseSkipped) {
        log.info("Skipping phase {}", phase);
    }//w  w  w.  j  a  v  a 2s.  co  m
    return !phaseSkipped;
}

From source file:yaphyre.app.YaPhyRe.java

private static void saveImages(Scene scene, double gamma) {
    final AtomicInteger cameraIndex = new AtomicInteger(0);

    scene.getCameras().stream().map(Camera::getFilm)
            .filter(film -> ImageFile.class.isAssignableFrom(film.getClass())).map(ImageFile.class::cast)
            .forEach(imageFileFilm -> saveFilmToFile(gamma, cameraIndex.getAndIncrement(), imageFileFilm,
                    ImageFile.ImageFormat.PNG));
}

From source file:org.niord.core.geojson.GeoJsonUtils.java

/** Returns the n'th coordinate **/
public static double[] computeCoordinate(GeoJsonVo g, int n) {
    // Note to self: This can be implemented much more efficiently
    AtomicInteger cnt = new AtomicInteger(0);
    double[][] resultHolder = new double[1][];
    g.visitCoordinates(xy -> {/*from www.jav a  2s .  c o  m*/
        if (cnt.getAndIncrement() == n) {
            resultHolder[0] = xy;
        }
    });
    return resultHolder[0];
}

From source file:org.niord.core.geojson.GeoJsonUtils.java

/** Serializes the geometry coordinates */
private static <T> void serializeCoordinates(T coords, IncludeCoord incl, SerializedFeature sf,
        Map<String, Object> properties, String language, AtomicInteger index) {
    if (coords != null) {
        if (coords instanceof double[]) {
            if (((double[]) coords).length >= 2) {
                int coordIndex = index.getAndIncrement();
                if (incl == IncludeCoord.ALL) {
                    SerializedCoordinates sc = new SerializedCoordinates();
                    sc.setCoordinates((double[]) coords);
                    sc.setName(FeatureName.getFeatureCoordinateName(properties, language, coordIndex));
                    sf.getCoordinates().add(sc);
                }//from  w ww  .ja  v  a2 s .  c o  m
            }
        } else if (coords instanceof double[][]) {
            double[][] coordSet = (double[][]) coords;
            for (int c = 0; c < coordSet.length; c++) {
                IncludeCoord inclCoord = incl == IncludeCoord.ALL_BUT_LAST
                        ? (c == coordSet.length - 1 ? IncludeCoord.NONE : IncludeCoord.ALL)
                        : incl;
                serializeCoordinates(coordSet[c], inclCoord, sf, properties, language, index);
            }
        } else if (coords instanceof double[][][]) {
            for (double[][] c : (double[][][]) coords) {
                serializeCoordinates(c, incl, sf, properties, language, index);
            }
        } else if (coords instanceof double[][][][]) {
            for (double[][][] c : (double[][][][]) coords) {
                serializeCoordinates(c, incl, sf, properties, language, index);
            }
        }
    }
}

From source file:com.cloudera.oryx.app.serving.als.model.LoadTestALSModelFactory.java

public static ALSServingModel buildTestModel() {

    log.info("Building load test model...");

    System.gc();// www  .j a  v a 2s .  c  om
    long startMemory = JVMUtils.getUsedMemory();

    ALSServingModel model = new ALSServingModel(FEATURES, true, LSH_SAMPLE_RATE, new TestALSRescorerProvider());
    AtomicLong totalEntries = new AtomicLong();

    int numCores = Runtime.getRuntime().availableProcessors();
    log.info("Adding {} users", USERS);
    AtomicInteger userCount = new AtomicInteger();
    ExecUtils.doInParallel(numCores, i -> {
        RandomGenerator random = RandomManager.getRandom(((long) i << 32) ^ System.nanoTime());
        PoissonDistribution itemPerUserDist = new PoissonDistribution(random, AVG_ITEMS_PER_USER,
                PoissonDistribution.DEFAULT_EPSILON, PoissonDistribution.DEFAULT_MAX_ITERATIONS);
        for (int user = userCount.getAndIncrement(); user < USERS; user = userCount.getAndIncrement()) {
            String userID = "U" + user;
            model.setUserVector(userID, VectorMath.randomVectorF(FEATURES, random));
            int itemsPerUser = itemPerUserDist.sample();
            totalEntries.addAndGet(itemsPerUser);
            Collection<String> knownIDs = new ArrayList<>(itemsPerUser);
            for (int item = 0; item < itemsPerUser; item++) {
                knownIDs.add("I" + random.nextInt(ITEMS));
            }
            model.addKnownItems(userID, knownIDs);
        }
    });

    log.info("Adding {} items", ITEMS);
    AtomicInteger itemCount = new AtomicInteger();
    ExecUtils.doInParallel(numCores, i -> {
        RandomGenerator random = RandomManager.getRandom(((long) i << 32) ^ System.nanoTime());
        for (int item = itemCount.getAndIncrement(); item < ITEMS; item = itemCount.getAndIncrement()) {
            model.setItemVector("I" + item, VectorMath.randomVectorF(FEATURES, random));
        }
    });

    System.gc();
    long endMemory = JVMUtils.getUsedMemory();

    log.info("Built model over {} users, {} items, {} features, {} entries, using {}MB", USERS, ITEMS, FEATURES,
            totalEntries, (endMemory - startMemory) / 1_000_000);
    log.info("Model: {}", model);
    return model;
}

From source file:io.uploader.drive.drive.DriveOperations.java

private static void dealWithException(Throwable e, AtomicInteger counter) throws Throwable {
    if (isRetryable(e)) {
        if (counter.getAndIncrement() >= maxNumberOfRetry) {
            throw e;
        }//from   w  w  w .jav a2  s. c  o m
        logger.info(String.format("Error: %s", e.toString()));
    } else
        throw e;
}

From source file:my.mahout.AbstractJob.java

protected static boolean shouldRunNextPhase(Map<String, List<String>> args, AtomicInteger currentPhase) {
    int phase = currentPhase.getAndIncrement();
    String startPhase = getOption(args, "--startPhase");
    String endPhase = getOption(args, "--endPhase");
    boolean phaseSkipped = (startPhase != null && phase < Integer.parseInt(startPhase))
            || (endPhase != null && phase > Integer.parseInt(endPhase));
    if (phaseSkipped) {
        log.info("Skipping phase {}", phase);
    }//w ww  . j a  v a2s  .  c o  m
    return !phaseSkipped;
}

From source file:org.onosproject.drivers.fujitsu.FujitsuT100DeviceDescription.java

/**
 * Parses a configuration and returns a set of ports for the fujitsu T100.
 *
 * @param cfg a hierarchical configuration
 * @return a list of port descriptions/*from   w w w. j ava 2 s  .  c o m*/
 */
private static List<PortDescription> parseFujitsuT100Ports(HierarchicalConfiguration cfg) {
    AtomicInteger counter = new AtomicInteger(1);
    List<PortDescription> portDescriptions = Lists.newArrayList();
    List<HierarchicalConfiguration> subtrees = cfg.configurationsAt("data.interfaces.interface");
    for (HierarchicalConfiguration portConfig : subtrees) {
        if (!portConfig.getString("name").contains("LCN") && !portConfig.getString("name").contains("LMP")
                && portConfig.getString("type").equals("ianaift:ethernetCsmacd")) {
            portDescriptions.add(parseT100OduPort(portConfig, counter.getAndIncrement()));
        } else if (portConfig.getString("type").equals("ianaift:otnOtu")) {
            portDescriptions.add(parseT100OchPort(portConfig, counter.getAndIncrement()));
        }
    }
    return portDescriptions;
}

From source file:org.opencloudengine.flamingo.mapreduce.core.AbstractJob.java

/**
 *  ? Job?   ? Phase?   .//from  www . jav a2s  .c  o m
 *
 * @param args         Key Value ? 
 * @param currentPhase Phase
 * @return ?   . ?    <tt>true</tt> .
 */
protected static boolean shouldRunNextPhase(Map<String, String> args, AtomicInteger currentPhase) {
    int phase = currentPhase.getAndIncrement();
    String startPhase = args.get("--startPhase");
    String endPhase = args.get("--endPhase");
    boolean phaseSkipped = (startPhase != null && phase < Integer.parseInt(startPhase))
            || (endPhase != null && phase > Integer.parseInt(endPhase));
    if (phaseSkipped) {
        log.info("Skipping phase {}", phase);
    }
    return !phaseSkipped;
}

From source file:org.semanticweb.owlapi.io.RDFTriple.java

static TObjectIntHashMap<IRI> initMap() {
    TObjectIntHashMap<IRI> predicates = new TObjectIntHashMap<>();
    AtomicInteger nextId = new AtomicInteger(1);
    List<OWLRDFVocabulary> ORDERED_URIS = Arrays.asList(RDF_TYPE, RDFS_LABEL, OWL_DEPRECATED, RDFS_COMMENT,
            RDFS_IS_DEFINED_BY, RDF_FIRST, RDF_REST, OWL_EQUIVALENT_CLASS, OWL_EQUIVALENT_PROPERTY,
            RDFS_SUBCLASS_OF, RDFS_SUB_PROPERTY_OF, RDFS_DOMAIN, RDFS_RANGE, OWL_DISJOINT_WITH, OWL_ON_PROPERTY,
            OWL_DATA_RANGE, OWL_ON_CLASS, OWL_ANNOTATED_SOURCE, OWL_ANNOTATED_PROPERTY, OWL_ANNOTATED_TARGET);
    ORDERED_URIS.forEach(iri -> predicates.put(iri.getIRI(), nextId.getAndIncrement()));
    Stream.of(OWLRDFVocabulary.values())
            .forEach(iri -> predicates.putIfAbsent(iri.getIRI(), nextId.getAndIncrement()));
    return predicates;
}