Search in sources :

Example 11 with DefaultCacheManager

use of org.infinispan.manager.DefaultCacheManager in project galley by Commonjava.

the class RoutingCacheProviderWrapperTest method prepare.

@Before
public void prepare() throws Exception {
    final File cacheDir = temp.newFolder();
    partylineFac = new PartyLineCacheProviderFactory(cacheDir);
    SimpleCacheInstance<String, String> cacheInstance = new SimpleCacheInstance<>("test", new DefaultCacheManager().getCache());
    fastLocalFac = new FastLocalCacheProviderFactory(cacheDir, temp.newFolder(), cacheInstance, Executors.newFixedThreadPool(5));
}
Also used : PartyLineCacheProviderFactory(org.commonjava.maven.galley.cache.partyline.PartyLineCacheProviderFactory) DefaultCacheManager(org.infinispan.manager.DefaultCacheManager) FastLocalCacheProviderFactory(org.commonjava.maven.galley.cache.infinispan.FastLocalCacheProviderFactory) File(java.io.File) SimpleCacheInstance(org.commonjava.maven.galley.cache.infinispan.SimpleCacheInstance) Before(org.junit.Before)

Example 12 with DefaultCacheManager

use of org.infinispan.manager.DefaultCacheManager in project galley by Commonjava.

the class NFSOwnerCacheProducer method getCacheMgr.

public EmbeddedCacheManager getCacheMgr() {
    final EmbeddedCacheManager cacheManager = new DefaultCacheManager(new GlobalConfigurationBuilder().globalJmxStatistics().jmxDomain("org.commonjava.maven.galley").build());
    // Want to enable dead lock check as lock will be used in FastLocalCacheProvider
    // and also set transaction mode to PESSIMISTIC with DummyTransactionManger.
    final Configuration configuration = new ConfigurationBuilder().eviction().strategy(EvictionStrategy.LRU).size(1000).type(EvictionType.COUNT).deadlockDetection().spinDuration(10, TimeUnit.SECONDS).enable().transaction().transactionManagerLookup(new DummyTransactionManagerLookup()).lockingMode(LockingMode.PESSIMISTIC).build();
    cacheManager.defineConfiguration(CACHE_NAME, configuration);
    return cacheManager;
}
Also used : GlobalConfigurationBuilder(org.infinispan.configuration.global.GlobalConfigurationBuilder) DummyTransactionManagerLookup(org.infinispan.transaction.lookup.DummyTransactionManagerLookup) DefaultCacheManager(org.infinispan.manager.DefaultCacheManager) ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) GlobalConfigurationBuilder(org.infinispan.configuration.global.GlobalConfigurationBuilder) Configuration(org.infinispan.configuration.cache.Configuration) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager)

Example 13 with DefaultCacheManager

use of org.infinispan.manager.DefaultCacheManager in project sling by apache.

the class CacheManagerServiceImpl method activate.

@Activate
public void activate(Map<String, Object> properties) throws FileNotFoundException, IOException {
    String config = toString(properties.get(CACHE_CONFIG), DEFAULT_CACHE_CONFIG);
    File configFile = new File(config);
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    try {
        Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
        if (configFile.exists()) {
            LOGGER.info("Configuring Cache from {} ", configFile.getAbsolutePath());
            InputStream in = null;
            try {
                in = processConfig(new FileInputStream(configFile), properties);
                cacheManager = new DefaultCacheManager(in);
            } finally {
                if (in != null) {
                    in.close();
                }
            }
        } else {
            LOGGER.info("Configuring Cache from Classpath Default {} ", CONFIG_PATH);
            InputStream in = processConfig(this.getClass().getClassLoader().getResourceAsStream(CONFIG_PATH), properties);
            if (in == null) {
                throw new IOException("Unable to open config at classpath location " + CONFIG_PATH);
            }
            cacheManager = new DefaultCacheManager(in);
            in.close();
        }
    } finally {
        Thread.currentThread().setContextClassLoader(cl);
    }
    final WeakReference<CacheManagerServiceImpl> ref = new WeakReference<CacheManagerServiceImpl>(this);
    /*
		 * Add in a shutdown hook, for safety
		 */
    Runtime.getRuntime().addShutdownHook(new Thread() {

        /*
			 * (non-Javadoc)
			 * 
			 * @see java.lang.Thread#run()
			 */
        @Override
        public void run() {
            try {
                CacheManagerServiceImpl cm = ref.get();
                if (cm != null) {
                    cm.deactivate();
                }
            } catch (Throwable t) {
                LOGGER.debug(t.getMessage(), t);
            }
        }
    });
// JMX Registration is performed by configuration
}
Also used : DefaultCacheManager(org.infinispan.manager.DefaultCacheManager) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) WeakReference(java.lang.ref.WeakReference) File(java.io.File) Activate(org.apache.felix.scr.annotations.Activate)

Example 14 with DefaultCacheManager

use of org.infinispan.manager.DefaultCacheManager in project hibernate-orm by hibernate.

the class TestInfinispanRegionFactory method createCacheManager.

@Override
protected EmbeddedCacheManager createCacheManager(ConfigurationBuilderHolder holder) {
    // If the cache manager has been provided by calling setCacheManager, don't create a new one
    EmbeddedCacheManager cacheManager = getCacheManager();
    if (cacheManager != null) {
        return cacheManager;
    }
    amendConfiguration(holder);
    cacheManager = new DefaultCacheManager(holder, true);
    if (timeService != null) {
        cacheManager.getGlobalComponentRegistry().registerComponent(timeService, TimeService.class);
        cacheManager.getGlobalComponentRegistry().rewire();
    }
    return cacheManager;
}
Also used : DefaultCacheManager(org.infinispan.manager.DefaultCacheManager) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager)

Example 15 with DefaultCacheManager

use of org.infinispan.manager.DefaultCacheManager in project camel by apache.

the class InfinispanTestSupport method setUp.

@Override
@Before
public void setUp() throws Exception {
    basicCacheContainer = new DefaultCacheManager();
    basicCacheContainer.start();
    super.setUp();
}
Also used : DefaultCacheManager(org.infinispan.manager.DefaultCacheManager) Before(org.junit.Before)

Aggregations

DefaultCacheManager (org.infinispan.manager.DefaultCacheManager)18 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)7 BeforeClass (org.junit.BeforeClass)5 Before (org.junit.Before)4 File (java.io.File)3 InputStream (java.io.InputStream)3 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)3 IOException (java.io.IOException)2 Properties (java.util.Properties)2 GlobalConfigurationBuilder (org.infinispan.configuration.global.GlobalConfigurationBuilder)2 Test (org.junit.Test)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileInputStream (java.io.FileInputStream)1 WeakReference (java.lang.ref.WeakReference)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Consumer (java.util.function.Consumer)1 Function (java.util.function.Function)1 Supplier (java.util.function.Supplier)1 PostConstruct (javax.annotation.PostConstruct)1