KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mchange > v2 > resourcepool > ResourcePoolEventSupport


1 /*
2  * Distributed as part of c3p0 v.0.9.1
3  *
4  * Copyright (C) 2005 Machinery For Change, Inc.
5  *
6  * Author: Steve Waldman <swaldman@mchange.com>
7  *
8  * This library is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License version 2.1, as
10  * published by the Free Software Foundation.
11  *
12  * This software is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this software; see the file LICENSE. If not, write to the
19  * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */

22
23
24 package com.mchange.v2.resourcepool;
25
26 import java.util.*;
27
28 public class ResourcePoolEventSupport
29 {
30     ResourcePool source;
31     Set mlisteners = new HashSet();
32
33     public ResourcePoolEventSupport(ResourcePool source)
34     { this.source = source; }
35
36     public synchronized void addResourcePoolListener(ResourcePoolListener mlistener)
37     {mlisteners.add(mlistener);}
38
39     public synchronized void removeResourcePoolListener(ResourcePoolListener mlistener)
40     {mlisteners.remove(mlistener);}
41
42     public synchronized void fireResourceAcquired( Object JavaDoc resc,
43                            int pool_size,
44                            int available_size,
45                            int removed_but_unreturned_size )
46     {
47     if (! mlisteners.isEmpty() )
48         {
49         ResourcePoolEvent evt = new ResourcePoolEvent(source,
50                                   resc,
51                                   false,
52                                   pool_size,
53                                   available_size,
54                                   removed_but_unreturned_size );
55         for (Iterator i = mlisteners.iterator(); i.hasNext();)
56             {
57             ResourcePoolListener rpl = (ResourcePoolListener) i.next();
58             rpl.resourceAcquired(evt);
59             }
60         }
61     }
62
63     public synchronized void fireResourceCheckedIn( Object JavaDoc resc,
64                             int pool_size,
65                             int available_size,
66                             int removed_but_unreturned_size )
67     {
68     if (! mlisteners.isEmpty() )
69         {
70         ResourcePoolEvent evt = new ResourcePoolEvent(source,
71                                   resc,
72                                   false,
73                                   pool_size,
74                                   available_size,
75                                   removed_but_unreturned_size );
76         for (Iterator i = mlisteners.iterator(); i.hasNext();)
77             {
78             ResourcePoolListener rpl = (ResourcePoolListener) i.next();
79             rpl.resourceCheckedIn(evt);
80             }
81         }
82     }
83
84     public synchronized void fireResourceCheckedOut( Object JavaDoc resc,
85                              int pool_size,
86                              int available_size,
87                              int removed_but_unreturned_size )
88     {
89     if (! mlisteners.isEmpty() )
90         {
91         ResourcePoolEvent evt = new ResourcePoolEvent(source,
92                                   resc,
93                                   true,
94                                   pool_size,
95                                   available_size,
96                                   removed_but_unreturned_size );
97         for (Iterator i = mlisteners.iterator(); i.hasNext();)
98             {
99             ResourcePoolListener rpl = (ResourcePoolListener) i.next();
100             rpl.resourceCheckedOut(evt);
101             }
102         }
103     }
104
105     public synchronized void fireResourceRemoved( Object JavaDoc resc,
106                           boolean checked_out_resource,
107                           int pool_size,
108                           int available_size,
109                           int removed_but_unreturned_size )
110     {
111     if (! mlisteners.isEmpty() )
112         {
113         ResourcePoolEvent evt = new ResourcePoolEvent(source,
114                                   resc,
115                                   checked_out_resource,
116                                   pool_size,
117                                   available_size,
118                                   removed_but_unreturned_size );
119         for (Iterator i = mlisteners.iterator(); i.hasNext();)
120             {
121             ResourcePoolListener rpl = (ResourcePoolListener) i.next();
122             rpl.resourceRemoved(evt);
123             }
124         }
125     }
126 }
127
128
129
130
Popular Tags