// Path: infinispan-remote/connect-to-infinispan-server/src/main/java/org/infinispan/tutorial/simple/connect/Infinispan.java
// public class Infinispan {
// 
//    public static final String USER = "admin";
//    public static final String PASSWORD = "password";
// 
//    public static final String TUTORIAL_CACHE_NAME = "test";
//    public static final String HOST = "127.0.0.1";
// 
//    public static final String TUTORIAL_CACHE_CONFIG =
//          "<distributed-cache name=\"CACHE_NAME\">\n"
//          + "    <encoding media-type=\"application/x-protostream\"/>\n"
//          + "</distributed-cache>";
// 
//    /**
//     * Returns the configuration builder with the connection information
//     *
//     * @return a Configuration Builder with the connection config
//     */
//    public static final ConfigurationBuilder connectionConfig() {
//       ConfigurationBuilder builder = new ConfigurationBuilder();
//       builder.addServer().host("127.0.0.1").port(ConfigurationProperties.DEFAULT_HOTROD_PORT).security()
//             .authentication()
//             //Add user credentials.
//             .username(USER)
//             .password(PASSWORD);
// 
//       // Docker 4 Mac Workaround. Don't use BASIC intelligence in production
//       builder.clientIntelligence(ClientIntelligence.BASIC);
// 
//       // Make sure the remote cache is available.
//       // If the cache does not exist, the cache will be created
//       builder.remoteCache(TUTORIAL_CACHE_NAME)
//             .configuration(TUTORIAL_CACHE_CONFIG.replace("CACHE_NAME", TUTORIAL_CACHE_NAME));
//       return builder;
//    }
// 
//    /**
//     * Connect to the running Infinispan Server in localhost:11222.
//     *
//     * This method illustrates how to connect to a running Infinispan Server with a downloaded
//     * distribution or a container.
//     *
//     * @return a connected RemoteCacheManager
//     */
//    public static final RemoteCacheManager connect() {
//       ConfigurationBuilder builder = connectionConfig();
// 
//       RemoteCacheManager cacheManager = new RemoteCacheManager(builder.build());
// 
//       // Clear the cache in case it already exists from a previous running tutorial
//       cacheManager.getCache(TUTORIAL_CACHE_NAME).clear();
// 
//       // Return the connected cache manager
//       return cacheManager;
//    }
// 
// }


import org.infinispan.client.hotrod.RemoteCacheManager;
import org.infinispan.client.hotrod.RemoteCounterManagerFactory;
import org.infinispan.counter.api.CounterConfiguration;
import org.infinispan.counter.api.CounterManager;
import org.infinispan.counter.api.CounterType;
import org.infinispan.counter.api.StrongCounter;
import org.infinispan.counter.api.WeakCounter;
import org.infinispan.tutorial.simple.connect.Infinispan;
         // Value is null since the counter is bounded and we can add 10 to it.
         System.out.println("Counter-1 Exception is " + throwable.getMessage());
         return 0;
      }).get();

      // Check the counter value. It should be the upper-bound (10)
      counter1.getValue().thenAccept(value -> System.out.println("Counter-1 value is " + value)).get();

      //Decrement the value. Should be 9.
      counter1.decrementAndGet().handle((value, throwable) -> {
         // No exception this time.
         System.out.println("Counter-1 new value is " + value);
         return value;
      }).get();

      // Similar to counter-1, counter-2 is a strong counter but it is unbounded. It will never throw the CounterOutOfBoundsException
      StrongCounter counter2 = counterManager.getStrongCounter("counter-2");

      // All counters allow a listener to be registered.
      // The handle can be used to remove the listener
      counter2.addListener(event -> System.out
            .println("Counter-2 event: oldValue=" + event.getOldValue() + " newValue=" + event.getNewValue()));

      // Adding MAX_VALUE won't throws an exception. But the all the increments won't have any effect since we can store
      //any value larger the MAX_VALUE
      counter2.addAndGet(Long.MAX_VALUE).thenAccept(aLong -> System.out.println("Counter-2 value is " + aLong)).get();

      // Conditional operations are allowed in strong counters
      counter2.compareAndSet(Long.MAX_VALUE, 0)
            .thenAccept(aBoolean -> System.out.println("Counter-2 CAS result is " + aBoolean)).get();
