DefaultChannelCapacity.java

  1. /*
  2.   File: DefaultChannelCapacity.java

  3.   Originally written by Doug Lea and released into the public domain.
  4.   This may be used for any purposes whatsoever without acknowledgment.
  5.   Thanks for the assistance and support of Sun Microsystems Labs,
  6.   and everyone contributing, testing, and using this code.

  7.   History:
  8.   Date       Who                What
  9.   11Jun1998  dl               Create public version
  10. */

  11. package org.dbunit.util.concurrent;

  12. import org.slf4j.Logger;
  13. import org.slf4j.LoggerFactory;

  14. /**
  15.  * A utility class to set the default capacity of
  16.  * BoundedChannel
  17.  * implementations that otherwise require a capacity argument
  18.  * @see BoundedChannel
  19.  * [<a href="http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/intro.html"> Introduction to this package. </a>] <p>
  20.  *
  21.  * @author Doug Lea
  22.  * @author Last changed by: $Author$
  23.  * @version $Revision$ $Date$
  24.  * @since ? (pre 2.1)
  25.  */
  26. public class DefaultChannelCapacity {

  27.     /**
  28.      * Logger for this class
  29.      */
  30.     private static final Logger logger = LoggerFactory.getLogger(DefaultChannelCapacity.class);

  31.   /** The initial value of the default capacity is 1024 **/
  32.   public static final int INITIAL_DEFAULT_CAPACITY = 1024;

  33.   /**  the current default capacity **/
  34.   private static final SynchronizedInt defaultCapacity_ =
  35.     new SynchronizedInt(INITIAL_DEFAULT_CAPACITY);

  36.   /**
  37.    * Set the default capacity used in
  38.    * default (no-argument) constructor for BoundedChannels
  39.    * that otherwise require a capacity argument.
  40.    * @exception IllegalArgumentException if capacity less or equal to zero
  41.    */
  42.   public static void set(int capacity) {
  43.     logger.debug("set(capacity={}) - start", String.valueOf(capacity));
  44.     if (capacity <= 0) throw new IllegalArgumentException();
  45.     defaultCapacity_.set(capacity);
  46.   }

  47.   /**
  48.    * Get the default capacity used in
  49.    * default (no-argument) constructor for BoundedChannels
  50.    * that otherwise require a capacity argument.
  51.    * Initial value is <code>INITIAL_DEFAULT_CAPACITY</code>
  52.    * @see #INITIAL_DEFAULT_CAPACITY
  53.    */
  54.   public static int get() {
  55.     return defaultCapacity_.get();
  56.   }
  57. }