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

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

Introduction

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

Prototype

public AtomicInteger(int initialValue) 

Source Link

Document

Creates a new AtomicInteger with the given initial value.

Usage

From source file:cc.gospy.example.google.GoogleSpider.java

public Collection<String> getResultLinks(final String keyword, final int pageFrom, final int pageTo) {
    if (pageFrom < 1)
        throw new IllegalArgumentException(pageFrom + "<" + 1);
    if (pageFrom >= pageTo)
        throw new IllegalArgumentException(pageFrom + ">=" + pageTo);

    final AtomicInteger currentPage = new AtomicInteger(pageFrom);
    final AtomicBoolean returned = new AtomicBoolean(false);
    final Collection<String> links = new LinkedHashSet<>();
    Gospy googleSpider = Gospy.custom()//w w w  .  j a  v a 2s .  c  o m
            .setScheduler(
                    Schedulers.VerifiableScheduler.custom().setExitCallback(() -> returned.set(true)).build())
            .addFetcher(Fetchers.HttpFetcher.custom()
                    .before(request -> request.setConfig(
                            RequestConfig.custom().setProxy(new HttpHost("127.0.0.1", 8118)).build()))
                    .build())
            .addProcessor(Processors.XPathProcessor.custom()
                    .extract("//*[@id='ires']/ol/div/h3/a/@href", (task, resultList, returnedData) -> {
                        resultList.forEach(a -> {
                            if (a.startsWith("/url?q=")) {
                                String link = a.substring(7);
                                int end = link.indexOf("&sa=");
                                links.add(link.substring(0, end != -1 ? end : link.length()));
                            }
                        });
                        currentPage.incrementAndGet();
                        if (pageFrom <= currentPage.get() && currentPage.get() < pageTo) {
                            return Arrays.asList(
                                    new Task(String.format("http://www.google.com/search?q=%s&start=%d&*",
                                            keyword, (currentPage.get() - 1) * 10)));
                        } else {
                            return Arrays.asList();
                        }
                    }).build())
            .build().addTask(String.format("http://www.google.com/search?q=%s&start=%d&*", keyword, pageFrom));
    googleSpider.start();
    while (!returned.get())
        ; // block until spider returned
    googleSpider.stop();
    return links;
}

From source file:lockstep.ClientReceivingQueue.java

/**
* Constructor.// ww  w  .j  a  va  2  s .com
* 
* @param initialFrameNumber First frame's number. Must be the same for all 
* the hosts using the protocol
* 
* @param senderID ID of the client whose frames are collected in this queue
* 
* @param clientExecutionSemaphore semaphore used by to signal the client of
* the availability of the next frame input. The client awaits that all the 
* queues are ready before collecting the next frame inputs
*/
public ClientReceivingQueue(int initialFrameNumber, int senderID, Semaphore clientExecutionSemaphore) {
    this.senderID = senderID;

    this.nextFrame = new AtomicInteger(initialFrameNumber);
    this.commandBuffer = new ConcurrentSkipListMap<>();
    this.executionSemaphore = clientExecutionSemaphore;

    this.lastInOrderACK = new AtomicInteger(initialFrameNumber - 1);
    this.selectiveACKsSet = new ConcurrentSkipListSet<>();
}

From source file:cc.gospy.example.google.GoogleScholarSpider.java

public Collection<String> getResultLinks(final String keyword, final int pageFrom, final int pageTo) {
    if (pageFrom < 1)
        throw new IllegalArgumentException(pageFrom + "<" + 1);
    if (pageFrom >= pageTo)
        throw new IllegalArgumentException(pageFrom + ">=" + pageTo);

    final AtomicInteger currentPage = new AtomicInteger(pageFrom);
    final AtomicBoolean returned = new AtomicBoolean(false);
    final Collection<String> links = new LinkedHashSet<>();
    Gospy googleScholarSpider = Gospy.custom()
            .setScheduler(/*from  www .  j a  v a  2 s  . c  o m*/
                    Schedulers.VerifiableScheduler.custom().setExitCallback(() -> returned.set(true)).build())
            .addFetcher(Fetchers.HttpFetcher.custom()
                    .before(request -> request.setConfig(
                            RequestConfig.custom().setProxy(new HttpHost("127.0.0.1", 8118)).build()))
                    .build())
            .addProcessor(Processors.XPathProcessor.custom().extract(
                    "//*[@id='gs_ccl_results']/div/div/h3/a/@href", (task, resultList, returnedData) -> {
                        links.addAll(resultList);
                        currentPage.incrementAndGet();
                        if (pageFrom <= currentPage.get() && currentPage.get() < pageTo) {
                            return Arrays.asList(
                                    new Task(String.format("https://scholar.google.com/scholar?start=%d&q=%s",
                                            (currentPage.get() - 1) * 10, keyword)));
                        } else {
                            return Arrays.asList();
                        }
                    }).build())
            .build()
            .addTask(String.format("https://scholar.google.com/scholar?start=%d&q=%s", pageFrom, keyword));
    googleScholarSpider.start();
    while (!returned.get())
        ; // block until spider returned
    googleScholarSpider.stop();
    return links;
}

