use of org.infinispan.counter.api.CounterType in project infinispan by infinispan.
the class CounterResource method executeCommonCounterOp.
private CompletionStage<RestResponse> executeCommonCounterOp(RestRequest request, Function<WeakCounter, CompletionStage<Void>> weakOp, Function<StrongCounter, CompletableFuture<Long>> strongOp) {
String counterName = request.variables().get("counterName");
CompletableFuture<CounterConfiguration> counterConfigAsync = invocationHelper.getCounterManager().getConfigurationAsync(counterName);
return counterConfigAsync.thenCompose(configuration -> {
if (configuration == null)
return notFoundResponseFuture();
CounterType type = configuration.type();
if (type == CounterType.WEAK)
return executeWeakCounterOp(counterName, weakOp);
return executeStrongCounterOp(counterName, strongOp);
});
}
use of org.infinispan.counter.api.CounterType in project infinispan by infinispan.
the class EncodeUtil method decodeConfiguration.
/**
* Decodes a {@link CounterConfiguration} encoded by {@link #encodeConfiguration(CounterConfiguration, Consumer,
* LongConsumer, IntConsumer)}.
*
* @return the decoded {@link CounterConfiguration}.
* @see #encodeConfiguration(CounterConfiguration, Consumer, LongConsumer, IntConsumer)
*/
public static CounterConfiguration decodeConfiguration(Supplier<Byte> byteSupplier, LongSupplier longSupplier, IntSupplier intSupplier) {
byte flags = byteSupplier.get();
CounterType type = decodeType(flags);
CounterConfiguration.Builder builder = CounterConfiguration.builder(type);
builder.storage(decodeStorage(flags));
switch(type) {
case WEAK:
builder.concurrencyLevel(intSupplier.getAsInt());
break;
case BOUNDED_STRONG:
builder.lowerBound(longSupplier.getAsLong());
builder.upperBound(longSupplier.getAsLong());
break;
case UNBOUNDED_STRONG:
default:
break;
}
builder.initialValue(longSupplier.getAsLong());
return builder.build();
}
Aggregations