View Javadoc

1   /*
2    *   @(#) $Id: ProtocolLoggingFilter.java 357871 2005-12-20 01:56:40Z trustin $
3    *
4    *   Copyright 2004 The Apache Software Foundation
5    *
6    *   Licensed under the Apache License, Version 2.0 (the "License");
7    *   you may not use this file except in compliance with the License.
8    *   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   */
19  package org.apache.mina.protocol.filter;
20  
21  import org.apache.mina.common.IdleStatus;
22  import org.apache.mina.protocol.ProtocolFilter;
23  import org.apache.mina.protocol.ProtocolSession;
24  import org.apache.mina.util.SessionLog;
25  import org.slf4j.Logger;
26  
27  /***
28   * Logs all MINA protocol events to {@link Logger}.
29   * 
30   * @author The Apache Directory Project (dev@directory.apache.org)
31   * @version $Rev: 357871 $, $Date: 2005-12-20 10:56:40 +0900 (Tue, 20 Dec 2005) $
32   * 
33   * @see SessionLog
34   */
35  public class ProtocolLoggingFilter implements ProtocolFilter
36  {
37      /***
38       * Session attribute key: prefix string
39       */
40      public static final String PREFIX = SessionLog.PREFIX;
41  
42      /***
43       * Session attribute key: {@link Logger}
44       */
45      public static final String LOGGER = SessionLog.LOGGER;
46      
47      /***
48       * Creates a new instance.
49       */
50      public ProtocolLoggingFilter()
51      {
52      }
53      
54      public void sessionOpened( NextFilter nextFilter, ProtocolSession session )
55      {
56          SessionLog.info( session, "OPENED" );
57          nextFilter.sessionOpened( session );
58      }
59  
60      public void sessionClosed( NextFilter nextFilter, ProtocolSession session )
61      {
62          SessionLog.info( session, "CLOSED" );
63          nextFilter.sessionClosed( session );
64      }
65  
66      public void sessionIdle( NextFilter nextFilter, ProtocolSession session, IdleStatus status )
67      {
68          SessionLog.info( session, "IDLE: " + status );
69          nextFilter.sessionIdle( session, status );
70      }
71  
72      public void exceptionCaught( NextFilter nextFilter, ProtocolSession session, Throwable cause )
73      {
74          SessionLog.error( session, "EXCEPTION:", cause );
75          nextFilter.exceptionCaught( session, cause );
76      }
77  
78      public void messageReceived( NextFilter nextFilter, ProtocolSession session, Object message )
79      {
80          SessionLog.info( session, "RECEIVED: " + message );
81          nextFilter.messageReceived( session, message );
82      }
83  
84      public void messageSent( NextFilter nextFilter, ProtocolSession session, Object message )
85      {
86          SessionLog.info( session, "SENT: " + message );
87          nextFilter.messageSent( session, message );
88      }
89  
90      public void filterWrite( NextFilter nextFilter, ProtocolSession session, Object message)
91      {
92          SessionLog.info( session, "WRITE: " + message );
93          nextFilter.filterWrite( session, message );
94      }
95  }