Search in sources :

Example 31 with ConcurrentSkipListMap

use of java.util.concurrent.ConcurrentSkipListMap in project opennms by OpenNMS.

the class DnsMonitorIT method testIPV6Response.

@Test
public void testIPV6Response() throws UnknownHostException {
    assumeTrue(!Boolean.getBoolean("skipIpv6Tests"));
    final Map<String, Object> m = new ConcurrentSkipListMap<String, Object>();
    final ServiceMonitor monitor = new DnsMonitor();
    final MonitoredService svc = MonitorTestUtils.getMonitoredService(99, addr("::1"), "DNS");
    m.put("port", "9153");
    m.put("retry", "1");
    m.put("timeout", "1000");
    m.put("lookup", "ipv6.example.com");
    final PollStatus status = monitor.poll(svc, m);
    MockUtil.println("Reason: " + status.getReason());
    assertEquals(PollStatus.SERVICE_AVAILABLE, status.getStatusCode());
}
Also used : ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) ServiceMonitor(org.opennms.netmgt.poller.ServiceMonitor) PollStatus(org.opennms.netmgt.poller.PollStatus) MonitoredService(org.opennms.netmgt.poller.MonitoredService) Test(org.junit.Test)

Example 32 with ConcurrentSkipListMap

use of java.util.concurrent.ConcurrentSkipListMap in project opennms by OpenNMS.

the class TcpMonitorIT method testLocalhostIPv6Connection.

@Test
@JUnitHttpServer(port = 10342)
public void testLocalhostIPv6Connection() throws UnknownHostException {
    assumeTrue(!Boolean.getBoolean("skipIpv6Tests"));
    Map<String, Object> m = new ConcurrentSkipListMap<String, Object>();
    Parameter p = new Parameter();
    ServiceMonitor monitor = new TcpMonitor();
    MonitoredService svc = MonitorTestUtils.getMonitoredService(3, "::1", addr("::1"), "TCP");
    p.setKey("port");
    p.setValue("10342");
    m.put(p.getKey(), p.getValue());
    p.setKey("retry");
    p.setValue("1");
    m.put(p.getKey(), p.getValue());
    p.setKey("timeout");
    p.setValue("500");
    m.put(p.getKey(), p.getValue());
    PollStatus status = monitor.poll(svc, m);
    MockUtil.println("Reason: " + status.getReason());
    assertEquals(PollStatus.SERVICE_AVAILABLE, status.getStatusCode());
    assertNull(status.getReason());
}
Also used : ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) ServiceMonitor(org.opennms.netmgt.poller.ServiceMonitor) PollStatus(org.opennms.netmgt.poller.PollStatus) MonitoredService(org.opennms.netmgt.poller.MonitoredService) Parameter(org.opennms.netmgt.config.poller.Parameter) Test(org.junit.Test) JUnitHttpServer(org.opennms.core.test.http.annotations.JUnitHttpServer)

Example 33 with ConcurrentSkipListMap

use of java.util.concurrent.ConcurrentSkipListMap in project bookkeeper by apache.

the class DLAuditor method calculateStreamSpaceUsage.

private Map<String, Long> calculateStreamSpaceUsage(final URI uri, final Namespace namespace) throws IOException {
    Iterator<String> streams = namespace.getLogs();
    final LinkedBlockingQueue<String> streamQueue = new LinkedBlockingQueue<String>();
    while (streams.hasNext()) {
        streamQueue.add(streams.next());
    }
    final Map<String, Long> streamSpaceUsageMap = new ConcurrentSkipListMap<String, Long>();
    final AtomicInteger numStreamsCollected = new AtomicInteger(0);
    executeAction(streamQueue, 10, new Action<String>() {

        @Override
        public void execute(String stream) throws IOException {
            streamSpaceUsageMap.put(stream, calculateStreamSpaceUsage(namespace, stream));
            if (numStreamsCollected.incrementAndGet() % 1000 == 0) {
                logger.info("Calculated {} streams from uri {}.", numStreamsCollected.get(), uri);
            }
        }
    });
    return streamSpaceUsageMap;
}
Also used : ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicLong(java.util.concurrent.atomic.AtomicLong) IOException(java.io.IOException) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue)

Example 34 with ConcurrentSkipListMap

use of java.util.concurrent.ConcurrentSkipListMap in project bookkeeper by apache.

the class DistributedLogAdmin method checkStreams.

