Search in sources :

Example 11 with CounterConfiguration

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

the class MultiResourceTest method createCounters.

private void createCounters(String... names) {
    CounterConfiguration configuration = CounterConfiguration.builder(CounterType.BOUNDED_STRONG).lowerBound(0).upperBound(100).initialValue(0).build();
    for (String counterName : names) {
        AbstractCounterConfiguration config = ConvertUtil.configToParsedConfig(counterName, configuration);
        RestResponse response = join(client.counter(counterName).create(RestEntity.create(APPLICATION_JSON, counterConfigToJson(config))));
        ResponseAssertion.assertThat(response).isOk();
    }
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse) AbstractCounterConfiguration(org.infinispan.counter.configuration.AbstractCounterConfiguration) AbstractCounterConfiguration(org.infinispan.counter.configuration.AbstractCounterConfiguration) CounterConfiguration(org.infinispan.counter.api.CounterConfiguration)

Example 12 with CounterConfiguration

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

the class TestServlet method incrementCounter.

@Path("incr/{id}")
@GET
@Produces(MediaType.TEXT_PLAIN)
public CompletionStage<Long> incrementCounter(@PathParam("id") String id) {
    ensureStart();
    CounterConfiguration configuration = counterManager.getConfiguration(id);
    if (configuration == null) {
        configuration = CounterConfiguration.builder(CounterType.BOUNDED_STRONG).build();
        counterManager.defineCounter(id, configuration);
    }
    StrongCounter strongCounter = counterManager.getStrongCounter(id);
    return strongCounter.incrementAndGet();
}
Also used : CounterConfiguration(org.infinispan.counter.api.CounterConfiguration) StrongCounter(org.infinispan.counter.api.StrongCounter) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 13 with CounterConfiguration

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

the class RemoteCounterManager method createStrongCounter.

private StrongCounter createStrongCounter(String counterName) {
    CounterConfiguration configuration = getConfiguration(counterName);
    if (configuration == null) {
        throw commonsLog.undefinedCounter(counterName);
    }
    assertStrongCounter(configuration);
    return new StrongCounterImpl(counterName, configuration, factory, notificationManager);
}
Also used : CounterConfiguration(org.infinispan.counter.api.CounterConfiguration)

Example 14 with CounterConfiguration

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

the class RemoteCounterManager method createWeakCounter.

private WeakCounter createWeakCounter(String counterName) {
    CounterConfiguration configuration = getConfiguration(counterName);
    if (configuration == null) {
        throw commonsLog.undefinedCounter(counterName);
    }
    assertWeakCounter(configuration);
    return new WeakCounterImpl(counterName, configuration, factory, notificationManager);
}
Also used : CounterConfiguration(org.infinispan.counter.api.CounterConfiguration)

Example 15 with CounterConfiguration

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

the class AbstractCounterTest method testGetConfigurationAndGetName.

public void testGetConfigurationAndGetName(Method method) {
    final String counterNamePrefix = method.getName();
    final CounterManager counterManager = counterManager(0);
    int suffix = 0;
    for (CounterConfiguration configuration : configurationToTest()) {
        T counter = createCounter(counterManager, counterNamePrefix + suffix, configuration);
        assertEquals(configuration, counter.getConfiguration());
        assertEquals(counterNamePrefix + suffix, counter.getName());
        suffix++;
    }
}
Also used : CounterManager(org.infinispan.counter.api.CounterManager) 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