@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); }
@Override public void testUnboundedStrongCounter(Method method) { final Random random = generateRandom(); final String counterName = method.getName(); CounterConfiguration config = builder(CounterType.UNBOUNDED_STRONG) .initialValue(random.nextInt()) .storage(random.nextBoolean() ? Storage.VOLATILE : Storage.PERSISTENT) .build(); doCreationTest(counterName, config); }
@Override public CounterConfiguration readObject(ObjectInput input) throws IOException, ClassNotFoundException { byte flags = input.readByte(); CounterType type = decodeType(flags); Builder builder = builder(type); builder.storage(decodeStorage(flags)); builder.initialValue(input.readLong()); switch (type) { case BOUNDED_STRONG: builder.lowerBound(input.readLong()); builder.upperBound(input.readLong()); break; case WEAK: builder.concurrencyLevel(readUnsignedInt(input)); break; default: } return builder.build(); } }
case 305: hr2x_counterConfiguration = CounterConfiguration.builder(EncodeUtil.decodeType(hr2x_counterFlags)).storage(EncodeUtil.decodeStorage(hr2x_counterFlags));
/** * 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(); }
/** * Create a counter if one is not defined already, otherwise return the existing one. * * @param counterName unique name for the counter * @param initialValue initial value for the counter * @return a {@link StrongCounter} */ protected StrongCounter getCounterOrCreateIt(String counterName, int initialValue) { CounterManager counterManager = EmbeddedCounterManagerFactory.asCounterManager( cacheManager ); if ( !counterManager.isDefined( counterName ) ) { LOG.tracef( "Counter %s is not defined, creating it", counterName ); // global configuration is mandatory in order to define // a new clustered counter with persistent storage validateGlobalConfiguration(); counterManager.defineCounter( counterName, CounterConfiguration.builder( CounterType.UNBOUNDED_STRONG ) .initialValue( initialValue ) .storage( Storage.PERSISTENT ) .build() ); } StrongCounter strongCounter = counterManager.getStrongCounter( counterName ); return strongCounter; }
/** * Create a counter if one is not defined already, otherwise return the existing one. * * @param counterName unique name for the counter * @param initialValue initial value for the counter * @return a {@link StrongCounter} */ protected StrongCounter getCounterOrCreateIt(String counterName, int initialValue) { CounterManager counterManager = EmbeddedCounterManagerFactory.asCounterManager( cacheManager ); if ( !counterManager.isDefined( counterName ) ) { LOG.tracef( "Counter %s is not defined, creating it", counterName ); // global configuration is mandatory in order to define // a new clustered counter with persistent storage validateGlobalConfiguration(); counterManager.defineCounter( counterName, CounterConfiguration.builder( CounterType.UNBOUNDED_STRONG ) .initialValue( initialValue ) .storage( Storage.PERSISTENT ) .build() ); } StrongCounter strongCounter = counterManager.getStrongCounter( counterName ); return strongCounter; }
private void define(CounterManager manager) { //lower bound is ignored if the type is not bounded. manager.defineCounter(name, CounterConfiguration.builder(type).lowerBound(0).storage(storage).build()); }
private void defineCounter(CounterManager counterManager, String counterName, int initialValue) { counterManager.defineCounter( counterName, CounterConfiguration.builder( CounterType.UNBOUNDED_STRONG ) .initialValue( initialValue ) .storage( Storage.PERSISTENT ) .build() ); } }
@Override public void testLowerBoundedStrongCounter(Method method) { final Random random = generateRandom(); final String counterName = method.getName(); CounterConfiguration config = builder(CounterType.BOUNDED_STRONG) .initialValue(15) .lowerBound(5) .storage(random.nextBoolean() ? Storage.VOLATILE : Storage.PERSISTENT) .build(); doCreationTest(counterName, config); }
@Override public void testUpperBoundedStrongCounter(Method method) { final Random random = generateRandom(); final String counterName = method.getName(); CounterConfiguration config = builder(CounterType.BOUNDED_STRONG) .initialValue(5) .upperBound(15) .storage(random.nextBoolean() ? Storage.VOLATILE : Storage.PERSISTENT) .build(); doCreationTest(counterName, config); }
void processModelNode(OperationContext context, ModelNode counter, CounterConfiguration.Builder builder) throws OperationFailedException { long initialValue = CounterResource.INITIAL_VALUE.resolveModelAttribute(context, counter).asLong(); String storageType = CounterResource.STORAGE.resolveModelAttribute(context, counter).asString(); builder.initialValue(initialValue); builder.storage(Storage.valueOf(storageType)); }
@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); }