001: /*
002: * Distributed as part of c3p0 v.0.9.1.2
003: *
004: * Copyright (C) 2005 Machinery For Change, Inc.
005: *
006: * Author: Steve Waldman <swaldman@mchange.com>
007: *
008: * This library is free software; you can redistribute it and/or modify
009: * it under the terms of the GNU Lesser General Public License version 2.1, as
010: * published by the Free Software Foundation.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: * GNU Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public License
018: * along with this software; see the file LICENSE. If not, write to the
019: * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
020: * Boston, MA 02111-1307, USA.
021: */
022:
023: package com.mchange.v2.resourcepool;
024:
025: import java.util.*;
026:
027: public class ResourcePoolEventSupport {
028: ResourcePool source;
029: Set mlisteners = new HashSet();
030:
031: public ResourcePoolEventSupport(ResourcePool source) {
032: this .source = source;
033: }
034:
035: public synchronized void addResourcePoolListener(
036: ResourcePoolListener mlistener) {
037: mlisteners.add(mlistener);
038: }
039:
040: public synchronized void removeResourcePoolListener(
041: ResourcePoolListener mlistener) {
042: mlisteners.remove(mlistener);
043: }
044:
045: public synchronized void fireResourceAcquired(Object resc,
046: int pool_size, int available_size,
047: int removed_but_unreturned_size) {
048: if (!mlisteners.isEmpty()) {
049: ResourcePoolEvent evt = new ResourcePoolEvent(source, resc,
050: false, pool_size, available_size,
051: removed_but_unreturned_size);
052: for (Iterator i = mlisteners.iterator(); i.hasNext();) {
053: ResourcePoolListener rpl = (ResourcePoolListener) i
054: .next();
055: rpl.resourceAcquired(evt);
056: }
057: }
058: }
059:
060: public synchronized void fireResourceCheckedIn(Object resc,
061: int pool_size, int available_size,
062: int removed_but_unreturned_size) {
063: if (!mlisteners.isEmpty()) {
064: ResourcePoolEvent evt = new ResourcePoolEvent(source, resc,
065: false, pool_size, available_size,
066: removed_but_unreturned_size);
067: for (Iterator i = mlisteners.iterator(); i.hasNext();) {
068: ResourcePoolListener rpl = (ResourcePoolListener) i
069: .next();
070: rpl.resourceCheckedIn(evt);
071: }
072: }
073: }
074:
075: public synchronized void fireResourceCheckedOut(Object resc,
076: int pool_size, int available_size,
077: int removed_but_unreturned_size) {
078: if (!mlisteners.isEmpty()) {
079: ResourcePoolEvent evt = new ResourcePoolEvent(source, resc,
080: true, pool_size, available_size,
081: removed_but_unreturned_size);
082: for (Iterator i = mlisteners.iterator(); i.hasNext();) {
083: ResourcePoolListener rpl = (ResourcePoolListener) i
084: .next();
085: rpl.resourceCheckedOut(evt);
086: }
087: }
088: }
089:
090: public synchronized void fireResourceRemoved(Object resc,
091: boolean checked_out_resource, int pool_size,
092: int available_size, int removed_but_unreturned_size) {
093: if (!mlisteners.isEmpty()) {
094: ResourcePoolEvent evt = new ResourcePoolEvent(source, resc,
095: checked_out_resource, pool_size, available_size,
096: removed_but_unreturned_size);
097: for (Iterator i = mlisteners.iterator(); i.hasNext();) {
098: ResourcePoolListener rpl = (ResourcePoolListener) i
099: .next();
100: rpl.resourceRemoved(evt);
101: }
102: }
103: }
104: }
|