001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements. See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache license, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License. You may obtain a copy of the License at
008     *
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the license for the specific language governing permissions and
015     * limitations under the license.
016     */
017    package org.apache.logging.log4j.spi;
018    
019    import java.util.Map;
020    
021    /**
022     * Service provider interface to implement custom MDC behavior for {@link org.apache.logging.log4j.ThreadContext}.
023     */
024    public interface ThreadContextMap {
025        /**
026         * Put a context value (the <code>o</code> parameter) as identified
027         * with the <code>key</code> parameter into the current thread's
028         * context map.
029         *
030         * <p>If the current thread does not have a context map it is
031         * created as a side effect.</p>
032         * @param key The key name.
033         * @param value The key value.
034         */
035        void put(final String key, final String value);
036    
037        /**
038         * Get the context identified by the <code>key</code> parameter.
039         *
040         * <p>This method has no side effects.</p>
041         * @param key The key to locate.
042         * @return The value associated with the key or null.
043         */
044        String get(final String key);
045    
046        /**
047         * Remove the the context identified by the <code>key</code>
048         * parameter.
049         * @param key The key to remove.
050         */
051        void remove(final String key);
052    
053        /**
054         * Clear the context.
055         */
056        void clear();
057    
058        /**
059         * Determine if the key is in the context.
060         * @param key The key to locate.
061         * @return True if the key is in the context, false otherwise.
062         */
063        boolean containsKey(final String key);
064    
065        /**
066         * Get a non-{@code null} mutable copy of current thread's context Map.
067         * @return a mutable copy of the context.
068         */
069        Map<String, String> getCopy();
070    
071        /**
072         * Return an immutable view on the context Map or {@code null} if the context map is empty.
073         * @return an immutable context Map or {@code null}.
074         */
075        Map<String, String> getImmutableMapOrNull();
076    
077        /**
078         * Returns true if the Map is empty.
079         * @return true if the Map is empty, false otherwise.
080         */
081        boolean isEmpty();
082    }