Coverage report

  %line %branch
org.apache.jcs.utils.threadpool.PoolConfiguration
87% 
98% 

 1  
 package org.apache.jcs.utils.threadpool;
 2  
 
 3  
 /*
 4  
  * Licensed to the Apache Software Foundation (ASF) under one
 5  
  * or more contributor license agreements.  See the NOTICE file
 6  
  * distributed with this work for additional information
 7  
  * regarding copyright ownership.  The ASF licenses this file
 8  
  * to you under the Apache License, Version 2.0 (the
 9  
  * "License"); you may not use this file except in compliance
 10  
  * with the License.  You may obtain a copy of the License at
 11  
  *
 12  
  *   http://www.apache.org/licenses/LICENSE-2.0
 13  
  *
 14  
  * Unless required by applicable law or agreed to in writing,
 15  
  * software distributed under the License is distributed on an
 16  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 17  
  * KIND, either express or implied.  See the License for the
 18  
  * specific language governing permissions and limitations
 19  
  * under the License.
 20  
  */
 21  
 
 22  
 import org.apache.jcs.utils.threadpool.behavior.IPoolConfiguration;
 23  
 
 24  
 
 25  
 /**
 26  
  * This object holds configuration data for a thread pool.
 27  
  * <p>
 28  
  * @author Aaron Smuts
 29  
  */
 30  
 public class PoolConfiguration
 31  
     implements Cloneable, IPoolConfiguration
 32  
 {
 33  590
     private boolean useBoundary = true;
 34  
 
 35  590
     private int boundarySize = 2000;
 36  
 
 37  
     // only has meaning if a bounday is used
 38  590
     private int maximumPoolSize = 150;
 39  
 
 40  
     // the exact number that will be used in a boundless queue. If the queue has
 41  
     // a boundary, more will be created if the queue fills.
 42  590
     private int minimumPoolSize = 4;
 43  
 
 44  590
     private int keepAliveTime = 1000 * 60 * 5;
 45  
 
 46  
     // should be ABORT, BLOCK, RUN, WAIT, DISCARDOLDEST,
 47  590
     private String whenBlockedPolicy = POLICY_RUN;
 48  
 
 49  590
     private int startUpSize = 4;
 50  
 
 51  
     /**
 52  
      * @param useBoundary
 53  
      *            The useBoundary to set.
 54  
      */
 55  
     public void setUseBoundary( boolean useBoundary )
 56  
     {
 57  634
         this.useBoundary = useBoundary;
 58  634
     }
 59  
 
 60  
     /**
 61  
      * @return Returns the useBoundary.
 62  
      */
 63  
     public boolean isUseBoundary()
 64  
     {
 65  798
         return useBoundary;
 66  
     }
 67  
 
 68  
     /**
 69  
      * Default
 70  
      */
 71  
     public PoolConfiguration()
 72  0
     {
 73  
         // nop
 74  0
     }
 75  
 
 76  
     /**
 77  
      * Construct a completely configured instance.
 78  
      * <p>
 79  
      * @param useBoundary
 80  
      * @param boundarySize
 81  
      * @param maximumPoolSize
 82  
      * @param minimumPoolSize
 83  
      * @param keepAliveTime
 84  
      * @param whenBlockedPolicy
 85  
      * @param startUpSize
 86  
      */
 87  32
     public PoolConfiguration( boolean useBoundary, int boundarySize, class="keyword">int maximumPoolSize, class="keyword">int minimumPoolSize,
 88  
                              int keepAliveTime, String whenBlockedPolicy, class="keyword">int startUpSize )
 89  558
     {
 90  590
         setUseBoundary( useBoundary );
 91  590
         setBoundarySize( boundarySize );
 92  590
         setMaximumPoolSize( maximumPoolSize );
 93  590
         setMinimumPoolSize( minimumPoolSize );
 94  590
         setKeepAliveTime( keepAliveTime );
 95  590
         setWhenBlockedPolicy( whenBlockedPolicy );
 96  590
         setStartUpSize( startUpSize );
 97  590
     }
 98  
 
 99  
     /**
 100  
      * @param boundarySize
 101  
      *            The boundarySize to set.
 102  
      */
 103  
     public void setBoundarySize( int boundarySize )
 104  
     {
 105  810
         this.boundarySize = boundarySize;
 106  810
     }
 107  
 
 108  
     /**
 109  
      * @return Returns the boundarySize.
 110  
      */
 111  
     public int getBoundarySize()
 112  
     {
 113  64
         return boundarySize;
 114  
     }
 115  
 
 116  
     /**
 117  
      * @param maximumPoolSize
 118  
      *            The maximumPoolSize to set.
 119  
      */
 120  
     public void setMaximumPoolSize( int maximumPoolSize )
 121  
     {
 122  810
         this.maximumPoolSize = maximumPoolSize;
 123  810
     }
 124  
 
 125  
     /**
 126  
      * @return Returns the maximumPoolSize.
 127  
      */
 128  
     public int getMaximumPoolSize()
 129  
     {
 130  100
         return maximumPoolSize;
 131  
     }
 132  
 
 133  
     /**
 134  
      * @param minimumPoolSize
 135  
      *            The minimumPoolSize to set.
 136  
      */
 137  
     public void setMinimumPoolSize( int minimumPoolSize )
 138  
     {
 139  810
         this.minimumPoolSize = minimumPoolSize;
 140  810
     }
 141  
 
 142  
     /**
 143  
      * @return Returns the minimumPoolSize.
 144  
      */
 145  
     public int getMinimumPoolSize()
 146  
     {
 147  100
         return minimumPoolSize;
 148  
     }
 149  
 
 150  
     /**
 151  
      * @param keepAliveTime
 152  
      *            The keepAliveTime to set.
 153  
      */
 154  
     public void setKeepAliveTime( int keepAliveTime )
 155  
     {
 156  810
         this.keepAliveTime = keepAliveTime;
 157  810
     }
 158  
 
 159  
     /**
 160  
      * @return Returns the keepAliveTime.
 161  
      */
 162  
     public int getKeepAliveTime()
 163  
     {
 164  100
         return keepAliveTime;
 165  
     }
 166  
 
 167  
     /**
 168  
      * @param whenBlockedPolicy
 169  
      *            The whenBlockedPolicy to set.
 170  
      */
 171  
     public void setWhenBlockedPolicy( String whenBlockedPolicy )
 172  
     {
 173  810
         if ( whenBlockedPolicy != null )
 174  
         {
 175  810
             whenBlockedPolicy = whenBlockedPolicy.trim();
 176  
 
 177  810
             if ( whenBlockedPolicy.equalsIgnoreCase( POLICY_ABORT ) )
 178  
             {
 179  0
                 this.whenBlockedPolicy = POLICY_ABORT;
 180  0
             }
 181  810
             else if ( whenBlockedPolicy.equalsIgnoreCase( POLICY_RUN ) )
 182  
             {
 183  778
                 this.whenBlockedPolicy = POLICY_RUN;
 184  738
             }
 185  32
             else if ( whenBlockedPolicy.equalsIgnoreCase( POLICY_BLOCK ) )
 186  
             {
 187  0
                 this.whenBlockedPolicy = POLICY_BLOCK;
 188  0
             }
 189  32
             else if ( whenBlockedPolicy.equalsIgnoreCase( POLICY_DISCARDOLDEST ) )
 190  
             {
 191  0
                 this.whenBlockedPolicy = POLICY_DISCARDOLDEST;
 192  0
             }
 193  32
             else if ( whenBlockedPolicy.equalsIgnoreCase( POLICY_WAIT ) )
 194  
             {
 195  32
                 this.whenBlockedPolicy = POLICY_WAIT;
 196  28
             }
 197  
             else
 198  
             {
 199  
                 // the value is invalid, dfault to RUN
 200  0
                 this.whenBlockedPolicy = POLICY_RUN;
 201  
             }
 202  0
         }
 203  
         else
 204  
         {
 205  
             // the value is null, dfault to RUN
 206  0
             this.whenBlockedPolicy = POLICY_RUN;
 207  
         }
 208  810
     }
 209  
 
 210  
     /**
 211  
      * @return Returns the whenBlockedPolicy.
 212  
      */
 213  
     public String getWhenBlockedPolicy()
 214  
     {
 215  930
         return whenBlockedPolicy;
 216  
     }
 217  
 
 218  
     /**
 219  
      * @param startUpSize
 220  
      *            The startUpSize to set.
 221  
      */
 222  
     public void setStartUpSize( int startUpSize )
 223  
     {
 224  810
         this.startUpSize = startUpSize;
 225  810
     }
 226  
 
 227  
     /**
 228  
      * @return Returns the startUpSize.
 229  
      */
 230  
     public int getStartUpSize()
 231  
     {
 232  100
         return startUpSize;
 233  
     }
 234  
 
 235  
     /**
 236  
      * To string for debugging purposes.
 237  
      * @return String
 238  
      */
 239  
     public String toString()
 240  
     {
 241  349
         StringBuffer buf = new StringBuffer();
 242  349
         buf.append( "useBoundary = [" + isUseBoundary() + "] " );
 243  349
         buf.append( "boundarySize = [" + boundarySize + "] " );
 244  349
         buf.append( "maximumPoolSize = [" + maximumPoolSize + "] " );
 245  349
         buf.append( "minimumPoolSize = [" + minimumPoolSize + "] " );
 246  349
         buf.append( "keepAliveTime = [" + keepAliveTime + "] " );
 247  349
         buf.append( "whenBlockedPolicy = [" + getWhenBlockedPolicy() + "] " );
 248  349
         buf.append( "startUpSize = [" + startUpSize + "]" );
 249  349
         return buf.toString();
 250  
     }
 251  
 
 252  
     /**
 253  
      * Copies the instance variables to another instance.
 254  
      * <p>
 255  
      * @return PoolConfiguration
 256  
      */
 257  
     public Object clone()
 258  
     {
 259  370
         return new PoolConfiguration( isUseBoundary(), boundarySize, maximumPoolSize, minimumPoolSize, keepAliveTime,
 260  21
                                       getWhenBlockedPolicy(), startUpSize );
 261  
     }
 262  
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.