All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.infinispan.counter.EmbeddedCounterManagerFactory Maven / Gradle / Ivy

There is a newer version: 15.1.0.Dev05
Show newest version
package org.infinispan.counter;

import static java.util.Objects.requireNonNull;

import org.infinispan.commons.IllegalLifecycleStateException;
import org.infinispan.counter.api.CounterManager;
import org.infinispan.factories.impl.BasicComponentRegistry;
import org.infinispan.factories.impl.ComponentRef;
import org.infinispan.lifecycle.ComponentStatus;
import org.infinispan.manager.EmbeddedCacheManager;
import org.infinispan.security.actions.SecurityActions;

/**
 * A {@link CounterManager} factory for embedded cached.
 *
 * @author Pedro Ruivo
 * @since 9.0
 */
public final class EmbeddedCounterManagerFactory {

   private EmbeddedCounterManagerFactory() {
   }

   /**
    * @return the {@link CounterManager} associated to the {@link EmbeddedCacheManager}.
    * @throws IllegalLifecycleStateException if the cache manager is not running
    */
   public static CounterManager asCounterManager(EmbeddedCacheManager cacheManager) {
      requireNonNull(cacheManager, "EmbeddedCacheManager can't be null.");

      if (cacheManager.getStatus() != ComponentStatus.RUNNING)
         throw new IllegalLifecycleStateException();

      ComponentRef component = SecurityActions.getGlobalComponentRegistry(cacheManager)
            .getComponent(BasicComponentRegistry.class)
            .getComponent(CounterManager.class);
      if (component == null) {
         return null;
      }

      return component.running();
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy