package org.infinispan.demo;

import org.infinispan.configuration.global.GlobalConfigurationBuilder;
import org.infinispan.counter.EmbeddedCounterManagerFactory;
import org.infinispan.counter.api.CounterManager;
import org.infinispan.counter.api.Storage;
import org.infinispan.counter.api.StrongCounter;
import org.infinispan.counter.configuration.CounterManagerConfigurationBuilder;
import org.infinispan.counter.configuration.Reliability;
import org.infinispan.manager.DefaultCacheManager;
import org.infinispan.manager.EmbeddedCacheManager;

public class StrongCounters {

    
    public static void main(String[] args) throws Exception {
        StrongCounter cnt = createCounter();
        for (int i = 0; i < 1_000; i++) {
            System.out.println(" -> " + cnt.incrementAndGet().get());
        }
    }
    
    public static StrongCounter createCounter() {
        GlobalConfigurationBuilder gcb = new GlobalConfigurationBuilder();
        gcb.clusteredDefault();
        
        CounterManagerConfigurationBuilder cntBuilder = gcb.addModule(CounterManagerConfigurationBuilder.class);
        cntBuilder.numOwner(2).reliability(Reliability.CONSISTENT);
        cntBuilder.addStrongCounter().name("cnt").initialValue(0).storage(Storage.VOLATILE);
        
        EmbeddedCacheManager cm = new DefaultCacheManager(gcb.build());
        CounterManager cntManager = EmbeddedCounterManagerFactory.asCounterManager(cm);
        return cntManager.getStrongCounter("cnt");
    }

}

@@ -23,16 +23,55 @@
 .demo;%0A%0A
+import java.util.concurrent.TimeUnit;%0A%0A
 import o
@@ -608,21 +608,16 @@
 ters %7B%0A%0A
-    %0A
     publ
@@ -670,16 +670,70 @@
 ption %7B%0A
+        EmbeddedCacheManager cm = configureCluster();%0A
         
@@ -762,27 +762,30 @@
 eateCounter(
+cm
 );%0A
+%0A
         for 
@@ -894,26 +894,42 @@
       %7D%0A
-    %7D
+%0A        cm.stop();
 %0A    
+%7D%0A
 %0A    pub
@@ -943,32 +943,42 @@
 tic 
-StrongCounter createCoun
+EmbeddedCacheManager configureClus
 ter(
@@ -1088,32 +1088,115 @@
 ault();%0A        
+gcb.transport().initialClusterSize(2).initialClusterTimeout(10, TimeUnit.SECONDS);%0A
 %0A        Counter
@@ -1454,24 +1454,16 @@
 ATILE);%0A
-        
 %0A       
@@ -1467,33 +1467,14 @@
     
-EmbeddedCacheManager cm =
+return
  new
@@ -1504,24 +1504,104 @@
 b.build());%0A
+    %7D%0A%0A    public static StrongCounter createCounter(EmbeddedCacheManager cm) %7B%0A
         Coun

Stop cluster manager, require 2 node cluster