Search in sources :

Example 1 with GroupMember

use of org.apache.curator.framework.recipes.nodes.GroupMember in project zipkin by openzipkin.

the class ZooKeeperCollectorSampler method storeRateGroup.

static GroupMember storeRateGroup(CuratorFramework client, Builder builder, Closer closer, AtomicInteger spanCount, AtomicInteger storeRate) {
    String storeRatePath = ensureExists(client, builder.basePath + "/storeRates");
    GroupMember storeRateGroup = closer.register(new GroupMember(client, storeRatePath, builder.id));
    log.debug("{} is to join the group {}", builder.id, storeRatePath);
    storeRateGroup.start();
    ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
    closer.register(executor::shutdown);
    ScheduledFuture<?> future = executor.scheduleAtFixedRate(() -> {
        int oldValue = storeRate.get();
        int newValue = (int) (1.0 * spanCount.getAndSet(0) * 60 / builder.updateFrequency);
        log.debug("Store rates was: {} now {}", oldValue, newValue);
        if (oldValue != newValue) {
            storeRate.set(newValue);
            storeRateGroup.setThisData(Integer.valueOf(newValue).toString().getBytes(UTF_8));
        }
    }, 0, builder.updateFrequency, TimeUnit.SECONDS);
    closer.register(() -> future.cancel(true));
    return storeRateGroup;
}
Also used : GroupMember(org.apache.curator.framework.recipes.nodes.GroupMember) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService)

Aggregations

ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 GroupMember (org.apache.curator.framework.recipes.nodes.GroupMember)1