Package net.sf.ehcache

Examples of net.sf.ehcache.CacheManager


  @Test
  public void testOffHeapExceedMemory()
          throws IOException {
    Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
    CacheManager cacheManager = CacheManager.getInstance();
    Ehcache ehcache = cacheManager.getEhcache("testCache");
    Element element = null;
    try {
      for (int i = 0; i < 3000000; i++) {
        if ((i % 1000) == 0) {
          System.out.println("heatbeat 2 " + i);
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

    EhCacheDataCache dataCache = new EhCacheDataCache();
    DataCacheKey key = new DataCacheKey();
    key.addAttribute("Test", "test");
    dataCache.put(key, new DefaultTableModel());

    final CacheManager cacheManager = CacheManager.getInstance();
    // Note: EHCacheProvider will dynamically create these
    // caches if they don't exist.
    cacheManager.clearAll();
    cacheManager.removalAll();

    assertFalse(cacheManager.cacheExists("libloader-bundles"));
    assertFalse(cacheManager.cacheExists("libloader-data"));
    assertFalse(cacheManager.cacheExists("libloader-factory"));
    assertFalse(cacheManager.cacheExists("report-dataset-cache"));

    cacheManager.shutdown();

    assertNull(dataCache.get(key));
    dataCache.put(key, new DefaultTableModel());
    assertNotNull(dataCache.get(key));
View Full Code Here

    EhCacheDataCache dataCache = new EhCacheDataCache();
    DataCacheKey key = new DataCacheKey();
    key.addAttribute("Test", "test");
    dataCache.put(key, new DefaultTableModel());

    final CacheManager cacheManager = CacheManager.getInstance();
    // Note: EHCacheProvider will dynamically create these
    // caches if they don't exist.
    cacheManager.clearAll();
    cacheManager.removalAll();

    assertFalse(cacheManager.cacheExists("libloader-bundles"));
    assertFalse(cacheManager.cacheExists("libloader-data"));
    assertFalse(cacheManager.cacheExists("libloader-factory"));
    assertFalse(cacheManager.cacheExists("report-dataset-cache"));

    assertNull(dataCache.get(key));
    dataCache.put(key, new DefaultTableModel());
    assertNotNull(dataCache.get(key));
View Full Code Here

  }

  protected CacheManager createCacheManager()
  {
    return new CacheManager();
  }
View Full Code Here

            if ( properties != null ) {
                configurationResourceName = (String) properties.get( NET_SF_EHCACHE_CONFIGURATION_RESOURCE_NAME );
            }
            if ( configurationResourceName == null || configurationResourceName.length() == 0 ) {
                Configuration configuration = ConfigurationFactory.parseConfiguration();
                manager = new CacheManager( configuration );
            }
            else {
                URL url;
                try {
                    url = new URL( configurationResourceName );
                }
                catch ( MalformedURLException e ) {
                    url = loadResource( configurationResourceName );
                }
                Configuration configuration = HibernateUtil.loadAndCorrectConfiguration( url );
                manager = new CacheManager( configuration );
            }
            mbeanRegistrationHelper.registerMBean( manager, properties );
        }
        catch ( net.sf.ehcache.CacheException e ) {
            if ( e.getMessage().startsWith(
View Full Code Here

            String configurationResourceName = null;
            if (properties != null) {
                configurationResourceName = (String) properties.get( Environment.CACHE_PROVIDER_CONFIG );
            }
            if ( StringHelper.isEmpty( configurationResourceName ) ) {
                manager = new CacheManager();
            } else {
                URL url = loadResource(configurationResourceName);
                manager = new CacheManager(url);
            }
        } catch (net.sf.ehcache.CacheException e) {
      //yukky! Don't you have subclasses for that!
      //TODO race conditions can happen here
      if (e.getMessage().startsWith("Cannot parseConfiguration CacheManager. Attempt to create a new instance of " +
View Full Code Here

  public ResourceDataCache createDataCache()
  {
    try
    {
      final CacheManager manager = getCacheManager();
      synchronized(manager)
      {
        if (manager.cacheExists(DATA_CACHE_NAME) == false)
        {
          final Cache libloaderCache = new Cache(DATA_CACHE_NAME,   // cache name
                                                 500,         // maxElementsInMemory
                                                 false,       // overflowToDisk
                                                 false,       // eternal
                                                 600,         // timeToLiveSeconds
                                                 600,         // timeToIdleSeconds
                                                 false,       // diskPersistent
                                                 120);        // diskExpiryThreadIntervalSeconds
          manager.addCache(libloaderCache);
          return new EHResourceDataCache(libloaderCache);
        }
        else
        {
          return new EHResourceDataCache(manager.getCache(DATA_CACHE_NAME));
        }
      }
    }
    catch (CacheException e)
    {
View Full Code Here

  public ResourceBundleDataCache createBundleDataCache()
  {
    try
    {
      final CacheManager manager = getCacheManager();
      synchronized(manager)
      {
        if (manager.cacheExists(BUNDLES_CACHE_NAME) == false)
        {
          final Cache libloaderCache = new Cache(BUNDLES_CACHE_NAME,   // cache name
                                                 500,         // maxElementsInMemory
                                                 false,       // overflowToDisk
                                                 false,       // eternal
                                                 600,         // timeToLiveSeconds
                                                 600,         // timeToIdleSeconds
                                                 false,       // diskPersistent
                                                 120);        // diskExpiryThreadIntervalSeconds
          manager.addCache(libloaderCache);
          return new EHResourceBundleDataCache(libloaderCache);
        } else
        {
          return new EHResourceBundleDataCache(manager.getCache(BUNDLES_CACHE_NAME));
        }
      }
    }
    catch (CacheException e)
    {
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.