1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache license, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the license for the specific language governing permissions and
15 * limitations under the license.
16 */
17 package org.apache.logging.log4j.spi;
18
19 import java.util.Map;
20
21 /**
22 * Service provider interface to implement custom MDC behavior for {@link org.apache.logging.log4j.ThreadContext}.
23 */
24 public interface ThreadContextMap {
25 /**
26 * Put a context value (the <code>o</code> parameter) as identified
27 * with the <code>key</code> parameter into the current thread's
28 * context map.
29 *
30 * <p>If the current thread does not have a context map it is
31 * created as a side effect.</p>
32 * @param key The key name.
33 * @param value The key value.
34 */
35 void put(final String key, final String value);
36
37 /**
38 * Get the context identified by the <code>key</code> parameter.
39 *
40 * <p>This method has no side effects.</p>
41 * @param key The key to locate.
42 * @return The value associated with the key or null.
43 */
44 String get(final String key);
45
46 /**
47 * Remove the the context identified by the <code>key</code>
48 * parameter.
49 * @param key The key to remove.
50 */
51 void remove(final String key);
52
53 /**
54 * Clear the context.
55 */
56 void clear();
57
58 /**
59 * Determine if the key is in the context.
60 * @param key The key to locate.
61 * @return True if the key is in the context, false otherwise.
62 */
63 boolean containsKey(final String key);
64
65 /**
66 * Get a non-{@code null} mutable copy of current thread's context Map.
67 * @return a mutable copy of the context.
68 */
69 Map<String, String> getCopy();
70
71 /**
72 * Return an immutable view on the context Map or {@code null} if the context map is empty.
73 * @return an immutable context Map or {@code null}.
74 */
75 Map<String, String> getImmutableMapOrNull();
76
77 /**
78 * Returns true if the Map is empty.
79 * @return true if the Map is empty, false otherwise.
80 */
81 boolean isEmpty();
82 }