use of org.infinispan.counter.impl.manager.EmbeddedCounterManager in project infinispan by infinispan.
the class CounterResource method getCounter.
private CompletionStage<RestResponse> getCounter(RestRequest request) throws RestResponseException {
String counterName = request.variables().get("counterName");
String accept = request.getAcceptHeader();
MediaType contentType = accept == null ? MediaType.TEXT_PLAIN : negotiateMediaType(accept);
EmbeddedCounterManager counterManager = invocationHelper.getCounterManager();
return counterManager.getConfigurationAsync(counterName).thenCompose(configuration -> {
if (configuration == null)
return notFoundResponseFuture();
NettyRestResponse.Builder responseBuilder = new NettyRestResponse.Builder().contentType(contentType).header(CACHE_CONTROL.toString(), CacheControl.noCache());
CompletionStage<Long> response;
if (configuration.type() == CounterType.WEAK) {
response = getWeakCounter(counterName, counterManager).thenApply(WeakCounter::getValue);
} else {
response = getStrongCounter(counterName, counterManager).thenCompose(StrongCounter::getValue);
}
return response.thenApply(v -> responseBuilder.entity(Long.toString(v)).build());
});
}
use of org.infinispan.counter.impl.manager.EmbeddedCounterManager in project infinispan by infinispan.
the class CounterResource method deleteCounter.
private CompletionStage<RestResponse> deleteCounter(RestRequest request) {
String counterName = request.variables().get("counterName");
EmbeddedCounterManager counterManager = invocationHelper.getCounterManager();
return counterManager.getConfigurationAsync(counterName).thenCompose(configuration -> {
if (configuration == null)
return notFoundResponseFuture();
return CompletableFuture.runAsync(() -> counterManager.undefineCounter(counterName), invocationHelper.getExecutor()).thenApply(ignore -> new NettyRestResponse.Builder().status(NO_CONTENT).build());
});
}
use of org.infinispan.counter.impl.manager.EmbeddedCounterManager in project infinispan by infinispan.
the class CounterModuleLifecycle method registerCounterManager.
private static void registerCounterManager(EmbeddedCacheManager cacheManager, BasicComponentRegistry registry, GlobalConfiguration globalConfiguration) {
if (log.isTraceEnabled())
log.tracef("Registering counter manager.");
EmbeddedCounterManager counterManager = new EmbeddedCounterManager(cacheManager);
// This must happen before CacheManagerJmxRegistration starts
registry.registerComponent(CounterManager.class, counterManager, true);
if (globalConfiguration.jmx().enabled()) {
try {
CacheManagerJmxRegistration jmxRegistration = registry.getComponent(CacheManagerJmxRegistration.class).running();
jmxRegistration.registerMBean(counterManager);
} catch (Exception e) {
throw log.jmxRegistrationFailed(e);
}
}
}
use of org.infinispan.counter.impl.manager.EmbeddedCounterManager in project infinispan by infinispan.
the class CounterRequestProcessor method applyCounter.
private void applyCounter(HotRodHeader header, String counterName, BiConsumer<HotRodHeader, StrongCounter> applyStrong, BiConsumer<HotRodHeader, WeakCounter> applyWeak) {
EmbeddedCounterManager counterManager = counterManager(header);
CounterConfiguration config = counterManager.getConfiguration(counterName);
if (config == null) {
writeResponse(header, missingCounterResponse(header));
return;
}
switch(config.type()) {
case UNBOUNDED_STRONG:
case BOUNDED_STRONG:
applyStrong.accept(header, counterManager.getStrongCounter(counterName));
break;
case WEAK:
applyWeak.accept(header, counterManager.getWeakCounter(counterName));
break;
}
}
use of org.infinispan.counter.impl.manager.EmbeddedCounterManager in project infinispan by infinispan.
the class CounterResource method resetCounter.
private CompletionStage<RestResponse> resetCounter(RestRequest request) throws RestResponseException {
String counterName = request.variables().get("counterName");
EmbeddedCounterManager counterManager = invocationHelper.getCounterManager();
return counterManager.getConfigurationAsync(counterName).thenCompose(configuration -> {
if (configuration == null)
return notFoundResponseFuture();
CompletionStage<Void> result = configuration.type() == CounterType.WEAK ? counterManager.getWeakCounter(counterName).reset() : counterManager.getStrongCounter(counterName).reset();
return result.thenApply(v -> new NettyRestResponse.Builder().status(NO_CONTENT).build());
});
}
Aggregations