KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > transport > TransportLogger


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.activemq.transport;
19
20 import java.io.IOException JavaDoc;
21
22 import org.apache.commons.logging.Log;
23 import org.apache.commons.logging.LogFactory;
24
25
26 /**
27  * @version $Revision$
28  */

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 JavaDoc request(Object JavaDoc command) throws IOException JavaDoc {
48         log.debug("SENDING REQUEST: "+command);
49         Object JavaDoc rc = super.request(command);
50         log.debug("GOT RESPONSE: "+rc);
51         return rc;
52     }
53     
54     public Object JavaDoc request(Object JavaDoc command, int timeout) throws IOException JavaDoc {
55         log.debug("SENDING REQUEST: "+command);
56         Object JavaDoc rc = super.request(command, timeout);
57         log.debug("GOT RESPONSE: "+rc);
58         return rc;
59     }
60     
61     public FutureResponse asyncRequest(Object JavaDoc command, ResponseCallback responseCallback) throws IOException JavaDoc {
62         log.debug("SENDING ASNYC REQUEST: "+command);
63         FutureResponse rc = next.asyncRequest(command, responseCallback);
64         return rc;
65     }
66     
67     public void oneway(Object JavaDoc command) throws IOException JavaDoc {
68         if( log.isDebugEnabled() ) {
69             log.debug("SENDING: "+command);
70         }
71         next.oneway(command);
72     }
73     
74     public void onCommand(Object JavaDoc command) {
75         if( log.isDebugEnabled() ) {
76             log.debug("RECEIVED: " + command);
77         }
78         getTransportListener().onCommand(command);
79     }
80     
81     public void onException(IOException JavaDoc error) {
82         if( log.isDebugEnabled() ) {
83             log.debug("RECEIVED Exception: "+error, error);
84         }
85         getTransportListener().onException(error);
86     }
87     
88     public String JavaDoc toString() {
89         return next.toString();
90     }
91 }
92
Popular Tags