KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > avalon > excalibur > component > test > PoolableTestObject


1 /*
2  * Copyright 2002-2004 The Apache Software Foundation
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12  * implied.
13  *
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.avalon.excalibur.component.test;
18
19 import org.apache.avalon.excalibur.pool.Poolable;
20 import org.apache.avalon.excalibur.pool.Recyclable;
21 import org.apache.avalon.framework.activity.Disposable;
22 import org.apache.avalon.framework.activity.Initializable;
23 import org.apache.avalon.framework.component.Component;
24 import org.apache.avalon.framework.logger.Logger;
25
26 /**
27  * @deprecated ECM is no longer supported
28  *
29  * @author <a HREF="mailto:dev@avalon.apache.org">Avalon Development Team</a>
30  * @version CVS $Revision: 1.4 $ $Date: 2004/02/28 11:47:36 $
31  */

32 public class PoolableTestObject
33     implements PoolableTestObjectInterface, Initializable, Recyclable, Disposable, Poolable
34 {
35     /** Semaphore used to synchronize access to m_instanceCounter */
36     private static Object JavaDoc m_semaphore = new Object JavaDoc();
37
38     /** Number of instances created since the last call to resetInstanceCounter() */
39     private static int m_instanceCounter = 0;
40
41     private static Logger m_logger;
42
43     /** Instance Id */
44     private int m_instanceId;
45
46     /*---------------------------------------------------------------
47      * Constructors
48      *-------------------------------------------------------------*/

49     public PoolableTestObject()
50     {
51         synchronized( m_semaphore )
52         {
53             m_instanceCounter++;
54             m_instanceId = m_instanceCounter;
55         }
56     }
57
58     /*---------------------------------------------------------------
59      * Static Methods
60      *-------------------------------------------------------------*/

61     /**
62      * Resets the instance counter so that the next Poolable will get an instance Id of 1.
63      */

64     public static void resetInstanceCounter()
65     {
66         synchronized( m_semaphore )
67         {
68             m_instanceCounter = 0;
69         }
70     }
71
72     /**
73      * Used by tests to change the current logger object.
74      */

75     public static void setStaticLoggger( Logger logger )
76     {
77         m_logger = logger;
78     }
79
80     /*---------------------------------------------------------------
81      * Initializable Methods
82      *-------------------------------------------------------------*/

83     /**
84      * Called by the Container to initialize the component.
85      */

86     public void initialize()
87     {
88         m_logger.debug( "PoolableTestObject #" + m_instanceId + " initialized." );
89     }
90
91     /*---------------------------------------------------------------
92      * Recyclable Methods
93      *-------------------------------------------------------------*/

94     /**
95      * Called by the Container when the component is recycled.
96      */

97     public void recycle()
98     {
99         m_logger.debug( "PoolableTestObject #" + m_instanceId + " recycled." );
100     }
101
102     /*---------------------------------------------------------------
103      * Disposable Methods
104      *-------------------------------------------------------------*/

105     /**
106      * Called by the Container to dispose the component.
107      */

108     public void dispose()
109     {
110         m_logger.debug( "PoolableTestObject #" + m_instanceId + " disposed." );
111     }
112 }
113
114
Popular Tags