01: package org.apache.turbine.util.pool;
02:
03: /*
04: * Licensed to the Apache Software Foundation (ASF) under one
05: * or more contributor license agreements. See the NOTICE file
06: * distributed with this work for additional information
07: * regarding copyright ownership. The ASF licenses this file
08: * to you under the Apache License, Version 2.0 (the
09: * "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: * The disposed flag.
33: */
34: private boolean disposed;
35:
36: /**
37: * Constructs a new recyclable support and calls the default recycle method.
38: */
39: public void Recyclable() {
40: recycle();
41: }
42:
43: /**
44: * Recycles the object by removing its disposed flag.
45: */
46: public void recycle() {
47: disposed = false;
48: }
49:
50: /**
51: * Disposes the object by setting its disposed flag.
52: */
53: public void dispose() {
54: disposed = true;
55: }
56:
57: /**
58: * Checks whether the object is disposed.
59: *
60: * @return true, if the object is disposed.
61: */
62: public boolean isDisposed() {
63: return disposed;
64: }
65:
66: /**
67: * A convenience method allowing a clever recyclable object
68: * to put itself into a pool for recycling.
69: *
70: * @return true, if disposal was accepted by the pool.
71: */
72: protected boolean doDispose() {
73: try {
74: return TurbinePool.putInstance(this );
75: } catch (RuntimeException x) {
76: return false;
77: }
78: }
79: }
|