Package org.infinispan.manager

Examples of org.infinispan.manager.EmbeddedCacheManager


   }
  
   @Override
   public boolean isDistributed()
   {
      EmbeddedCacheManager container = (EmbeddedCacheManager) this.container;
      Configuration config = (this.cacheName != null) ? container.defineConfiguration(this.cacheName, new Configuration()) : container.getDefaultConfiguration();
      return config.getCacheMode().isDistributed();
   }
View Full Code Here


   @Override
   public void getCache(String regionPrefix)
   {
      try
      {
         EmbeddedCacheManager container = DefaultCacheContainerRegistry.getInstance().getCacheContainer("hibernate");
         for (String cacheName: container.getCacheNames())
         {
            if (cacheName.startsWith(regionPrefix))
            {
               Cache<?, ?> cache = container.getCache(cacheName);
               cache.addListener(this);
               caches.add(cache);
            }
         }
         container.addListener(this);
      }
      catch (Exception e)
      {
         throw new RuntimeException(e);
      }
View Full Code Here

         managerConfig.setCacheLoaderConfigs(Collections.<CacheLoaderConfig>singletonList(fileConfig));
        
         config.setCacheLoaderManagerConfig(managerConfig);
      }
     
      final EmbeddedCacheManager sessionContainer = new DefaultCacheManager(global, config, false);
     
      global = local ? GlobalConfiguration.getNonClusteredDefault() : GlobalConfiguration.getClusteredDefault();
      global.setClusterName("testing-jvmroute");
      global.setCacheManagerName("container" + containerIndex++);
      global.setStrictPeerToPeer(false);
     
      config = new Configuration();
      config.setInvocationBatchingEnabled(true);
      config.setIsolationLevel(IsolationLevel.REPEATABLE_READ);
      config.setSyncReplTimeout(20000);
      config.setLockAcquisitionTimeout(15000);
      config.setCacheMode(CacheMode.REPL_SYNC);
      config.setFetchInMemoryState(true);
      config.setSyncCommitPhase(true);
      config.setSyncRollbackPhase(true);
     
      final EmbeddedCacheManager jvmRouteContainer = new DefaultCacheManager(global, config, false);
     
      return new EmbeddedCacheManager()
      {
         @Override
         public <K, V> Cache<K, V> getCache()
         {
            return sessionContainer.getCache();
         }

         @Override
         public <K, V> Cache<K, V> getCache(String cacheName)
         {
            return cacheName.equals("jboss.web") ? jvmRouteContainer.<K, V>getCache() : sessionContainer.<K, V>getCache(cacheName);
         }

         @Override
         public void start()
         {
            jvmRouteContainer.start();
            sessionContainer.start();
         }

         @Override
         public void stop()
         {
            sessionContainer.stop();
            jvmRouteContainer.stop();
         }

         @Override
         public void addListener(Object listener)
         {
            sessionContainer.addListener(listener);
         }

         @Override
         public void removeListener(Object listener)
         {
            sessionContainer.removeListener(listener);
         }

         @Override
         public Set<Object> getListeners()
         {
            return sessionContainer.getListeners();
         }

         @Override
         public Configuration defineConfiguration(String cacheName, Configuration configurationOverride)
         {
            return sessionContainer.defineConfiguration(cacheName, configurationOverride);
         }

         @Override
         public Configuration defineConfiguration(String cacheName, String templateCacheName, Configuration configurationOverride)
         {
            return sessionContainer.defineConfiguration(cacheName, templateCacheName, configurationOverride);
         }

         @Override
         public String getClusterName()
         {
            return sessionContainer.getClusterName();
         }

         @Override
         public List<Address> getMembers()
         {
            return sessionContainer.getMembers();
         }

         @Override
         public Address getAddress()
         {
            return sessionContainer.getAddress();
         }

         @Override
         public boolean isCoordinator()
         {
            return sessionContainer.isCoordinator();
         }

         @Override
         public ComponentStatus getStatus()
         {
            return sessionContainer.getStatus();
         }

         @Override
         public GlobalConfiguration getGlobalConfiguration()
         {
            return sessionContainer.getGlobalConfiguration();
         }

         @Override
         public Configuration getDefaultConfiguration()
         {
            return sessionContainer.getDefaultConfiguration();
         }

         @Override
         public Set<String> getCacheNames()
         {
            return sessionContainer.getCacheNames();
         }

         @Override
         public Address getCoordinator()
         {
            return sessionContainer.getCoordinator();
         }

         @Override
         public boolean isRunning(String cacheName)
         {
            return cacheName.equals("jboss.web") ? jvmRouteContainer.isDefaultRunning() : sessionContainer.isRunning(cacheName);
         }

         @Override
         public boolean isDefaultRunning()
         {
View Full Code Here

   private List<Cache<?, ?>> caches = new LinkedList<Cache<?, ?>>();
  
   @Override
   public void getCache(String regionPrefix)
   {
      EmbeddedCacheManager container = DefaultCacheContainerRegistry.getInstance().getCacheContainer("hibernate");
      for (String cacheName: container.getCacheNames())
      {
         if (cacheName.startsWith(regionPrefix))
         {
            Cache<?, ?> cache = container.getCache(cacheName);
            cache.addListener(this);
            caches.add(cache);
         }
      }
   }
View Full Code Here

   protected EmbeddedCacheManager createCacheManager(Properties properties) throws CacheException {
      try {
         String configLoc = ConfigurationHelper.getString(INFINISPAN_CONFIG_RESOURCE_PROP, properties, DEF_INFINISPAN_CONFIG_RESOURCE);

         EmbeddedCacheManager manager = new DefaultCacheManager(configLoc, false);
         String globalStats = extractProperty(INFINISPAN_GLOBAL_STATISTICS_PROP, properties);
         if (globalStats != null) {
            // Hack to enable global JMX stats being enabled in both 5.1 and 5.2

            // 1. Create a configuration builder holder
            ConfigurationBuilderHolder holder = new ConfigurationBuilderHolder();

            // 2. Build global configuration with custom settings
            GlobalConfigurationBuilder globalBuilder = holder.getGlobalConfigurationBuilder();
            globalBuilder.read(manager.getCacheManagerConfiguration());
            globalBuilder.globalJmxStatistics().enabled(Boolean.parseBoolean(globalStats));

            // 3. Build default configuration
            holder.getDefaultConfigurationBuilder().read(manager.getDefaultCacheConfiguration());

            // 4. Build all defined caches
            for (String cacheName : manager.getCacheNames()){
               ConfigurationBuilder builder = holder.newConfigurationBuilder(cacheName);
               builder.read(manager.getCacheConfiguration(cacheName));
            }

            // 5. Discard existing cache manager and create a brand new one
            manager.stop();
            manager = new DefaultCacheManager(holder, false);
         }

         manager.start();
         return manager;
      } catch (IOException e) {
         throw new CacheException("Unable to create default cache manager", e);
      }
   }
View Full Code Here

public class JDBCCacheLoaderTest {

  public static void main(String[] args) throws Exception {

    EmbeddedCacheManager cacheManager = new DefaultCacheManager("infinispan-loaders-mysql.xml");
   
    stringBasedTest(cacheManager);
   
    Cache<Object, Object> cache = cacheManager.getCache("custom-cache-loader");
   
    for(int i = 1 ; i <= 15 ; i ++){
      cache.put(i, UUID.randomUUID().toString());
    }
   
View Full Code Here

public class ProgrammaticConfiguration {

  public static void main(String[] args) throws IOException {

    EmbeddedCacheManager manager = new DefaultCacheManager();
//    Cache defaultCache = manager.getCache();
   
    Configuration c = new ConfigurationBuilder().clustering().cacheMode(CacheMode.REPL_SYNC).build();
   
    String newCacheName = "repl";
    manager.defineConfiguration(newCacheName, c);
    Cache<String, String> cache = manager.getCache(newCacheName);
  }
View Full Code Here

  private EmbeddedCacheManager createCustomCacheManager(URL configUrl, JtaPlatform platform) {
    TransactionManagerLookupDelegator transactionManagerLookupDelegator = new TransactionManagerLookupDelegator( platform );
    try {
      InputStream configurationFile = configUrl.openStream();
      try {
        EmbeddedCacheManager tmpCacheManager = new DefaultCacheManager( configurationFile, false );

        AdvancedExternalizer<?> entityKeyExternalizer = EntityKeyExternalizer.INSTANCE;
        AdvancedExternalizer<?> associationKeyExternalizer = AssociationKeyExternalizer.INSTANCE;
        AdvancedExternalizer<?> rowKeyExternalizer = RowKeyExternalizer.INSTANCE;
        AdvancedExternalizer<?> entityKeyMetadataExternalizer = EntityKeyMetadataExternalizer.INSTANCE;
        AdvancedExternalizer<?> idGeneratorKeyExternalizer = IdSourceKeyExternalizer.INSTANCE;

        // override global configuration from the config file to inject externalizers
        GlobalConfiguration globalConfiguration = new GlobalConfigurationBuilder()
          .read( tmpCacheManager.getCacheManagerConfiguration() )
          .serialization()
            .addAdvancedExternalizer( entityKeyExternalizer.getId(), entityKeyExternalizer )
            .addAdvancedExternalizer( associationKeyExternalizer.getId(), associationKeyExternalizer )
            .addAdvancedExternalizer( rowKeyExternalizer.getId(), rowKeyExternalizer )
            .addAdvancedExternalizer( entityKeyMetadataExternalizer.getId(), entityKeyMetadataExternalizer )
            .addAdvancedExternalizer( idGeneratorKeyExternalizer.getId(), idGeneratorKeyExternalizer )
          .build();

        cacheManager = new DefaultCacheManager( globalConfiguration, false );

        // override the named cache configuration defined in the configuration file to
        // inject the platform TransactionManager
        for (String cacheName : tmpCacheManager.getCacheNames() ) {
          Configuration originalCfg = tmpCacheManager.getCacheConfiguration( cacheName );
          Configuration newCfg = new ConfigurationBuilder()
            .read( originalCfg )
              .transaction()
                .transactionManagerLookup( transactionManagerLookupDelegator )
            .build();
View Full Code Here

public class FileCacheLoaderTest {

  public static void main(String[] args) throws IOException {
   
    EmbeddedCacheManager cacheManager = new DefaultCacheManager("infinispan-loaders-file.xml");
   
    Cache<Object, Object> cache = cacheManager.getCache("custom-cache-loader");
   
    for(int i = 1 ; i <= 15 ; i ++){
      cache.put(i, UUID.randomUUID().toString());
    }
   
    log("Total entities in cache: " + cache.size());
   
    printCacheEntities(cache);
   
    cache.stop();
   
    cacheManager.stop();
  }
View Full Code Here

 
  Cache<Object, Object> cache;

  @Before
  public void setup() {
    EmbeddedCacheManager manager = new DefaultCacheManager();
    manager.defineConfiguration("custom-cache", new ConfigurationBuilder()
        .eviction().strategy(EvictionStrategy.LIRS).maxEntries(10)
        .build());
    cache = manager.getCache("custom-cache");
  }
View Full Code Here

TOP

Related Classes of org.infinispan.manager.EmbeddedCacheManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.