Search in sources :

Example 6 with CounterConfiguration

use of org.infinispan.counter.api.CounterConfiguration in project infinispan by infinispan.

the class CounterManagerImplTestStrategy method testBoundedStrongCounter.

@Override
public void testBoundedStrongCounter(Method method) {
    final Random random = generateRandom();
    final String counterName = method.getName();
    CounterConfiguration config = builder(CounterType.BOUNDED_STRONG).initialValue(15).lowerBound(5).upperBound(20).storage(random.nextBoolean() ? Storage.VOLATILE : Storage.PERSISTENT).build();
    doCreationTest(counterName, config);
}
Also used : Random(java.util.Random) CounterConfiguration(org.infinispan.counter.api.CounterConfiguration)

Example 7 with CounterConfiguration

use of org.infinispan.counter.api.CounterConfiguration in project infinispan by infinispan.

the class TestCounterManager method getStrongCounter.

@Override
public StrongCounter getStrongCounter(String name) {
    StrongCounter c = (StrongCounter) counters.get(name);
    if (c == null) {
        CounterConfiguration config = getConfiguration(name);
        if (config == null || config.type() == CounterType.WEAK) {
            throw new IllegalStateException();
        }
        c = new TestStrongCounter(name, config, client, notificationManager);
        counters.put(name, c);
    }
    return c;
}
Also used : StrongCounter(org.infinispan.counter.api.StrongCounter) CounterConfiguration(org.infinispan.counter.api.CounterConfiguration)

Example 8 with CounterConfiguration

use of org.infinispan.counter.api.CounterConfiguration in project infinispan by infinispan.

the class TestCounterManager method getWeakCounter.

@Override
public WeakCounter getWeakCounter(String name) {
    WeakCounter c = (WeakCounter) counters.get(name);
    if (c == null) {
        CounterConfiguration config = getConfiguration(name);
        if (config == null || config.type() != CounterType.WEAK) {
            throw new IllegalStateException();
        }
        c = new TestWeakCounter(name, config, client, notificationManager);
        counters.put(name, c);
    }
    return c;
}
Also used : WeakCounter(org.infinispan.counter.api.WeakCounter) CounterConfiguration(org.infinispan.counter.api.CounterConfiguration)

Example 9 with CounterConfiguration

use of org.infinispan.counter.api.CounterConfiguration in project infinispan by infinispan.

the class CounterManagerImplTestStrategy method testWeakCounter.

@Override
public void testWeakCounter(Method method) {
    final Random random = generateRandom();
    final String counterName = method.getName();
    CounterConfiguration config = builder(CounterType.WEAK).initialValue(random.nextInt()).storage(random.nextBoolean() ? Storage.VOLATILE : Storage.PERSISTENT).concurrencyLevel(abs(random.nextInt())).build();
    doCreationTest(counterName, config);
}
Also used : Random(java.util.Random) CounterConfiguration(org.infinispan.counter.api.CounterConfiguration)

Example 10 with CounterConfiguration

use of org.infinispan.counter.api.CounterConfiguration 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)

Aggregations

CounterConfiguration (org.infinispan.counter.api.CounterConfiguration)30 CounterManager (org.infinispan.counter.api.CounterManager)8 Random (java.util.Random)7 AbstractCounterConfiguration (org.infinispan.counter.configuration.AbstractCounterConfiguration)7 StrongCounter (org.infinispan.counter.api.StrongCounter)4 RestResponse (org.infinispan.client.rest.RestResponse)3 CounterType (org.infinispan.counter.api.CounterType)3 WeakCounter (org.infinispan.counter.api.WeakCounter)3 DataInputStream (java.io.DataInputStream)2 IOException (java.io.IOException)2 ZipEntry (java.util.zip.ZipEntry)2 RestCounterClient (org.infinispan.client.rest.RestCounterClient)2 CacheException (org.infinispan.commons.CacheException)2 BlockingManager (org.infinispan.util.concurrent.BlockingManager)2 Flowable (io.reactivex.rxjava3.core.Flowable)1 DataOutputStream (java.io.DataOutputStream)1 OutputStream (java.io.OutputStream)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1