"git@git.gitsec.cn:baidan/clutch.git" did not exist on "7ffe90b520d5a4edb4876408c978569d985c26ba"
Commit e0058d67 authored by rpopma's avatar rpopma
Browse files

LOG4J2-1648 SPI interface for putting Object values in the ThreadContextMap...

LOG4J2-1648 SPI interface for putting Object values in the ThreadContextMap (no end-user visible API yet)
parent 76961207
Showing with 68 additions and 4 deletions
+68 -4
......@@ -34,7 +34,7 @@ import org.apache.logging.log4j.util.PropertiesUtil;
*
* @since 2.7
*/
class CopyOnWriteSortedArrayThreadContextMap implements ReadOnlyThreadContextMap, ThreadContextMap2, CopyOnWrite {
class CopyOnWriteSortedArrayThreadContextMap implements ReadOnlyThreadContextMap, ObjectThreadContextMap, CopyOnWrite {
/**
* Property name ({@value} ) for selecting {@code InheritableThreadLocal} (value "true") or plain
......@@ -107,6 +107,11 @@ class CopyOnWriteSortedArrayThreadContextMap implements ReadOnlyThreadContextMap
@Override
public void put(final String key, final String value) {
putValue(key, value);
}
@Override
public void putValue(final String key, final Object value) {
StringMap map = localMap.get();
map = map == null ? createStringMap() : createStringMap(map);
map.putValue(key, value);
......@@ -130,8 +135,13 @@ class CopyOnWriteSortedArrayThreadContextMap implements ReadOnlyThreadContextMap
@Override
public String get(final String key) {
return (String) getValue(key);
}
@Override
public Object getValue(final String key) {
final StringMap map = localMap.get();
return map == null ? null : (String) map.getValue(key);
return map == null ? null : map.getValue(key);
}
@Override
......
......@@ -34,7 +34,7 @@ import org.apache.logging.log4j.util.SortedArrayStringMap;
* </p>
* @since 2.7
*/
class GarbageFreeSortedArrayThreadContextMap implements ReadOnlyThreadContextMap, ThreadContextMap2 {
class GarbageFreeSortedArrayThreadContextMap implements ReadOnlyThreadContextMap, ObjectThreadContextMap {
/**
* Property name ({@value} ) for selecting {@code InheritableThreadLocal} (value "true") or plain
......@@ -114,6 +114,11 @@ class GarbageFreeSortedArrayThreadContextMap implements ReadOnlyThreadContextMap
getThreadLocalMap().putValue(key, value);
}
@Override
public void putValue(final String key, final Object value) {
getThreadLocalMap().putValue(key, value);
}
@Override
public void putAll(final Map<String, String> values) {
if (values == null || values.isEmpty()) {
......@@ -127,8 +132,13 @@ class GarbageFreeSortedArrayThreadContextMap implements ReadOnlyThreadContextMap
@Override
public String get(final String key) {
return (String) getValue(key);
}
@Override
public Object getValue(final String key) {
final StringMap map = localMap.get();
return map == null ? null : (String) map.getValue(key);
return map == null ? null : map.getValue(key);
}
@Override
......
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache license, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the license for the specific language governing permissions and
* limitations under the license.
*/
package org.apache.logging.log4j.spi;
/**
* Extension service provider interface to allow putting Object values in the
* {@link org.apache.logging.log4j.ThreadContext}.
*
* @see ThreadContextMap2
* @since 2.8
*/
public interface ObjectThreadContextMap extends ThreadContextMap2 {
/**
* Returns the Object value for the specified key, or {@code null} if the specified key does not exist in this
* collection.
*
* @param key the key whose value to return
* @return the value for the specified key or {@code null}
*/
<V> V getValue(String key);
/**
* Puts the specified key-value pair into the collection.
*
* @param key the key to add or remove. Keys may be {@code null}.
* @param value the value to add. Values may be {@code null}.
*/
<V> void putValue(String key, V value);
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment