1 18 package org.apache.activemq.transport; 19 20 import java.io.IOException ; 21 22 import org.apache.commons.logging.Log; 23 import org.apache.commons.logging.LogFactory; 24 25 26 29 public class TransportLogger extends TransportFilter { 30 31 private static int lastId=0; 32 private final Log log; 33 34 public TransportLogger(Transport next) { 35 this( next, LogFactory.getLog(TransportLogger.class.getName()+".Connection:"+getNextId())); 36 } 37 38 synchronized private static int getNextId() { 39 return ++lastId; 40 } 41 42 public TransportLogger(Transport next, Log log) { 43 super(next); 44 this.log = log; 45 } 46 47 public Object request(Object command) throws IOException { 48 log.debug("SENDING REQUEST: "+command); 49 Object rc = super.request(command); 50 log.debug("GOT RESPONSE: "+rc); 51 return rc; 52 } 53 54 public Object request(Object command, int timeout) throws IOException { 55 log.debug("SENDING REQUEST: "+command); 56 Object rc = super.request(command, timeout); 57 log.debug("GOT RESPONSE: "+rc); 58 return rc; 59 } 60 61 public FutureResponse asyncRequest(Object command, ResponseCallback responseCallback) throws IOException { 62 log.debug("SENDING ASNYC REQUEST: "+command); 63 FutureResponse rc = next.asyncRequest(command, responseCallback); 64 return rc; 65 } 66 67 public void oneway(Object command) throws IOException { 68 if( log.isDebugEnabled() ) { 69 log.debug("SENDING: "+command); 70 } 71 next.oneway(command); 72 } 73 74 public void onCommand(Object command) { 75 if( log.isDebugEnabled() ) { 76 log.debug("RECEIVED: " + command); 77 } 78 getTransportListener().onCommand(command); 79 } 80 81 public void onException(IOException error) { 82 if( log.isDebugEnabled() ) { 83 log.debug("RECEIVED Exception: "+error, error); 84 } 85 getTransportListener().onException(error); 86 } 87 88 public String toString() { 89 return next.toString(); 90 } 91 } 92 | Popular Tags |