org.apache.mina.filter.logging
Class MdcInjectionFilter

java.lang.Object
  extended by org.apache.mina.core.filterchain.IoFilterAdapter
      extended by org.apache.mina.filter.util.CommonEventFilter
          extended by org.apache.mina.filter.logging.MdcInjectionFilter
All Implemented Interfaces:
IoFilter

public class MdcInjectionFilter
extends CommonEventFilter

This filter will inject some key IoSession properties into the Mapped Diagnostic Context (MDC)

These properties will be set in the MDC for all logging events that are generated down the call stack, even in code that is not aware of MINA. By default, the following properties will be set for all transports:

When session.getTransportMetadata().getAddressType() == InetSocketAddress.class the following properties will also be set: User code can also add properties to the context, via If you only want the MDC to be set for the IoHandler code, it's enough to add one MdcInjectionFilter at the end of the filter chain. If you want the MDC to be set for ALL code, you should add an MdcInjectionFilter to the start of the chain and add that same MdcInjectionFilter instance after EVERY ExecutorFilter in the chain Thus it's ok to have one instance of the MdcInjectionFilter and add it multiple times to the chain but you should avoid adding multiple instances to the chain.

Version:
$Rev: 566952 $, $Date: 2007-08-17 09:25:04 +0200 (vr, 17 aug 2007) $
Author:
The Apache MINA Project (dev@mina.apache.org)

Nested Class Summary
static class MdcInjectionFilter.MdcKey
           
 
Nested classes/interfaces inherited from interface org.apache.mina.core.filterchain.IoFilter
IoFilter.NextFilter
 
Constructor Summary
MdcInjectionFilter()
           
MdcInjectionFilter(EnumSet<MdcInjectionFilter.MdcKey> keys)
          Use this constructor when you want to specify which keys to add to the MDC.
MdcInjectionFilter(MdcInjectionFilter.MdcKey... keys)
          Use this constructor when you want to specify which keys to add to the MDC You could still add custom keys via setProperty(IoSession, String, String)
 
Method Summary
protected  void fillContext(IoSession session, Map<String,String> context)
          write key properties of the session to the Mapped Diagnostic Context sub-classes could override this method to map more/other attributes
protected  void filter(IoFilterEvent event)
           
static String getProperty(IoSession session, String key)
           
static void removeProperty(IoSession session, String key)
           
static void setProperty(IoSession session, String key, String value)
          Add a property to the context for the given session This property will be added to the MDC for all subsequent events
 
Methods inherited from class org.apache.mina.filter.util.CommonEventFilter
exceptionCaught, filterClose, filterWrite, messageReceived, messageSent, sessionClosed, sessionCreated, sessionIdle, sessionOpened
 
Methods inherited from class org.apache.mina.core.filterchain.IoFilterAdapter
destroy, init, onPostAdd, onPostRemove, onPreAdd, onPreRemove, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MdcInjectionFilter

public MdcInjectionFilter(EnumSet<MdcInjectionFilter.MdcKey> keys)
Use this constructor when you want to specify which keys to add to the MDC. You could still add custom keys via setProperty(IoSession, String, String)

Parameters:
keys - set of keys that should be added to the MDC
See Also:
setProperty(org.apache.mina.core.session.IoSession, String, String)

MdcInjectionFilter

public MdcInjectionFilter(MdcInjectionFilter.MdcKey... keys)
Use this constructor when you want to specify which keys to add to the MDC You could still add custom keys via setProperty(IoSession, String, String)

Parameters:
keys - list of keys that should be added to the MDC
See Also:
setProperty(org.apache.mina.core.session.IoSession, String, String)

MdcInjectionFilter

public MdcInjectionFilter()
Method Detail

filter

protected void filter(IoFilterEvent event)
               throws Exception
Specified by:
filter in class CommonEventFilter
Throws:
Exception

fillContext

protected void fillContext(IoSession session,
                           Map<String,String> context)
write key properties of the session to the Mapped Diagnostic Context sub-classes could override this method to map more/other attributes

Parameters:
session - the session to map
context - key properties will be added to this map

getProperty

public static String getProperty(IoSession session,
                                 String key)

setProperty

public static void setProperty(IoSession session,
                               String key,
                               String value)
Add a property to the context for the given session This property will be added to the MDC for all subsequent events

Parameters:
session - The session for which you want to set a property
key - The name of the property (should not be null)
value - The value of the property

removeProperty

public static void removeProperty(IoSession session,
                                  String key)


Copyright © 2004-2010 Apache MINA Project. All Rights Reserved.