Search in sources :

Example 1 with ConcurrentSkipListSet

use of java.util.concurrent.ConcurrentSkipListSet in project hbase by apache.

the class TestProcedureSchedulerConcurrency method testConcurrentWaitWake.

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));
    }
    final Thread[] threads = new Thread[4];
    final AtomicInteger waitCount = new AtomicInteger(0);
    final AtomicInteger wakeCount = new AtomicInteger(0);
    final ConcurrentSkipListSet<TestProcedureWithEvent> waitQueue = new ConcurrentSkipListSet<>();
    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();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ConcurrentSkipListSet(java.util.concurrent.ConcurrentSkipListSet)

Example 2 with ConcurrentSkipListSet

use of java.util.concurrent.ConcurrentSkipListSet in project mapdb by jankotek.

the class ConcurrentSkipListSubSetTest method set5.

/**
     * Returns a new set of first 5 ints.
     */
private NavigableSet set5() {
    ConcurrentSkipListSet q = new ConcurrentSkipListSet();
    assertTrue(q.isEmpty());
    q.add(one);
    q.add(two);
    q.add(three);
    q.add(four);
    q.add(five);
    q.add(zero);
    q.add(seven);
    NavigableSet s = q.subSet(one, true, seven, false);
    assertEquals(5, s.size());
    return s;
}
Also used : NavigableSet(java.util.NavigableSet) ConcurrentSkipListSet(java.util.concurrent.ConcurrentSkipListSet)

Example 3 with ConcurrentSkipListSet

use of java.util.concurrent.ConcurrentSkipListSet in project spring-framework by spring-projects.

the class OriginHandshakeInterceptorTests method originNoMatchWithNullHostileCollection.

@Test
public void originNoMatchWithNullHostileCollection() throws Exception {
    Map<String, Object> attributes = new HashMap<>();
    WebSocketHandler wsHandler = Mockito.mock(WebSocketHandler.class);
    this.servletRequest.addHeader(HttpHeaders.ORIGIN, "http://mydomain4.com");
    OriginHandshakeInterceptor interceptor = new OriginHandshakeInterceptor();
    Set<String> allowedOrigins = new ConcurrentSkipListSet<>();
    allowedOrigins.add("http://mydomain1.com");
    interceptor.setAllowedOrigins(allowedOrigins);
    assertFalse(interceptor.beforeHandshake(request, response, wsHandler, attributes));
    assertEquals(servletResponse.getStatus(), HttpStatus.FORBIDDEN.value());
}
Also used : HashMap(java.util.HashMap) ConcurrentSkipListSet(java.util.concurrent.ConcurrentSkipListSet) WebSocketHandler(org.springframework.web.socket.WebSocketHandler) Test(org.junit.Test)

Example 4 with ConcurrentSkipListSet

use of java.util.concurrent.ConcurrentSkipListSet in project cassandra by apache.

the class SkipListMemIndex method search.

public RangeIterator<Long, Token> search(Expression expression) {
    ByteBuffer min = expression.lower == null ? null : expression.lower.value;
    ByteBuffer max = expression.upper == null ? null : expression.upper.value;
    SortedMap<ByteBuffer, ConcurrentSkipListSet<DecoratedKey>> search;
    if (min == null && max == null) {
        throw new IllegalArgumentException();
    }
    if (min != null && max != null) {
        search = index.subMap(min, expression.lower.inclusive, max, expression.upper.inclusive);
    } else if (min == null) {
        search = index.headMap(max, expression.upper.inclusive);
    } else {
        search = index.tailMap(min, expression.lower.inclusive);
    }
    RangeUnionIterator.Builder<Long, Token> builder = RangeUnionIterator.builder();
    search.values().stream().filter(keys -> !keys.isEmpty()).forEach(keys -> builder.add(new KeyRangeIterator(keys)));
    return builder.build();
}
Also used : RangeIterator(org.apache.cassandra.index.sasi.utils.RangeIterator) java.util(java.util) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) DecoratedKey(org.apache.cassandra.db.DecoratedKey) ConcurrentSkipListSet(java.util.concurrent.ConcurrentSkipListSet) Expression(org.apache.cassandra.index.sasi.plan.Expression) Token(org.apache.cassandra.index.sasi.disk.Token) RangeUnionIterator(org.apache.cassandra.index.sasi.utils.RangeUnionIterator) AbstractType(org.apache.cassandra.db.marshal.AbstractType) ByteBuffer(java.nio.ByteBuffer) ColumnIndex(org.apache.cassandra.index.sasi.conf.ColumnIndex) ConcurrentSkipListSet(java.util.concurrent.ConcurrentSkipListSet) RangeUnionIterator(org.apache.cassandra.index.sasi.utils.RangeUnionIterator) Token(org.apache.cassandra.index.sasi.disk.Token) ByteBuffer(java.nio.ByteBuffer)

Example 5 with ConcurrentSkipListSet

use of java.util.concurrent.ConcurrentSkipListSet in project titan by thinkaurelius.

the class TestByteBuffer method testByte.

private static long testByte() {
    LongObjectMap<ConcurrentSkipListSet<ByteEntry>> tx = new LongObjectHashMap<ConcurrentSkipListSet<ByteEntry>>(NUM);
    for (int i = 0; i < NUM; i++) {
        tx.put(i, new ConcurrentSkipListSet<ByteEntry>());
    }
    for (int i = 0; i < NUM; i++) {
        for (int j = 0; j < NUM; j++) {
            if (i == j)
                continue;
            if (Math.random() < FRACTION) {
                ByteBuffer key = ByteBuffer.allocate(16);
                key.putLong(5).putLong(j).flip();
                ByteBuffer value = ByteBuffer.allocate(4);
                value.putInt(random.nextInt(ROUNDSIZE)).flip();
                tx.get(i).add(new ByteEntry(key, value));
            }
        }
    }
    long time = System.currentTimeMillis();
    long sum = 0;
    for (int t = 0; t < TRIALS; t++) {
        for (int i = 0; i < NUM; i++) {
            for (Vertex v : (new ByteVertex(i, tx)).getNeighbors(0)) {
                sum += v.getId();
            }
        }
    }
    time = System.currentTimeMillis() - time;
    return time;
}
Also used : LongObjectHashMap(com.carrotsearch.hppc.LongObjectHashMap) ConcurrentSkipListSet(java.util.concurrent.ConcurrentSkipListSet) ByteBuffer(java.nio.ByteBuffer)

Aggregations

ConcurrentSkipListSet (java.util.concurrent.ConcurrentSkipListSet)17 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 ByteBuffer (java.nio.ByteBuffer)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 NavigableSet (java.util.NavigableSet)2 Set (java.util.Set)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 ExecutorService (java.util.concurrent.ExecutorService)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 Ignite (org.apache.ignite.Ignite)2 DefaultMQPullConsumer (com.alibaba.rocketmq.client.consumer.DefaultMQPullConsumer)1 OffsetStore (com.alibaba.rocketmq.client.consumer.store.OffsetStore)1 MQClientException (com.alibaba.rocketmq.client.exception.MQClientException)1 MessageExt (com.alibaba.rocketmq.common.message.MessageExt)1 MessageQueue (com.alibaba.rocketmq.common.message.MessageQueue)1 LongObjectHashMap (com.carrotsearch.hppc.LongObjectHashMap)1