// Path: infinispan-remote/connect-to-infinispan-server/src/main/java/org/infinispan/tutorial/simple/connect/Infinispan.java
// public class Infinispan {
// 
//    public static final String USER = "admin";
//    public static final String PASSWORD = "password";
// 
//    public static final String TUTORIAL_CACHE_NAME = "test";
//    public static final String HOST = "127.0.0.1";
// 
//    public static final String TUTORIAL_CACHE_CONFIG =
//          "<distributed-cache name=\"CACHE_NAME\">\n"
//          + "    <encoding media-type=\"application/x-protostream\"/>\n"
//          + "</distributed-cache>";
// 
//    /**
//     * Returns the configuration builder with the connection information
//     *
//     * @return a Configuration Builder with the connection config
//     */
//    public static final ConfigurationBuilder connectionConfig() {
//       ConfigurationBuilder builder = new ConfigurationBuilder();
//       builder.addServer().host("127.0.0.1").port(ConfigurationProperties.DEFAULT_HOTROD_PORT).security()
//             .authentication()
//             //Add user credentials.
//             .username(USER)
//             .password(PASSWORD);
// 
//       // Docker 4 Mac Workaround. Don't use BASIC intelligence in production
//       builder.clientIntelligence(ClientIntelligence.BASIC);
// 
//       // Make sure the remote cache is available.
//       // If the cache does not exist, the cache will be created
//       builder.remoteCache(TUTORIAL_CACHE_NAME)
//             .configuration(TUTORIAL_CACHE_CONFIG.replace("CACHE_NAME", TUTORIAL_CACHE_NAME));
//       return builder;
//    }
// 
//    /**
//     * Connect to the running Infinispan Server in localhost:11222.
//     *
//     * This method illustrates how to connect to a running Infinispan Server with a downloaded
//     * distribution or a container.
//     *
//     * @return a connected RemoteCacheManager
//     */
//    public static final RemoteCacheManager connect() {
//       ConfigurationBuilder builder = connectionConfig();
// 
//       RemoteCacheManager cacheManager = new RemoteCacheManager(builder.build());
// 
//       // Clear the cache in case it already exists from a previous running tutorial
//       cacheManager.getCache(TUTORIAL_CACHE_NAME).clear();
// 
//       // Return the connected cache manager
//       return cacheManager;
//    }
// 
// }


// Path: infinispan-remote/counter/src/main/java/org/infinispan/tutorial/simple/remote/counter/InfinispanRemoteCounter.java
import org.infinispan.client.hotrod.RemoteCacheManager;
import org.infinispan.client.hotrod.RemoteCounterManagerFactory;
import org.infinispan.counter.api.CounterConfiguration;
import org.infinispan.counter.api.CounterManager;
import org.infinispan.counter.api.CounterType;
import org.infinispan.counter.api.StrongCounter;
import org.infinispan.counter.api.WeakCounter;
import org.infinispan.tutorial.simple.connect.Infinispan;

         // Value is null since the counter is bounded and we can add 10 to it.
         System.out.println("Counter-1 Exception is " + throwable.getMessage());
         return 0;
      }).get();

      // Check the counter value. It should be the upper-bound (10)
      counter1.getValue().thenAccept(value -> System.out.println("Counter-1 value is " + value)).get();

      //Decrement the value. Should be 9.
      counter1.decrementAndGet().handle((value, throwable) -> {
         // No exception this time.
         System.out.println("Counter-1 new value is " + value);
         return value;
      }).get();

      // Similar to counter-1, counter-2 is a strong counter but it is unbounded. It will never throw the CounterOutOfBoundsException
      StrongCounter counter2 = counterManager.getStrongCounter("counter-2");

      // All counters allow a listener to be registered.
      // The handle can be used to remove the listener
      counter2.addListener(event -> System.out
            .println("Counter-2 event: oldValue=" + event.getOldValue() + " newValue=" + event.getNewValue()));

      // Adding MAX_VALUE won't throws an exception. But the all the increments won't have any effect since we can store
      //any value larger the MAX_VALUE
      counter2.addAndGet(Long.MAX_VALUE).thenAccept(aLong -> System.out.println("Counter-2 value is " + aLong)).get();

      // Conditional operations are allowed in strong counters
      counter2.compareAndSet(Long.MAX_VALUE, 0)
            .thenAccept(aBoolean -> System.out.println("Counter-2 CAS result is " + aBoolean)).get();
      counter2.getValue().thenAccept(value -> System.out.println("Counter-2 value is " + value)).get();