View Javadoc

1   package org.apache.turbine.util.pool;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
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  }