001/**
002 * Copyright (c) 2004-2011 QOS.ch
003 * All rights reserved.
004 *
005 * Permission is hereby granted, free  of charge, to any person obtaining
006 * a  copy  of this  software  and  associated  documentation files  (the
007 * "Software"), to  deal in  the Software without  restriction, including
008 * without limitation  the rights to  use, copy, modify,  merge, publish,
009 * distribute,  sublicense, and/or sell  copies of  the Software,  and to
010 * permit persons to whom the Software  is furnished to do so, subject to
011 * the following conditions:
012 *
013 * The  above  copyright  notice  and  this permission  notice  shall  be
014 * included in all copies or substantial portions of the Software.
015 *
016 * THE  SOFTWARE IS  PROVIDED  "AS  IS", WITHOUT  WARRANTY  OF ANY  KIND,
017 * EXPRESS OR  IMPLIED, INCLUDING  BUT NOT LIMITED  TO THE  WARRANTIES OF
018 * MERCHANTABILITY,    FITNESS    FOR    A   PARTICULAR    PURPOSE    AND
019 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
020 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
021 * OF CONTRACT, TORT OR OTHERWISE,  ARISING FROM, OUT OF OR IN CONNECTION
022 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
023 *
024 */
025package org.slf4j.spi;
026
027import java.util.Deque;
028import java.util.Map;
029
030/**
031 * This interface abstracts the service offered by various MDC
032 * implementations.
033 * 
034 * @author Ceki Gülcü
035 * @since 1.4.1
036 */
037public interface MDCAdapter {
038
039    /**
040     * Put a context value (the <code>val</code> parameter) as identified with
041     * the <code>key</code> parameter into the current thread's context map. 
042     * The <code>key</code> parameter cannot be null. The <code>val</code> parameter
043     * can be null only if the underlying implementation supports it.
044     * 
045     * <p>If the current thread does not have a context map it is created as a side
046     * effect of this call.
047     */
048    public void put(String key, String val);
049
050    /**
051     * Get the context identified by the <code>key</code> parameter.
052     * The <code>key</code> parameter cannot be null.
053     * 
054     * @return the string value identified by the <code>key</code> parameter.
055     */
056    public String get(String key);
057
058    /**
059     * Remove the context identified by the <code>key</code> parameter.
060     * The <code>key</code> parameter cannot be null. 
061     * 
062     * <p>
063     * This method does nothing if there is no previous value 
064     * associated with <code>key</code>.
065     */
066    public void remove(String key);
067
068    /**
069     * Clear all entries in the MDC.
070     */
071    public void clear();
072
073    /**
074     * Return a copy of the current thread's context map, with keys and 
075     * values of type String. Returned value may be null.
076     * 
077     * @return A copy of the current thread's context map. May be null.
078     * @since 1.5.1
079     */
080    public Map<String, String> getCopyOfContextMap();
081
082    /**
083     * Set the current thread's context map by first clearing any existing 
084     * map and then copying the map passed as parameter. The context map 
085     * parameter must only contain keys and values of type String.
086     * 
087     * Implementations must support null valued map passed as parameter.
088     * 
089     * @param contextMap must contain only keys and values of type String
090     * 
091     * @since 1.5.1
092     */
093    public void setContextMap(Map<String, String> contextMap);
094    
095    /**
096     * Push a value into the deque(stack) referenced by 'key'.
097     *      
098     * @param key identifies the appropriate stack
099     * @param value the value to push into the stack
100     * @since 2.0.0
101     */
102    public void pushByKey(String key, String value);
103    
104    /**
105     * Pop the stack referenced by 'key' and return the value possibly null.
106     * 
107     * @param key identifies the deque(stack)
108     * @return the value just popped. May be null/
109     * @since 2.0.0
110     */
111    public String popByKey(String key);
112
113    /**
114     * Returns a copy of the deque(stack) referenced by 'key'. May be null.
115     * 
116     * @param key identifies the  stack
117     * @return copy of stack referenced by 'key'. May be null.
118     * 
119     * @since 2.0.0
120     */
121    public Deque<String>  getCopyOfDequeByKey(String key);
122    
123
124    /**
125     * Clear the deque(stack) referenced by 'key'. 
126     * 
127     * @param key identifies the  stack
128     * 
129     * @since 2.0.0
130     */
131    public void clearDequeByKey(String key);
132    
133}