KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > avalon > excalibur > component > DefaultComponentPoolController


1 /*
2  * Copyright (C) The Apache Software Foundation. All rights reserved.
3  *
4  * This software is published under the terms of the Apache Software License
5  * version 1.1, a copy of which has been included with this distribution in
6  * the LICENSE.txt file.
7  */

8 package org.apache.avalon.excalibur.component;
9
10 import org.apache.avalon.framework.thread.ThreadSafe;
11 import org.apache.avalon.excalibur.pool.PoolController;
12
13 /**
14  * This is the <code>PoolController</code> for the Avalon Excalibur
15  * Component Management Framework.
16  *
17  * @author <a HREF="mailto:Giacomo.Pati@pwr.ch">Giacomo Pati</a>
18  * @author <a HREF="mailto:bloritsch@apache.org">Berin Loritsch</a>
19  * @version CVS $Revision: 1.4 $ $Date: 2001/12/11 09:53:27 $
20  * @since 4.0
21  */

22 public class DefaultComponentPoolController
23     implements PoolController, ThreadSafe
24 {
25     /** Default increase/decrease amount */
26     public static final int DEFAULT_AMOUNT = 8;
27
28     /** Used increase/decrease amount */
29     protected final int m_amount;
30
31     /**
32      * The default constructor. It initializes the used increase/
33      * decrease amount to the default.
34      */

35     public DefaultComponentPoolController()
36     {
37         m_amount = DefaultComponentPoolController.DEFAULT_AMOUNT;
38     }
39
40     /**
41      * The alternate constructor. It initializes the used increase/
42      * decrease amount to the specified number only if it is greater
43      * than 0. Otherwise it uses the default amount.
44      *
45      * @param amount The amount to grow and shrink a pool by.
46      */

47     public DefaultComponentPoolController( final int amount )
48     {
49         if ( amount > 0 )
50         {
51             m_amount = amount;
52         }
53         else
54         {
55             m_amount = DefaultComponentPoolController.DEFAULT_AMOUNT;
56         }
57     }
58
59     /**
60      * Called when a Pool reaches it's minimum.
61      * Return the number of elements to increase pool by.
62      *
63      * @return the element increase
64      */

65     public int grow()
66     {
67         return m_amount;
68     }
69
70     /**
71      * Called when a pool reaches it's maximum.
72      * Returns the number of elements to decrease pool by.
73      *
74      * @return the element decrease
75      */

76     public int shrink()
77     {
78         return m_amount;
79     }
80 }
81
Popular Tags