Example usage for java.util.concurrent ConcurrentSkipListSet size

List of usage examples for java.util.concurrent ConcurrentSkipListSet size

Introduction

In this page you can find the example usage for java.util.concurrent ConcurrentSkipListSet size.

Prototype

public int size() 

Source Link

Document

Returns the number of elements in this set.

Usage

From source file:cn.wanghaomiao.seimi.def.DefaultLocalQueue.java

@Override
public long totalCrawled(String crawlerName) {
    ConcurrentSkipListSet<String> set = getProcessedSet(crawlerName);
    return set.size();
}

From source file:com.houghtonassociates.bamboo.plugins.dao.GerritService.java

public Set<GerritChangeVO> getLastUnverifiedChanges() throws RepositoryException {
    log.debug("getLastUnverifiedChange()...");

    Set<GerritChangeVO> changes = getGerritChangeInfo();

    ConcurrentSkipListSet<GerritChangeVO> filtedChanges = new ConcurrentSkipListSet<GerritChangeVO>(
            new SortByUnVerifiedLastUpdate());
    filtedChanges.addAll(changes);/*from  w  w w  . j a  v  a 2  s.com*/

    if ((filtedChanges.size() > 0)) {
        for (GerritChangeVO c : filtedChanges) {
            if (c.getVerificationScore() > 0) {
                filtedChanges.remove(c);
            }
        }
    }

    return filtedChanges;
}

From source file:org.apache.hadoop.hbase.procedure2.TestProcedureSchedulerConcurrency.java

private void testConcurrentWaitWake(final boolean useWakeBatch) throws Exception {
    final int WAIT_THRESHOLD = 2500;
    final int NPROCS = 20;
    final int NRUNS = 500;

    final ProcedureScheduler sched = procSched;
    for (long i = 0; i < NPROCS; ++i) {
        sched.addBack(new TestProcedureWithEvent(i));
    }/*  w ww.  ja v  a  2 s. co  m*/

    final Thread[] threads = new Thread[4];
    final AtomicInteger waitCount = new AtomicInteger(0);
    final AtomicInteger wakeCount = new AtomicInteger(0);

    final ConcurrentSkipListSet<TestProcedureWithEvent> waitQueue = new ConcurrentSkipListSet<TestProcedureWithEvent>();
    threads[0] = new Thread() {
        @Override
        public void run() {
            long lastUpdate = 0;
            while (true) {
                final int oldWakeCount = wakeCount.get();
                if (useWakeBatch) {
                    ProcedureEvent[] ev = new ProcedureEvent[waitQueue.size()];
                    for (int i = 0; i < ev.length; ++i) {
                        ev[i] = waitQueue.pollFirst().getEvent();
                        LOG.debug("WAKE BATCH " + ev[i] + " total=" + wakeCount.get());
                    }
                    sched.wakeEvents(ev.length, ev);
                    wakeCount.addAndGet(ev.length);
                } else {
                    int size = waitQueue.size();
                    while (size-- > 0) {
                        ProcedureEvent ev = waitQueue.pollFirst().getEvent();
                        sched.wakeEvent(ev);
                        LOG.debug("WAKE " + ev + " total=" + wakeCount.get());
                        wakeCount.incrementAndGet();
                    }
                }
                if (wakeCount.get() != oldWakeCount) {
                    lastUpdate = System.currentTimeMillis();
                } else if (wakeCount.get() >= NRUNS
                        && (System.currentTimeMillis() - lastUpdate) > WAIT_THRESHOLD) {
                    break;
                }
                Threads.sleepWithoutInterrupt(25);
            }
        }
    };

    for (int i = 1; i < threads.length; ++i) {
        threads[i] = new Thread() {
            @Override
            public void run() {
                while (true) {
                    TestProcedureWithEvent proc = (TestProcedureWithEvent) sched.poll();
                    if (proc == null)
                        continue;

                    sched.suspendEvent(proc.getEvent());
                    waitQueue.add(proc);
                    sched.waitEvent(proc.getEvent(), proc);
                    LOG.debug("WAIT " + proc.getEvent());
                    if (waitCount.incrementAndGet() >= NRUNS) {
                        break;
                    }
                }
            }
        };
    }

    for (int i = 0; i < threads.length; ++i) {
        threads[i].start();
    }
    for (int i = 0; i < threads.length; ++i) {
        threads[i].join();
    }

    sched.clear();
}

From source file:org.sindice.siren.index.Utils.java

/**
 * Flatten a list of triples to n-tuples containing many objects for the same
 * predicate. Generate one n-tuple per predicate.
 * //www  .  j a  v a 2  s .  c  o  m
 * @param values
 *          The list of n-triples.
 * @return The n-tuples concatenated.
 */
private static synchronized void flattenNTriples(final StringBuilder triples,
        final ConcurrentHashMap<String, ConcurrentSkipListSet<String>> map,
        final ConcurrentSkipListSet<String> types, final ConcurrentSkipListSet<String> label,
        final ConcurrentSkipListSet<String> description, final boolean isOut) {
    try {
        initParser();
        parser.parse(new StringReader(triples.toString()), "");
        for (Statement st : collector.getStatements()) {
            sb.setLength(0);
            final String subject = sb.append('<').append(st.getSubject().toString()).append('>').toString();
            sb.setLength(0);
            final String predicate = sb.append('<').append(st.getPredicate().toString()).append('>').toString();
            sb.setLength(0);
            final String object = (st.getObject() instanceof URI)
                    ? sb.append('<').append(st.getObject().toString()).append('>').toString()
                    : st.getObject().toString();
            if (label != null && predicate.equals(RDFS_LABEL))
                label.add(object);
            if (description != null && predicate.equals(DC_DESCRIPTION))
                description.add(object);
            if (description != null && predicate.equals(DBP_ABSTRACT))
                description.add(object);
            if (types != null && predicate.equals(RDF_TYPE)) {
                types.add(object);
            } else {
                ConcurrentSkipListSet<String> hs = map.get(predicate);
                final String toAdd = isOut ? object : subject;
                if (hs == null) {
                    hs = new ConcurrentSkipListSet<String>();
                    map.put(predicate, hs);
                }
                if (hs.size() < 65535) // 2 ^ 16 - 1
                    hs.add(toAdd);
            }
        }
    } catch (RDFParseException e1) {
    } catch (RDFHandlerException e1) {
    } catch (IOException e1) {
    }
    triples.setLength(0);
}