KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > notification > util > AbstractPoolable


1 package org.jacorb.notification.util;
2
3 /*
4  * JacORB - a free Java ORB
5  *
6  * Copyright (C) 1999-2004 Gerald Brose
7  *
8  * This library is free software; you can redistribute it and/or
9  * 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.2 2005/04/16 23:20:40 alphonse.bendt Exp $
32  */

33
34 public abstract class AbstractPoolable implements Disposable
35 {
36     private AbstractObjectPool objectPool_;
37
38     protected final Logger logger_ = LogUtil.getLogger(getClass().getName());
39
40
41     /**
42      * The call to this Method indicates that this Object is not needed by the user anymore. After a
43      * call to <code>dispose</code> the Object can be returned to its ObjectPool. It's forbidden
44      * to use the Object after release has been called as this may cause unexpected behaviour.
45      */

46     public void dispose()
47     {
48         if (objectPool_ != null)
49         {
50             objectPool_.returnObject(this);
51
52             setObjectPool(null);
53         }
54     }
55
56     /**
57      * Set the ObjectPool to which this instance should be returned.
58      */

59     public synchronized void setObjectPool(AbstractObjectPool pool)
60     {
61         objectPool_ = pool;
62     }
63
64     /**
65      * Reset the Object to an initial state. Subclasses should override this method appropiately to
66      * reset the instance to an initial state.
67      */

68     public abstract void reset();
69 }
Popular Tags