01: package org.jacorb.notification.util;
02:
03: /*
04: * JacORB - a free Java ORB
05: *
06: * Copyright (C) 1999-2004 Gerald Brose
07: *
08: * This library is free software; you can redistribute it and/or
09: * modify it under the terms of the GNU Library General Public
10: * License as published by the Free Software Foundation; either
11: * version 2 of the License, or (at your option) any later version.
12: *
13: * This library is distributed in the hope that it will be useful,
14: * but WITHOUT ANY WARRANTY; without even the implied warranty of
15: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16: * Library General Public License for more details.
17: *
18: * You should have received a copy of the GNU Library General Public
19: * License along with this library; if not, write to the Free
20: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21: *
22: */
23:
24: import org.apache.avalon.framework.logger.Logger;
25: import org.jacorb.notification.interfaces.Disposable;
26:
27: /**
28: * Interface to indicate that a Object can be pooled. Objects can be pooled to spare ressources.
29: *
30: * @author Alphonse Bendt
31: * @version $Id: AbstractPoolable.java,v 1.3 2005/08/21 13:38:40 alphonse.bendt Exp $
32: */
33:
34: public abstract class AbstractPoolable implements Disposable {
35: protected final Logger logger_ = LogUtil.getLogger(getClass()
36: .getName());
37:
38: private AbstractObjectPool objectPool_;
39:
40: /**
41: * The call to this Method indicates that this Object is not needed by the user anymore. After a
42: * call to <code>dispose</code> the Object can be returned to its ObjectPool. It's forbidden
43: * to use the Object after release has been called as this may cause unexpected behaviour.
44: */
45: public void dispose() {
46: if (objectPool_ != null) {
47: objectPool_.returnObject(this );
48:
49: setObjectPool(null);
50: }
51: }
52:
53: /**
54: * Set the ObjectPool to which this instance should be returned.
55: */
56: public synchronized void setObjectPool(AbstractObjectPool pool) {
57: objectPool_ = pool;
58: }
59:
60: /**
61: * Reset the Object to an initial state. Subclasses should override this method appropiately to
62: * reset the instance to an initial state.
63: */
64: public abstract void reset();
65: }
|