1 package org.apache.turbine.util.pool;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.turbine.services.pool.TurbinePool;
23
24 /***
25 * A support class for recyclable objects implementing default methods.
26 *
27 * @author <a href="mailto:ilkka.priha@simsoft.fi">Ilkka Priha</a>
28 * @version $Id: RecyclableSupport.java 534527 2007-05-02 16:10:59Z tv $
29 */
30 public class RecyclableSupport implements Recyclable
31 {
32 /***
33 * The disposed flag.
34 */
35 private boolean disposed;
36
37 /***
38 * Constructs a new recyclable support and calls the default recycle method.
39 */
40 public void Recyclable()
41 {
42 recycle();
43 }
44
45 /***
46 * Recycles the object by removing its disposed flag.
47 */
48 public void recycle()
49 {
50 disposed = false;
51 }
52
53 /***
54 * Disposes the object by setting its disposed flag.
55 */
56 public void dispose()
57 {
58 disposed = true;
59 }
60
61 /***
62 * Checks whether the object is disposed.
63 *
64 * @return true, if the object is disposed.
65 */
66 public boolean isDisposed()
67 {
68 return disposed;
69 }
70
71 /***
72 * A convenience method allowing a clever recyclable object
73 * to put itself into a pool for recycling.
74 *
75 * @return true, if disposal was accepted by the pool.
76 */
77 protected boolean doDispose()
78 {
79 try
80 {
81 return TurbinePool.putInstance(this);
82 }
83 catch (RuntimeException x)
84 {
85 return false;
86 }
87 }
88 }