Package org.jboss.cache.config

Examples of org.jboss.cache.config.EvictionRegionConfig


   }

   private void addStringBasedRegion() throws Exception
   {
      LRUAlgorithmConfig lru = new LRUAlgorithmConfig(150, 0, 1000);
      EvictionRegionConfig regConfig = new EvictionRegionConfig(Fqn.fromString("/dummy"), lru);

      RegionManager regionManager = cache.getRegionManager();
      EvictionConfig topConfig = cache.getConfiguration().getEvictionConfig();
      topConfig.addEvictionRegionConfig(regConfig);
      regionManager.setEvictionConfig(topConfig);
View Full Code Here


   }

   private void addObjectBasedRegion() throws Exception
   {
      LRUAlgorithmConfig lru = new LRUAlgorithmConfig(150, 1000);
      EvictionRegionConfig regConfig = new EvictionRegionConfig(Fqn.fromElements(1), lru);

      RegionManager regionManager = cache.getRegionManager();
      EvictionConfig topConfig = cache.getConfiguration().getEvictionConfig();
      topConfig.addEvictionRegionConfig(regConfig);
      regionManager.setEvictionConfig(topConfig);
View Full Code Here

   {
      Configuration config = UnitTestConfigurationFactory.createConfiguration(Configuration.CacheMode.LOCAL, true);
      EvictionConfig evConfig = config.getEvictionConfig();
      evConfig.setWakeupInterval(200);
      // root ERC
      evConfig.setDefaultEvictionRegionConfig(new EvictionRegionConfig(Fqn.ROOT, new MRUAlgorithmConfig(100), 200000));
      // new region ERC
      evConfig.addEvictionRegionConfig(new EvictionRegionConfig(Fqn.fromString("/org/jboss/test/data"), new MRUAlgorithmConfig(6)));


      config.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
      config.setIsolationLevel(IsolationLevel.SERIALIZABLE);
      cache = (CacheSPI<Object, Object>) new UnitTestCacheFactory<Object, Object>().createCache(config, getClass());
View Full Code Here

   }

   void initCaches() throws Exception
   {
      Configuration conf = UnitTestConfigurationFactory.createConfiguration(Configuration.CacheMode.LOCAL, true);
      EvictionConfig evConfig = new EvictionConfig(new EvictionRegionConfig(Fqn.ROOT, new ElementSizeAlgorithmConfig(5000, 100), 200000), -1);
      evConfig.addEvictionRegionConfig(new EvictionRegionConfig(Fqn.fromString("/org/jboss/data"), new ElementSizeAlgorithmConfig(10, 20)));
      evConfig.addEvictionRegionConfig(new EvictionRegionConfig(Fqn.fromString("/org/jboss/test/data"), new ElementSizeAlgorithmConfig(-1, 5)));
      evConfig.addEvictionRegionConfig(new EvictionRegionConfig(Fqn.fromString("/test/"), new ElementSizeAlgorithmConfig(5000, 1)));
      conf.setEvictionConfig(evConfig);
      cache = (CacheSPI<Object, Object>) new UnitTestCacheFactory<Object, Object>().createCache(conf, false, getClass());
      cache.getConfiguration().setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
      cache.getConfiguration().setIsolationLevel(IsolationLevel.SERIALIZABLE);
      cache.start();
View Full Code Here

   {
      CacheFactory factory = new DefaultCacheFactory();
      ExpirationAlgorithmConfig exp = new ExpirationAlgorithmConfig();
      exp.setMaxNodes(maxSize);

      EvictionRegionConfig evictionRegionConfig = new EvictionRegionConfig(RegionManagerImpl.DEFAULT_REGION);
      evictionRegionConfig.setEvictionAlgorithmConfig(exp);

      EvictionConfig evictConfig = new EvictionConfig();
      evictConfig.setDefaultEvictionRegionConfig(evictionRegionConfig);
      evictConfig.setWakeupInterval(wakeupInterval);
View Full Code Here

                    }
                }
            }
        } else {
            Configuration configuration = new Configuration();
            EvictionRegionConfig evictionRegionConfig = new EvictionRegionConfig(Fqn.root());
            ExpirationAlgorithmConfig expirationAlgorithm = new ExpirationAlgorithmConfig();
            int maxCacheSize = getIntConfigurationValue(facesContext, CoreConfiguration.Items.resourcesCacheSize);
            expirationAlgorithm.setMaxNodes(maxCacheSize);

            evictionRegionConfig.setEvictionAlgorithmConfig(expirationAlgorithm);

            EvictionConfig evictionConfig = new EvictionConfig(evictionRegionConfig);

            evictionConfig.setWakeupInterval(1000);
            configuration.setEvictionConfig(evictionConfig);
View Full Code Here

      EvictionConfig ec = cfg.getEvictionConfig();
      // Create the region and set the config
      Region region = cache.getRegion(fqn, true);
      if (ec != null && ec.getDefaultEvictionRegionConfig() != null)
      {
         EvictionRegionConfig erc = new EvictionRegionConfig(fqn);
         erc.setDefaults(ec.getDefaultEvictionRegionConfig());
         region.setEvictionRegionConfig(erc);
      }
   }
