View Javadoc

1   /**
2    * Copyright (c) 2004-2011 QOS.ch
3    * All rights reserved.
4    *
5    * Permission is hereby granted, free  of charge, to any person obtaining
6    * a  copy  of this  software  and  associated  documentation files  (the
7    * "Software"), to  deal in  the Software without  restriction, including
8    * without limitation  the rights to  use, copy, modify,  merge, publish,
9    * distribute,  sublicense, and/or sell  copies of  the Software,  and to
10   * permit persons to whom the Software  is furnished to do so, subject to
11   * the following conditions:
12   *
13   * The  above  copyright  notice  and  this permission  notice  shall  be
14   * included in all copies or substantial portions of the Software.
15   *
16   * THE  SOFTWARE IS  PROVIDED  "AS  IS", WITHOUT  WARRANTY  OF ANY  KIND,
17   * EXPRESS OR  IMPLIED, INCLUDING  BUT NOT LIMITED  TO THE  WARRANTIES OF
18   * MERCHANTABILITY,    FITNESS    FOR    A   PARTICULAR    PURPOSE    AND
19   * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20   * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21   * OF CONTRACT, TORT OR OTHERWISE,  ARISING FROM, OUT OF OR IN CONNECTION
22   * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23   *
24   */
25  package org.slf4j.spi;
26  
27  import java.util.Map;
28  
29  /**
30   * This interface abstracts the service offered by various MDC
31   * implementations.
32   * 
33   * @author Ceki Gülcü
34   * @since 1.4.1
35   */
36  public interface MDCAdapter {
37  
38    /**
39     * Put a context value (the <code>val</code> parameter) as identified with
40     * the <code>key</code> parameter into the current thread's context map. 
41     * The <code>key</code> parameter cannot be null. The code>val</code> parameter 
42     * can be null only if the underlying implementation supports it.
43     * 
44     * <p>If the current thread does not have a context map it is created as a side
45     * effect of this call.
46     */
47    public void put(String key, String val);
48  
49    /**
50     * Get the context identified by the <code>key</code> parameter.
51     * The <code>key</code> parameter cannot be null.
52     * 
53     * @return the string value identified by the <code>key</code> parameter.
54     */
55    public String get(String key);
56  
57    /**
58     * Remove the the context identified by the <code>key</code> parameter. 
59     * The <code>key</code> parameter cannot be null. 
60     * 
61     * <p>
62     * This method does nothing if there is no previous value 
63     * associated with <code>key</code>.
64     */
65    public void remove(String key);
66  
67    /**
68     * Clear all entries in the MDC.
69     */
70    public void clear();
71  
72    /**
73     * Return a copy of the current thread's context map, with keys and 
74     * values of type String. Returned value may be null.
75     * 
76     * @return A copy of the current thread's context map. May be null.
77     * @since 1.5.1
78     */
79    public Map getCopyOfContextMap();
80    
81    /**
82     * Set the current thread's context map by first clearing any existing 
83     * map and then copying the map passed as parameter. The context map 
84     * parameter must only contain keys and values of type String.
85     * 
86     * @param contextMap must contain only keys and values of type String
87     * 
88     * @since 1.5.1
89     */
90    public void setContextMap(Map contextMap);
91  }