From source file:com.consol.citrus.samples.bakery.service.ReportService.java

/**
 * Adds new produced item.//from   ww  w . j a  v  a  2  s.c om
 * @param id
 * @param name
 * @param amount
 */
public void add(String id, String name, Integer amount) throws Exception {
    produced.add(id);

    if (report.containsKey(name)) {
        report.get(name).addAndGet(amount);
    } else {
        report.put(name, new AtomicInteger(amount));
    }

    if (report.get(name).get() >= 1000) {
        informStakeholders(name);
    }
}

From source file:com.kakao.KakaoTalkLinkMessageBuilder.java

KakaoTalkLinkMessageBuilder(final String appKey, final String appVer) {
    this.appKey = appKey;
    this.appVer = appVer;

    this.textType = new AtomicInteger(0);
    this.imageType = new AtomicInteger(0);
    this.buttonType = new AtomicInteger(0);
    this.linkType = new AtomicInteger(0);

    this.linkObjList = new ArrayList<LinkObject>();
}

From source file:net.sf.sessionAnalysis.SessionVisitorSessionLengthNanosStatistics.java

public void handleSession(Session session) {
    final long curLength = session.getSessionLengthNanos();
    AtomicInteger curFrequency = sessionLengthHistogram.get(curLength);
    if (curFrequency == null) { // session length not observed before
        curFrequency = new AtomicInteger(0);
        sessionLengthHistogram.put(curLength, curFrequency);
    }//from   w  w  w.j  a va2s  . c o m
    curFrequency.incrementAndGet();
}

From source file:strat.mining.multipool.stats.service.impl.RequestStatsLoggingServiceImpl.java

public RequestStatsLoggingServiceImpl() {
    nbCurrencyTicker = new AtomicInteger(0);
    nbDonnation = new AtomicInteger(0);
    nbBlockchainDetails = new AtomicInteger(0);
    nbAllExchangePlace = new AtomicInteger(0);

    currencyTickerRequest = Collections.synchronizedMap(new HashMap<String, Map<String, AtomicInteger>>());
    donatorsRequests = Collections.synchronizedMap(new HashMap<String, AtomicInteger>());
}

From source file:io.watchcat.node.monitoring.threshold.DiskThresholds.java

public DiskThresholds() {
    minorThreshold = new AtomicInteger(DEFAULT_MINOR_THRESHOLD);
    majorThreshold = new AtomicInteger(DEFAULT_MAJOR_THRESHOLD);
    criticalThreshold = new AtomicInteger(DEFAULT_CRITICAL_THRESHOLD);
}

From source file:eu.stratosphere.nephele.io.channels.LocalChannelWithAccessInfo.java

LocalChannelWithAccessInfo(final File file, final boolean deleteOnClose) throws IOException {

    this.file = file;
    this.channel = new RandomAccessFile(file, "rw").getChannel();
    this.reservedWritePosition = new AtomicLong(0L);
    this.referenceCounter = new AtomicInteger(0);
    this.deleteOnClose = new AtomicBoolean(deleteOnClose);
}

From source file:strat.mining.multipool.stats.service.impl.middlecoin.RequestStatsLoggingServiceImpl.java

public RequestStatsLoggingServiceImpl() {
    nbAllGlobal = new AtomicInteger(0);
    nbLastGlobal = new AtomicInteger(0);
    nbAllAddress = new AtomicInteger(0);
    nbLastAddress = new AtomicInteger(0);
    nbPaidout = new AtomicInteger(0);
    nbSuggestion = new AtomicInteger(0);

    uniqueAddressesAllStats = Collections.synchronizedSet(new HashSet<String>());
    uniqueAddressesLastStats = Collections.synchronizedSet(new HashSet<String>());
    uniqueAddressesPaidout = Collections.synchronizedSet(new HashSet<String>());
}