Package net.sf.ehcache

Examples of net.sf.ehcache.CacheManager


    }

    @Test
    public void factory() {
        assertEquals(3, new EhCacheGaugeFactory().gauges().length);
        new CacheManager(new Configuration().name("other"));
        assertEquals(6, new EhCacheGaugeFactory().gauges().length);
    }
View Full Code Here


            ConfigurationFactory.parseConfiguration(EHCacheManagerHolder.class.getResource("/cxf-test-ehcache.xml"));
           
        assertNotNull(conf);
        conf.setName("testCache");
       
        CacheManager manager1 = EHCacheManagerHolder.createCacheManager(conf);
        assertNotNull(manager1);
        CacheManager manager2 = EHCacheManagerHolder.createCacheManager();
        assertNotNull(manager2);
       
        manager1.shutdown();
        assertEquals(Status.STATUS_SHUTDOWN, manager1.getStatus());
       
        assertEquals(Status.STATUS_ALIVE, manager2.getStatus());
       
        manager2.shutdown();
        assertEquals(Status.STATUS_SHUTDOWN, manager2.getStatus());
       
    }
View Full Code Here

        cc.setName(key);
        return cc;
    }
   
    public static CacheManager getCacheManager(Bus bus, URL configFileURL) {
        CacheManager cacheManager = null;
        if (configFileURL == null) {
            //using the default
            cacheManager = findDefaultCacheManager(bus);
        }
        if (cacheManager == null) {
            if (configFileURL == null) {
                cacheManager = createCacheManager();
            } else {
                cacheManager = createCacheManager(configFileURL);
            }
        }
        AtomicInteger a = COUNTS.get(cacheManager.getName());
        if (a == null) {
            COUNTS.putIfAbsent(cacheManager.getName(), new AtomicInteger());
            a = COUNTS.get(cacheManager.getName());
        }
        if (a.incrementAndGet() == 1) {
            //System.out.println("Create!! " + cacheManager.getName());
        }
        return cacheManager;
View Full Code Here

    }

    @Test
    public void testCache() throws Exception {
        // Is cache manager initialized before doing any routing?
        CacheManager cacheManager = cmfRef.getCacheManager();
        assertNull("CacheManager initialized", cacheManager);

        // Now do some routes to let endpoints be initialized
        template.sendBody("direct:add1", "Hello World");
        template.sendBody("direct:add2", "Hello World");
View Full Code Here

                in.setHeader(CacheConstants.CACHE_KEY, "greeting");
                in.setBody("Hello World");
            }
        });
       
        CacheManager cm = cacheEndpoint.getCacheManagerFactory().getInstance();
        Cache cache = cm.getCache(cacheEndpoint.getConfig().getCacheName());
        Set<CacheEventListener> ehcacheEventListners = cache.getCacheEventNotificationService().getCacheEventListeners();
        List<CacheLoader> cacheLoaders = cache.getRegisteredCacheLoaders();
        CacheEventListenerRegistry configuredEventRegistry = cacheEndpoint.getConfig().getEventListenerRegistry();
        CacheLoaderRegistry configuredLoaderRegistry = cacheEndpoint.getConfig().getCacheLoaderRegistry();
View Full Code Here

        // Now do some routes to let endpoints be initialized
        template.sendBody("direct:add1", "Hello World");
        template.sendBody("direct:add2", "Hello World");

        //Now should not be null
        CacheManager cacheManager = cmfRef.getCacheManager();
        assertNotNull("CacheManager initialized", cacheManager);

        Cache cache = cmfRef.getCacheManager().getCache("foo");

        // Is cache alive
View Full Code Here

    @Test
   
    public void testEHCacheCompatiblity() throws Exception {
        // get the default cache manager
        CacheManagerFactory factory = new DefaultCacheManagerFactory();
        CacheManager manager = factory.getInstance();
        assertEquals(Status.STATUS_ALIVE, manager.getStatus());
       
        // create another unrelated cache manager
        Configuration conf =
            ConfigurationFactory.parseConfiguration(DefaultCacheManagerFactory.class.getResource("/test-ehcache.xml"));
        assertNotNull(conf);
        conf.setName("otherCache");
        CacheManager other = CacheManager.create(conf);
        assertEquals(Status.STATUS_ALIVE, other.getStatus());
       
        // shutdown this unrelated cache manager
        other.shutdown();
        assertEquals(Status.STATUS_SHUTDOWN, other.getStatus());
       
        // the default cache manager should be still running
        assertEquals(Status.STATUS_ALIVE, manager.getStatus());
       
        factory.doStop();
View Full Code Here

     * Returns {@link Cache} instance or create new one if not exists.
     *
     * @return {@link Cache}
     */
    public Ehcache initializeCache() {
        CacheManager cacheManager = getCacheManagerFactory().getInstance();
        Ehcache cache;
        if (cacheManager.cacheExists(config.getCacheName())) {
            if (LOG.isTraceEnabled()) {
                LOG.trace("Found an existing cache: {}", config.getCacheName());
                LOG.trace("Cache {} currently contains {} elements",
                        config.getCacheName(),
                        cacheManager.getEhcache(config.getCacheName()).getSize());
            }
            cache = cacheManager.getEhcache(config.getCacheName());
        } else {
            cache = new Cache(config.getCacheName(),
                    config.getMaxElementsInMemory(),
                    config.getMemoryStoreEvictionPolicy(),
                    config.isOverflowToDisk(),
                    config.getDiskStorePath(),
                    config.isEternal(),
                    config.getTimeToLiveSeconds(),
                    config.getTimeToIdleSeconds(),
                    config.isDiskPersistent(),
                    config.getDiskExpiryThreadIntervalSeconds(),
                    null);

            for (CacheEventListener listener : config.getEventListenerRegistry().getEventListeners()) {
                cache.getCacheEventNotificationService().registerListener(listener);
            }

            for (CacheLoaderWrapper loader : config.getCacheLoaderRegistry().getCacheLoaders()) {
                loader.init(cache);
                cache.registerCacheLoader(loader);
            }

            cacheManager.addCache(cache);

            if (LOG.isDebugEnabled()) {
                LOG.debug("Added a new cache: " + cache.getName());
            }
        }
View Full Code Here

        return cache;
    }

    @Override
    public void stop() {
        CacheManager cacheManager = getCacheManagerFactory().getInstance();
        cacheManager.removeCache(config.getCacheName());
    }
View Full Code Here

  public ResourceDataCache createDataCache()
  {
    try
    {
      final CacheManager manager = getCacheManager();
      synchronized(manager)
      {
        if (manager.cacheExists("libloader-data") == false)
        {
          manager.addCache("libloader-data");
        }
        return new EHResourceDataCache(manager.getCache("libloader-data"));
      }
    }
    catch (CacheException e)
    {
      return null;
View Full Code Here

TOP

Related Classes of net.sf.ehcache.CacheManager

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.