1 6 package org.logicalcobwebs.proxool; 7 8 import java.sql.Connection ; 9 import java.sql.SQLException ; 10 11 import org.apache.commons.logging.Log; 12 import org.apache.commons.logging.LogFactory; 13 import org.logicalcobwebs.proxool.util.AbstractListenerContainer; 14 15 28 public class CompositeConnectionListener extends AbstractListenerContainer implements ConnectionListenerIF { 29 static final Log LOG = LogFactory.getLog(CompositeConnectionListener.class); 30 31 34 public void onBirth(Connection connection) throws SQLException 35 { 36 Object [] listeners = getListeners(); 37 38 for(int i=0; i<listeners.length; i++) { 39 try { 40 ConnectionListenerIF connectionListener = (ConnectionListenerIF) listeners[i]; 41 connectionListener.onBirth(connection); 42 } 43 catch (RuntimeException re) { 44 LOG.warn("RuntimeException received from listener "+listeners[i]+" when dispatching onBirth event", re); 45 } 46 catch(SQLException se) { 47 LOG.warn("SQLException received from listener "+listeners[i]+" when dispatching onBirth event - event dispatching cancelled"); 48 throw se; 49 } 50 } 51 } 52 53 56 public void onDeath(Connection connection) throws SQLException 57 { 58 Object [] listeners = getListeners(); 59 60 for(int i=0; i<listeners.length; i++) { 61 try { 62 ConnectionListenerIF connectionListener = (ConnectionListenerIF) listeners[i]; 63 connectionListener.onDeath(connection); 64 } 65 catch (RuntimeException re) { 66 LOG.warn("RuntimeException received from listener "+listeners[i]+" when dispatching onDeath event", re); 67 } 68 catch(SQLException se) { 69 LOG.warn("SQLException received from listener "+listeners[i]+" when dispatching onDeath event - event dispatching cancelled"); 70 throw se; 71 } 72 } 73 } 74 75 78 public void onExecute(String command, long elapsedTime) 79 { 80 Object [] listeners = getListeners(); 81 82 for(int i=0; i<listeners.length; i++) { 83 try { 84 ConnectionListenerIF connectionListener = (ConnectionListenerIF) listeners[i]; 85 connectionListener.onExecute(command, elapsedTime); 86 } 87 catch (RuntimeException re) { 88 LOG.warn("RuntimeException received from listener "+listeners[i]+" when dispatching onExecute event", re); 89 } 90 } 91 } 92 93 96 public void onFail(String command, Exception exception) 97 { 98 Object [] listeners = getListeners(); 99 100 for(int i=0; i<listeners.length; i++) { 101 try { 102 ConnectionListenerIF connectionListener = (ConnectionListenerIF) listeners[i]; 103 connectionListener.onFail(command, exception); 104 } 105 catch (RuntimeException re) { 106 LOG.warn("RuntimeException received from listener "+listeners[i]+" when dispatching onFail event", re); 107 } 108 } 109 } 110 } 111 112 | Popular Tags |