001/* ----------------------------------------------------------------------------
002   The Kiwi Toolkit - A Java Class Library
003   Copyright (C) 1998-2004 Mark A. Lindner
004
005   This library is free software; you can redistribute it and/or
006   modify it under the terms of the GNU General Public License as
007   published by the Free Software Foundation; either version 2 of the
008   License, or (at your option) any later version.
009
010   This library is distributed in the hope that it will be useful,
011   but WITHOUT ANY WARRANTY; without even the implied warranty of
012   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013   General Public License for more details.
014
015   You should have received a copy of the GNU General Public License
016   along with this library; if not, write to the Free Software
017   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
018   02111-1307, USA.
019 
020   The author may be contacted at: mark_a_lindner@yahoo.com
021   ----------------------------------------------------------------------------
022   $Log: TimerPool.java,v $
023   Revision 1.4  2004/05/05 21:22:46  markl
024   Comment header updates.
025
026   Revision 1.3  2003/01/19 09:42:39  markl
027   Javadoc & comment header updates.
028
029   Revision 1.2  2001/03/12 03:16:51  markl
030   *** empty log message ***
031
032   Revision 1.1  1999/04/23 07:31:08  markl
033   Initial revision
034   ----------------------------------------------------------------------------
035*/
036
037package kiwi.util;
038
039/** A concrete implementation of <code>ResourcePool</code> for managing a
040 * pool of <code>IntervalTimer</code>s.
041 *
042 * @author Mark Lindner
043 */
044
045public class TimerPool extends ResourcePool
046  {
047  /** Construct a new <code>TimerPool</code> of the specified size.
048   *
049   * @param size The number of <code>IntervalTimer</code>s to preallocate.
050   */
051
052  public TimerPool(int size)
053    {
054    super(size);
055    }
056
057  /** Construct a new <code>IntervalTimer</code>.
058   *
059   * @return The new <code>IntervalTimer</code>.
060   */
061   
062  protected Resource constructResource()
063    {
064    return(new IntervalTimer());
065    }
066  
067  /** Reserve a timer from the pool. If all timers are currently in use, the
068   * method blocks until one becomes available.
069   *
070   * @return An <code>IntervalTimer</code> instance.
071   */
072
073  public IntervalTimer reserveTimer()
074    {
075    IntervalTimer timer = (IntervalTimer)reserveResource();
076    return(timer);
077    }
078  
079  /** Release a timer back into the pool.
080   *
081   * @param timer The timer to release.
082   */
083   
084  public void releaseTimer(IntervalTimer timer)
085    {
086    releaseResource(timer);
087    }
088  
089  }
090
091/* end of source file */