Search in sources :

Example 1 with CounterType

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);
    });
}
Also used : CounterType(org.infinispan.counter.api.CounterType) AbstractCounterConfiguration(org.infinispan.counter.configuration.AbstractCounterConfiguration) CounterConfiguration(org.infinispan.counter.api.CounterConfiguration)

Example 2 with CounterType

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();
}
Also used : CounterType(org.infinispan.counter.api.CounterType) CounterConfiguration(org.infinispan.counter.api.CounterConfiguration)

Aggregations

CounterConfiguration (org.infinispan.counter.api.CounterConfiguration)2 CounterType (org.infinispan.counter.api.CounterType)2 AbstractCounterConfiguration (org.infinispan.counter.configuration.AbstractCounterConfiguration)1