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());
}
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());
}
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;
}
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;
}
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;
}
Aggregations