Package org.jboss.cache.config

Examples of org.jboss.cache.config.EvictionRegionConfig


      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


   }

   private EvictionConfig buildEvictionConfig()
   {
      return new EvictionConfig(
            new EvictionRegionConfig(
                  Fqn.ROOT,
                  new LRUAlgorithmConfig(1000000, 5000)
            ),
            200);
   }
View Full Code Here

   public EvictionAlgorithm createAndAssignToRegion(String fqnString, RegionManager regionManager, EvictionAlgorithmConfig config)
   {
      Fqn fqn = Fqn.fromString(fqnString);
      Configuration c = new Configuration();
      c.setEvictionConfig(new EvictionConfig());
      EvictionRegionConfig erc = new EvictionRegionConfig(fqn, config);
      c.getEvictionConfig().addEvictionRegionConfig(erc);
      CacheSPI mockCache = EasyMock.createNiceMock(CacheSPI.class);
      EasyMock.replay(mockCache);
      ((RegionManagerImpl) regionManager).injectDependencies(mockCache, c, null, null, null, new RegionRegistry());
      Region r = regionManager.getRegion(fqn, Region.Type.EVICTION, true);
View Full Code Here

   {
      algorithm = new LRUAlgorithm();
      regionManager = new RegionManagerImpl();
      ((RegionManagerImpl) regionManager).injectDependencies(null, null, null, null, null, new RegionRegistry());
      Region r = regionManager.getRegion("/a/b", true);//.setEvictionPolicy(new DummyEvictionConfiguration());
      r.setEvictionRegionConfig(new EvictionRegionConfig(r.getFqn(), new LRUAlgorithmConfig()));
   }
View Full Code Here

   @BeforeMethod(alwaysRun = true)
   public void setUp() throws Exception
   {
      Configuration conf = new Configuration();
      ExpirationAlgorithmConfig eAC = new ExpirationAlgorithmConfig();
      EvictionRegionConfig eRC = new EvictionRegionConfig(Fqn.ROOT, eAC);
      EvictionConfig econf = new EvictionConfig(eRC);
      econf.setWakeupInterval(100);
      conf.setEvictionConfig(econf);
      cache = (CacheSPI<Object, Object>) new UnitTestCacheFactory<Object, Object>().createCache(conf, false);
      cache.start();
View Full Code Here

   }

   public void testMaxNodes() throws Exception
   {
      log.info("set max nodes to 2, expire soonest to expire first");
      EvictionRegionConfig regionConfig = cache.getRegionManager().getAllRegions(Region.Type.EVICTION).get(0).getEvictionRegionConfig();
      ExpirationAlgorithmConfig ec = (ExpirationAlgorithmConfig) regionConfig.getEvictionAlgorithmConfig();
      ec.setMaxNodes(2);
      Long future2 = future + 500;
      cache.put(fqn1, ExpirationAlgorithmConfig.EXPIRATION_KEY, future2);
      cache.put(fqn2, ExpirationAlgorithmConfig.EXPIRATION_KEY, future2);
      cache.put(fqn3, ExpirationAlgorithmConfig.EXPIRATION_KEY, future);
View Full Code Here

      /* override recycle queue capacity to make the test shorter */
      BaseEvictionAlgorithm algorithm = new MockEvictionAlgorithm(recycleQueueCapacity);

      Region region = regionManager.getRegion("/a/b/c", true);
      region.setEvictionRegionConfig(new EvictionRegionConfig(region.getFqn(), new MockEvictionAlgorithmConfig()));

      for (int i = 0; i < (recycleQueueCapacity + 1); i++)
      {
         Fqn fqn = Fqn.fromString("/a/b/c/" + Integer.toString(i + 1));
         region.registerEvictionEvent(fqn, EvictionEvent.Type.ADD_NODE_EVENT);
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

               {
                  continue;
               }
               try
               {
                  EvictionRegionConfig evictionRegionConfig = parseEvictionRegionConfig((Element) node, defaultEvPolicyClassName, eventQueueSize);
                  if (!evictionRegionConfig.getRegionFqn().equals(RegionManagerImpl.DEFAULT_REGION))
                  {
                     regionConfigs.add(evictionRegionConfig);
                  }
                  else
                  {
                     evictionConfig.getDefaultEvictionRegionConfig().setEventQueueSize(evictionRegionConfig.getEventQueueSize());
                     evictionConfig.getDefaultEvictionRegionConfig().setEvictionAlgorithmConfig(evictionRegionConfig.getEvictionAlgorithmConfig());
                  }
               }
               catch (MissingPolicyException missingPolicy)
               {
                  LogFactory.getLog(EvictionConfig.class).warn(missingPolicy.getLocalizedMessage());
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.