View Javadoc
1   /*
2     File: DefaultChannelCapacity.java
3   
4     Originally written by Doug Lea and released into the public domain.
5     This may be used for any purposes whatsoever without acknowledgment.
6     Thanks for the assistance and support of Sun Microsystems Labs,
7     and everyone contributing, testing, and using this code.
8   
9     History:
10    Date       Who                What
11    11Jun1998  dl               Create public version
12  */
13  
14  package org.dbunit.util.concurrent;
15  
16  import org.slf4j.Logger;
17  import org.slf4j.LoggerFactory;
18  
19  /**
20   * A utility class to set the default capacity of
21   * BoundedChannel
22   * implementations that otherwise require a capacity argument
23   * @see BoundedChannel
24   * [<a href="http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/intro.html"> Introduction to this package. </a>] <p>
25   * 
26   * @author Doug Lea
27   * @author Last changed by: $Author$
28   * @version $Revision$ $Date$
29   * @since ? (pre 2.1)
30   */
31  public class DefaultChannelCapacity {
32  
33      /**
34       * Logger for this class
35       */
36      private static final Logger logger = LoggerFactory.getLogger(DefaultChannelCapacity.class);
37  
38    /** The initial value of the default capacity is 1024 **/
39    public static final int INITIAL_DEFAULT_CAPACITY = 1024;
40  
41    /**  the current default capacity **/
42    private static final SynchronizedInt defaultCapacity_ = 
43      new SynchronizedInt(INITIAL_DEFAULT_CAPACITY);
44  
45    /**
46     * Set the default capacity used in 
47     * default (no-argument) constructor for BoundedChannels
48     * that otherwise require a capacity argument.
49     * @exception IllegalArgumentException if capacity less or equal to zero
50     */
51    public static void set(int capacity) {
52      logger.debug("set(capacity={}) - start", String.valueOf(capacity));
53      if (capacity <= 0) throw new IllegalArgumentException();
54      defaultCapacity_.set(capacity);
55    }
56  
57    /**
58     * Get the default capacity used in 
59     * default (no-argument) constructor for BoundedChannels
60     * that otherwise require a capacity argument.
61     * Initial value is <code>INITIAL_DEFAULT_CAPACITY</code>
62     * @see #INITIAL_DEFAULT_CAPACITY
63     */
64    public static int get() {
65      return defaultCapacity_.get();
66    }
67  }