1 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 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 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 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 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 |