View Full Code Here

      evictionConfig = configuration.getEvictionConfig();
      if (evictionConfig != null && evictionConfig.isValidConfig())
      {
         this.evictionConfig = configuration.getEvictionConfig();
         // start with the default region
         EvictionRegionConfig defaultRegion = configuration.getEvictionConfig().getDefaultEvictionRegionConfig();
         if (defaultRegion.getEvictionAlgorithmConfig() != null) defaultRegion.getEvictionAlgorithmConfig().validate();

         // validate individual region configs now
         for (EvictionRegionConfig erc : configuration.getEvictionConfig().getEvictionRegionConfigs())
         {
            evictionConfig.applyDefaults(erc);
View Full Code Here

      List<EvictionRegionConfig> evictionRegionConfigs = new LinkedList<EvictionRegionConfig>();
      Element defaultRegion = getSingleElementInCoreNS("default", evictionElement);

      if (defaultRegion != null)
      {
         EvictionRegionConfig defaultRegionConfig = getEvictionRegionConfig(defaultRegion, null, true);
         if (defaultRegionConfig.getEvictionAlgorithmConfig() == null)
            throw new MissingPolicyException("Default eviction region should have an evictionAlgorithmClass defined.");
         evictionConfig.setDefaultEvictionRegionConfig(defaultRegionConfig);
      }

      NodeList regions = evictionElement.getElementsByTagName("region");
      for (int i = 0; i < regions.getLength(); i++)
      {
         Element regionConfig = (Element) regions.item(i);
         EvictionRegionConfig erc = getEvictionRegionConfig(regionConfig, evictionConfig.getDefaultEvictionRegionConfig(), false);
         evictionConfig.applyDefaults(erc);
         evictionRegionConfigs.add(erc);
      }
      evictionConfig.setEvictionRegionConfigs(evictionRegionConfigs);
      return evictionConfig;
View Full Code Here

   }

   @SuppressWarnings("unchecked")
   private EvictionRegionConfig getEvictionRegionConfig(Element element, EvictionRegionConfig defaultRegion, boolean isDefault)
   {
      EvictionRegionConfig erc = new EvictionRegionConfig();
      erc.setRegionName(getAttributeValue(element, "name"));
      String queueSize = getAttributeValue(element, "eventQueueSize");
      if (existsAttribute(queueSize))
      {
         erc.setEventQueueSize(getInt(queueSize));
      }
      else if (defaultRegion == null)
      {
         erc.setEventQueueSize(EvictionConfig.EVENT_QUEUE_SIZE_DEFAULT);
      }

      String algorithmClassName = getAttributeValue(element, "algorithmClass");
      EvictionAlgorithmConfig algorithmConfig = null; // every eviction region config needs an algorithm config.

      if (existsAttribute(algorithmClassName))
      {
         EvictionAlgorithm algorithm;
         Class<? extends EvictionAlgorithm> algorithmClass;
         // try using a 'getInstance()' factory.

         try
         {
            algorithmClass = Util.loadClass(algorithmClassName);
         }
         catch (Exception e)
         {
            throw new RuntimeException("Unable to load eviction algorithm class [" + algorithmClassName + "]", e);
         }


         try
         {
            algorithm = Util.getInstance(algorithmClass);
         }
         catch (Exception e)
         {
            throw new ConfigurationException("Unable to construct eviction algorithm class [" + algorithmClassName + "]", e);
         }

         try
         {
            algorithmConfig = Util.getInstance(algorithm.getConfigurationClass());
         }
         catch (Exception e)
         {
            throw new RuntimeException("Failed to instantiate eviction algorithm configuration class [" +
                  algorithm.getConfigurationClass() + "]", e);
         }
      }
      else
      {
         if (!isDefault)
         {
            if (defaultRegion == null || defaultRegion.getEvictionAlgorithmConfig() == null)
            {
               throw new MissingPolicyException("There is no Eviction Algorithm Class specified on the region or for the entire cache!");
            }
            else
            {
               try
               {
                  algorithmConfig = defaultRegion.getEvictionAlgorithmConfig().clone();
               }
               catch (CloneNotSupportedException e)
               {
                  throw new ConfigurationException("Unable to clone eviction algorithm configuration from default", e);
               }
            }
         }
      }

      if (algorithmConfig != null)
      {
         parseEvictionPolicyConfig(element, algorithmConfig);

         erc.setEvictionAlgorithmConfig(algorithmConfig);
      }

      String actionPolicyClass = getAttributeValue(element, "actionPolicyClass");
      if (existsAttribute(actionPolicyClass))
      {
         erc.setEvictionActionPolicyClassName(actionPolicyClass);
      }
      else if (defaultRegion == null)
      {
         // this is the default region. Make sure we set the default EvictionActionPolicyClass.
         erc.setEvictionActionPolicyClassName(EvictionConfig.EVICTION_ACTION_POLICY_CLASS_DEFAULT);
      }


      return erc;
   }
View Full Code Here

TOP

Related Classes of org.jboss.cache.config.EvictionRegionConfig

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.