Clover coverage report -
Coverage timestamp: Thu Jul 5 2007 20:02:32 EDT
file stats: LOC: 168   Methods: 13
NCLOC: 113   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
EvictionConfig.java 25% 69.2% 84.6% 64.1%
coverage coverage
 1    /*
 2    * JBoss, Home of Professional Open Source.
 3    * Copyright 2006, Red Hat Middleware LLC, and individual contributors
 4    * as indicated by the @author tags. See the copyright.txt file in the
 5    * distribution for a full listing of individual contributors.
 6    *
 7    * This is free software; you can redistribute it and/or modify it
 8    * under the terms of the GNU Lesser General Public License as
 9    * published by the Free Software Foundation; either version 2.1 of
 10    * the License, or (at your option) any later version.
 11    *
 12    * This software is distributed in the hope that it will be useful,
 13    * but WITHOUT ANY WARRANTY; without even the implied warranty of
 14    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 15    * Lesser General Public License for more details.
 16    *
 17    * You should have received a copy of the GNU Lesser General Public
 18    * License along with this software; if not, write to the Free
 19    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 20    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 21    */
 22    package org.jboss.cache.config;
 23   
 24    import org.jboss.cache.RegionManager;
 25    import org.jboss.cache.eviction.EvictionPolicy;
 26   
 27    import java.util.Collections;
 28    import java.util.List;
 29   
 30    public class EvictionConfig extends ConfigurationComponent
 31    {
 32    /**
 33    * The serialVersionUID
 34    */
 35    private static final long serialVersionUID = -7979639000026975201L;
 36   
 37    public static final String WAKEUP_INTERVAL_SECONDS = "wakeUpIntervalSeconds";
 38   
 39    public static final int WAKEUP_DEFAULT = 5;
 40   
 41    public static final String EVENT_QUEUE_SIZE = "eventQueueSize";
 42   
 43    public static final String EVICTION_POLICY_CLASS = "policyClass";
 44   
 45    public static final int EVENT_QUEUE_SIZE_DEFAULT = 200000;
 46   
 47    private String defaultEvictionPolicyClass;
 48   
 49    private int wakeupIntervalSeconds = WAKEUP_DEFAULT;
 50   
 51    private int defaultEventQueueSize = EVENT_QUEUE_SIZE_DEFAULT;
 52   
 53    // Dynamic to support runtime adds/removes of regions
 54    @Dynamic
 55    private List<EvictionRegionConfig> evictionRegionConfigs;
 56   
 57  1010 public EvictionConfig()
 58    {
 59    }
 60   
 61  4 public EvictionConfig(String defaultEvictionClass)
 62    {
 63  4 setDefaultEvictionPolicyClass(defaultEvictionClass);
 64    }
 65   
 66  750 public boolean isValidConfig()
 67    {
 68  750 return (defaultEvictionPolicyClass != null && defaultEvictionPolicyClass.length() > 0)
 69    || (evictionRegionConfigs != null && evictionRegionConfigs.size() > 0);
 70    }
 71   
 72  3036 public String getDefaultEvictionPolicyClass()
 73    {
 74  3036 return defaultEvictionPolicyClass;
 75    }
 76   
 77  1008 public void setDefaultEvictionPolicyClass(String defaultEvictionPolicyClass)
 78    {
 79  1008 testImmutability("defaultEvictionPolicyClass");
 80  1008 this.defaultEvictionPolicyClass = defaultEvictionPolicyClass;
 81    }
 82   
 83  379 public List<EvictionRegionConfig> getEvictionRegionConfigs()
 84    {
 85  379 if (evictionRegionConfigs == null && defaultEvictionPolicyClass != null)
 86    {
 87    // TODO this needs to be refactored obviously ...
 88  4 try
 89    {
 90  4 Class<EvictionPolicy> cpolicy = (Class<EvictionPolicy>) Class.forName(defaultEvictionPolicyClass);
 91  4 EvictionPolicy policy;
 92  4 policy = cpolicy.newInstance();
 93  4 EvictionRegionConfig erc = new EvictionRegionConfig();
 94  4 EvictionPolicyConfig epc = policy.getEvictionConfigurationClass().newInstance();
 95    // epc.set
 96  4 erc.setEvictionPolicyConfig(epc);
 97  4 erc.setRegionFqn(RegionManager.DEFAULT_REGION);
 98  4 return Collections.singletonList(erc);
 99    }
 100    catch (Exception e)
 101    {
 102  0 throw new ConfigurationException(e);
 103    }
 104    }
 105  375 return evictionRegionConfigs;
 106    }
 107   
 108  3036 public int getDefaultEventQueueSize()
 109    {
 110  3036 return defaultEventQueueSize;
 111    }
 112   
 113  1009 public void setDefaultEventQueueSize(int eventQueueSize)
 114    {
 115  1009 this.defaultEventQueueSize = eventQueueSize;
 116    }
 117   
 118  1009 public void setEvictionRegionConfigs(List<EvictionRegionConfig> evictionRegionConfigs)
 119    {
 120  1009 testImmutability("evictionRegionConfigs");
 121   
 122    // Make sure region configs built by MC have the event queue size
 123  1009 if (evictionRegionConfigs != null)
 124    {
 125  1009 for (EvictionRegionConfig cfg : evictionRegionConfigs)
 126    {
 127  3031 cfg.setDefaultEventQueueSize(getDefaultEventQueueSize());
 128    }
 129    }
 130  1009 replaceChildConfigs(this.evictionRegionConfigs, evictionRegionConfigs);
 131  1009 this.evictionRegionConfigs = evictionRegionConfigs;
 132    }
 133   
 134  414 public int getWakeupIntervalSeconds()
 135    {
 136  414 return wakeupIntervalSeconds;
 137    }
 138   
 139  1013 public void setWakeupIntervalSeconds(int wakeupIntervalSeconds)
 140    {
 141  1013 testImmutability("wakeupIntervalSeconds");
 142  1013 this.wakeupIntervalSeconds = wakeupIntervalSeconds;
 143    }
 144   
 145  0 public boolean equals(Object obj)
 146    {
 147  0 if (this == obj)
 148  0 return true;
 149   
 150  0 if (obj instanceof EvictionConfig)
 151    {
 152  0 EvictionConfig other = (EvictionConfig) obj;
 153  0 return (this.wakeupIntervalSeconds == other.wakeupIntervalSeconds)
 154    && safeEquals(this.defaultEvictionPolicyClass, other.defaultEvictionPolicyClass)
 155    && safeEquals(this.evictionRegionConfigs, other.evictionRegionConfigs);
 156    }
 157  0 return false;
 158    }
 159   
 160  0 public int hashCode()
 161    {
 162  0 int result = 17;
 163  0 result = 37 * result + wakeupIntervalSeconds;
 164  0 result = 37 * result + (defaultEvictionPolicyClass == null ? 0 : defaultEvictionPolicyClass.hashCode());
 165  0 result = 37 * result + (evictionRegionConfigs == null ? 0 : evictionRegionConfigs.hashCode());
 166  0 return result;
 167    }
 168    }