@Override public long getValue() { return syncCounter.getValue(); }
/** * @see WeakCounter#decrement() */ default void decrement() { add(-1); }
@Override public void decrement() { syncCounter.decrement(); }
@Override public void increment() { syncCounter.increment(); }
@Override public void reset() { syncCounter.reset(); }
@Override public CounterConfiguration getConfiguration() { return syncCounter.getConfiguration(); }
@Override public void remove() { syncCounter.remove(); } }
@Override public String getName() { return syncCounter.getName(); }
@Override protected ModelNode invoke(CounterManager counterManager, ModelNode operation) { final String counterName = counterName(operation); final String counterType = counterType(operation); if (counterManager.isDefined(counterName)) { boolean isStrongCounter = ModelKeys.STRONG_COUNTER.equals(counterType); if (isStrongCounter) { StrongCounter strongCounter = counterManager.getStrongCounter(counterName); strongCounter.sync().incrementAndGet(); } else { WeakCounter weakCounter = counterManager.getWeakCounter(counterName); weakCounter.sync().increment(); } } return new ModelNode(); } }
@Override protected ModelNode invoke(CounterManager counterManager, ModelNode operation) { final String counterName = counterName(operation); final String counterType = counterType(operation); if (counterManager.isDefined(counterName)) { boolean isStrongCounter = ModelKeys.STRONG_COUNTER.equals(counterType); if (isStrongCounter) { StrongCounter strongCounter = counterManager.getStrongCounter(counterName); strongCounter.sync().reset(); } else { WeakCounter weakCounter = counterManager.getWeakCounter(counterName); weakCounter.sync().reset(); } } return new ModelNode(); } }
@Override protected void executeRuntimeStep(OperationContext context, ModelNode operation) { final ModelNode result = new ModelNode(); final PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR)); final String cacheContainerName = address.getElement(CACHE_CONTAINER_INDEX).getValue(); final String counterType = address.getElement(COUNTER_INDEX).getKey(); final String counterName = address.getElement(COUNTER_INDEX).getValue(); final ServiceController<?> controller = context.getServiceRegistry(false) .getService(CacheContainerServiceName.CACHE_CONTAINER.getServiceName(cacheContainerName)); Long value; if (controller != null) { DefaultCacheContainer cacheManager = (DefaultCacheContainer) controller.getValue(); CounterManager counterManager = EmbeddedCounterManagerFactory.asCounterManager(cacheManager); if (ModelKeys.STRONG_COUNTER.equals(counterType)) { StrongCounter sc = counterManager.getStrongCounter(counterName); value = sc.sync().getValue(); } else { WeakCounter wc = counterManager.getWeakCounter(counterName); value = wc.sync().getValue(); } result.set(value); } context.getResult().set(result); }
private void incrementCounter(CounterManager counterManager) { switch (type) { case UNBOUNDED_STRONG: case BOUNDED_STRONG: counterManager.getStrongCounter(name).sync().incrementAndGet(); break; case WEAK: counterManager.getWeakCounter(name).sync().increment(); break; } }
/** * @see WeakCounter#increment() */ default void increment() { add(1); }
@Override protected ModelNode invoke(CounterManager counterManager, ModelNode operation) { final String counterName = counterName(operation); final String counterType = counterType(operation); if (counterManager.isDefined(counterName)) { boolean isStrongCounter = ModelKeys.STRONG_COUNTER.equals(counterType); if (isStrongCounter) { StrongCounter strongCounter = counterManager.getStrongCounter(counterName); strongCounter.sync().decrementAndGet(); } else { WeakCounter weakCounter = counterManager.getWeakCounter(counterName); weakCounter.sync().decrement(); } } return new ModelNode(); } }
@Test public void testCounters() { CounterManager counterManager = RemoteCounterManagerFactory.asCounterManager(remoteCacheManager); counterManager.defineCounter("c1", CounterConfiguration.builder(CounterType.BOUNDED_STRONG) .upperBound(10) .initialValue(1) .build()); counterManager.defineCounter("c2", CounterConfiguration.builder(CounterType.WEAK) .initialValue(5) .build()); SyncStrongCounter c1 = counterManager.getStrongCounter("c1").sync(); SyncWeakCounter c2 = counterManager.getWeakCounter("c2").sync(); assertEquals(1, c1.getValue()); assertEquals(5, c2.getValue()); }
@Override public void add(long delta) { syncCounter.add(delta); }