1 25 package com.mysql.jdbc.profiler; 26 27 import com.mysql.jdbc.Connection; 28 import com.mysql.jdbc.log.Log; 29 30 import java.sql.SQLException ; 31 import java.util.HashMap ; 32 import java.util.Map ; 33 34 37 public class ProfileEventSink { 38 39 private static final Map CONNECTIONS_TO_SINKS = new HashMap (); 40 41 private Connection ownerConnection = null; 42 43 private Log log = null; 44 45 53 public static synchronized ProfileEventSink getInstance(Connection conn) { 54 ProfileEventSink sink = (ProfileEventSink) CONNECTIONS_TO_SINKS 55 .get(conn); 56 57 if (sink == null) { 58 sink = new ProfileEventSink(conn); 59 CONNECTIONS_TO_SINKS.put(conn, sink); 60 } 61 62 return sink; 63 } 64 65 71 public void consumeEvent(ProfilerEvent evt) { 72 if (evt.eventType == ProfilerEvent.TYPE_WARN) { 73 this.log.logWarn(evt); 74 } else { 75 this.log.logInfo(evt); 76 } 77 } 78 79 private ProfileEventSink(Connection conn) { 80 this.ownerConnection = conn; 81 82 try { 83 this.log = this.ownerConnection.getLog(); 84 } catch (SQLException sqlEx) { 85 throw new RuntimeException ("Unable to get logger from connection"); 86 } 87 } 88 89 } 90 | Popular Tags |