private static Map<String, StreamCandidate> checkStreams(final Namespace namespace, final Collection<String> streams, final OrderedScheduler scheduler, final int concurrency) throws IOException {
    final LinkedBlockingQueue<String> streamQueue = new LinkedBlockingQueue<String>();
    streamQueue.addAll(streams);
    final Map<String, StreamCandidate> candidateMap = new ConcurrentSkipListMap<String, StreamCandidate>();
    final AtomicInteger numPendingStreams = new AtomicInteger(streams.size());
    final CountDownLatch doneLatch = new CountDownLatch(1);
    Runnable checkRunnable = new Runnable() {

        @Override
        public void run() {
            while (!streamQueue.isEmpty()) {
                String stream;
                try {
                    stream = streamQueue.take();
                } catch (InterruptedException e) {
                    Thread.currentThread().interrupt();
                    break;
                }
                StreamCandidate candidate;
                try {
                    LOG.info("Checking stream {}.", stream);
                    candidate = checkStream(namespace, stream, scheduler);
                    LOG.info("Checked stream {} - {}.", stream, candidate);
                } catch (Throwable e) {
                    LOG.error("Error on checking stream {} : ", stream, e);
                    doneLatch.countDown();
                    break;
                }
                if (null != candidate) {
                    candidateMap.put(stream, candidate);
                }
                if (numPendingStreams.decrementAndGet() == 0) {
                    doneLatch.countDown();
                }
            }
        }
    };
    Thread[] threads = new Thread[concurrency];
    for (int i = 0; i < concurrency; i++) {
        threads[i] = new Thread(checkRunnable, "check-thread-" + i);
        threads[i].start();
    }
    try {
        doneLatch.await();
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    }
    if (numPendingStreams.get() != 0) {
        throw new IOException(numPendingStreams.get() + " streams left w/o checked");
    }
    for (int i = 0; i < concurrency; i++) {
        threads[i].interrupt();
        try {
            threads[i].join();
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        }
    }
    return candidateMap;
}
Also used : ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) IOException(java.io.IOException) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) CountDownLatch(java.util.concurrent.CountDownLatch) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Example 35 with ConcurrentSkipListMap

use of java.util.concurrent.ConcurrentSkipListMap in project jackrabbit-oak by apache.

the class MemoryDocumentStore method remove.

@Override
public <T extends Document> int remove(Collection<T> collection, Map<String, Long> toRemove) {
    int num = 0;
    ConcurrentSkipListMap<String, T> map = getMap(collection);
    for (Map.Entry<String, Long> entry : toRemove.entrySet()) {
        Lock lock = rwLock.writeLock();
        lock.lock();
        try {
            T doc = map.get(entry.getKey());
            Condition c = newEqualsCondition(entry.getValue());
            if (doc != null && checkConditions(doc, Collections.singletonMap(KEY_MODIFIED, c))) {
                if (map.remove(entry.getKey()) != null) {
                    num++;
                }
            }
        } finally {
            lock.unlock();
        }
    }
    return num;
}
Also used : Condition.newEqualsCondition(org.apache.jackrabbit.oak.plugins.document.UpdateOp.Condition.newEqualsCondition) Condition(org.apache.jackrabbit.oak.plugins.document.UpdateOp.Condition) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ConcurrentNavigableMap(java.util.concurrent.ConcurrentNavigableMap) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) Lock(java.util.concurrent.locks.Lock)

Aggregations

ConcurrentSkipListMap (java.util.concurrent.ConcurrentSkipListMap)183 Test (org.junit.Test)66 PollStatus (org.opennms.netmgt.poller.PollStatus)32 MonitoredService (org.opennms.netmgt.poller.MonitoredService)31 Map (java.util.Map)30 ServiceMonitor (org.opennms.netmgt.poller.ServiceMonitor)25 MqttDeviceTwin (com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceTwin)23 HashMap (java.util.HashMap)21 DeviceTwinMessage (com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceTwinMessage)17 NavigableMap (java.util.NavigableMap)14 Set (java.util.Set)12 Iterator (java.util.Iterator)11 NavigableSet (java.util.NavigableSet)11 MockMonitoredService (org.opennms.netmgt.poller.mock.MockMonitoredService)11 IOException (java.io.IOException)10 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)10 ArrayList (java.util.ArrayList)9 BitSet (java.util.BitSet)9 DeviceOperations (com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceOperations)8 JUnitHttpServer (org.opennms.core.test.http.annotations.JUnitHttpServer)8