Categories:
Audio (13)
Biotech (29)
Bytecode (36)
Database (77)
Framework (7)
Game (7)
General (507)
Graphics (53)
I/O (35)
IDE (2)
JAR Tools (101)
JavaBeans (21)
JDBC (121)
JDK (426)
JSP (20)
Logging (108)
Mail (58)
Messaging (8)
Network (84)
PDF (97)
Report (7)
Scripting (84)
Security (32)
Server (121)
Servlet (26)
SOAP (24)
Testing (54)
Web (15)
XML (309)
Collections:
Other Resources:
Source Code for Apache Log4j API
Apache Log4j API
provides the interface that applications should code to and provides the adapter
components required for implementers to create a logging implementation.
Apache Log4j API is a required module to use Apache Log4j.
Bytecode (Java 8) for Apache Log4j API is provided in a separate JAR file like log4j-api-2.14.1.jar.
Source Code files for Apache Log4j API are provided in both binary packge like apache-log4j-2.14.1-bin.zip and source package like apache-log4j-2.14.1-src.zip. You can download them at Apache Log4j Website.
You can also browse Source Code files for Apache Log4j API 2.14.1 below.
✍: FYIcenter.com
⏎ org/apache/logging/log4j/spi/CopyOnWriteSortedArrayThreadContextMap.java
/* * 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; import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.Objects; import org.apache.logging.log4j.util.ReadOnlyStringMap; import org.apache.logging.log4j.util.SortedArrayStringMap; import org.apache.logging.log4j.util.StringMap; import org.apache.logging.log4j.util.PropertiesUtil; /** * {@code SortedArrayStringMap}-based implementation of the {@code ThreadContextMap} interface that creates a copy of * the data structure on every modification. Any particular instance of the data structure is a snapshot of the * ThreadContext at some point in time and can safely be passed off to other threads. Since it is * expected that the Map will be passed to many more log events than the number of keys it contains the performance * should be much better than if the Map was copied for each event. * * @since 2.7 */ class CopyOnWriteSortedArrayThreadContextMap implements ReadOnlyThreadContextMap, ObjectThreadContextMap, CopyOnWrite { /** * Property name ({@value} ) for selecting {@code InheritableThreadLocal} (value "true") or plain * {@code ThreadLocal} (value is not "true") in the implementation. */ public static final String INHERITABLE_MAP = "isThreadContextMapInheritable"; /** * The default initial capacity. */ protected static final int DEFAULT_INITIAL_CAPACITY = 16; /** * System property name that can be used to control the data structure's initial capacity. */ protected static final String PROPERTY_NAME_INITIAL_CAPACITY = "log4j2.ThreadContext.initial.capacity"; private static final StringMap EMPTY_CONTEXT_DATA = new SortedArrayStringMap(1); private static volatile int initialCapacity; private static volatile boolean inheritableMap; /** * Initializes static variables based on system properties. Normally called when this class is initialized by the VM * and when Log4j is reconfigured. */ static void init() { final PropertiesUtil properties = PropertiesUtil.getProperties(); initialCapacity = properties.getIntegerProperty(PROPERTY_NAME_INITIAL_CAPACITY, DEFAULT_INITIAL_CAPACITY); inheritableMap = properties.getBooleanProperty(INHERITABLE_MAP); } static { EMPTY_CONTEXT_DATA.freeze(); init(); } private final ThreadLocal<StringMap> localMap; public CopyOnWriteSortedArrayThreadContextMap() { this.localMap = createThreadLocalMap(); } // LOG4J2-479: by default, use a plain ThreadLocal, only use InheritableThreadLocal if configured. // (This method is package protected for JUnit tests.) private ThreadLocal<StringMap> createThreadLocalMap() { if (inheritableMap) { return new InheritableThreadLocal<StringMap>() { @Override protected StringMap childValue(final StringMap parentValue) { if (parentValue == null) { return null; } final StringMap stringMap = createStringMap(parentValue); stringMap.freeze(); return stringMap; } }; } // if not inheritable, return plain ThreadLocal with null as initial value return new ThreadLocal<>(); } /** * Returns an implementation of the {@code StringMap} used to back this thread context map. * <p> * Subclasses may override. * </p> * @return an implementation of the {@code StringMap} used to back this thread context map */ protected StringMap createStringMap() { return new SortedArrayStringMap(initialCapacity); } /** * Returns an implementation of the {@code StringMap} used to back this thread context map, pre-populated * with the contents of the specified context data. * <p> * Subclasses may override. * </p> * @param original the key-value pairs to initialize the returned context data with * @return an implementation of the {@code StringMap} used to back this thread context map */ protected StringMap createStringMap(final ReadOnlyStringMap original) { return new SortedArrayStringMap(original); } @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); map.freeze(); localMap.set(map); } @Override public void putAll(final Map<String, String> values) { if (values == null || values.isEmpty()) { return; } StringMap map = localMap.get(); map = map == null ? createStringMap() : createStringMap(map); for (final Map.Entry<String, String> entry : values.entrySet()) { map.putValue(entry.getKey(), entry.getValue()); } map.freeze(); localMap.set(map); } @Override public <V> void putAllValues(final Map<String, V> values) { if (values == null || values.isEmpty()) { return; } StringMap map = localMap.get(); map = map == null ? createStringMap() : createStringMap(map); for (final Map.Entry<String, V> entry : values.entrySet()) { map.putValue(entry.getKey(), entry.getValue()); } map.freeze(); localMap.set(map); } @Override public String get(final String key) { return (String) getValue(key); } @Override public <V> V getValue(final String key) { final StringMap map = localMap.get(); return map == null ? null : map.<V>getValue(key); } @Override public void remove(final String key) { final StringMap map = localMap.get(); if (map != null) { final StringMap copy = createStringMap(map); copy.remove(key); copy.freeze(); localMap.set(copy); } } @Override public void removeAll(final Iterable<String> keys) { final StringMap map = localMap.get(); if (map != null) { final StringMap copy = createStringMap(map); for (final String key : keys) { copy.remove(key); } copy.freeze(); localMap.set(copy); } } @Override public void clear() { localMap.remove(); } @Override public boolean containsKey(final String key) { final StringMap map = localMap.get(); return map != null && map.containsKey(key); } @Override public Map<String, String> getCopy() { final StringMap map = localMap.get(); return map == null ? new HashMap<>() : map.toMap(); } /** * {@inheritDoc} */ @Override public StringMap getReadOnlyContextData() { final StringMap map = localMap.get(); return map == null ? EMPTY_CONTEXT_DATA : map; } @Override public Map<String, String> getImmutableMapOrNull() { final StringMap map = localMap.get(); return map == null ? null : Collections.unmodifiableMap(map.toMap()); } @Override public boolean isEmpty() { final StringMap map = localMap.get(); return map == null || map.isEmpty(); } @Override public String toString() { final StringMap map = localMap.get(); return map == null ? "{}" : map.toString(); } @Override public int hashCode() { final int prime = 31; int result = 1; final StringMap map = this.localMap.get(); result = prime * result + ((map == null) ? 0 : map.hashCode()); return result; } @Override public boolean equals(final Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (!(obj instanceof ThreadContextMap)) { return false; } final ThreadContextMap other = (ThreadContextMap) obj; final Map<String, String> map = this.getImmutableMapOrNull(); final Map<String, String> otherMap = other.getImmutableMapOrNull(); return Objects.equals(map, otherMap); } }
⏎ org/apache/logging/log4j/spi/CopyOnWriteSortedArrayThreadContextMap.java
Or download all of them as a single archive file:
File name: log4j-api-2.14.1-sources.jar File size: 264773 bytes Release date: 2021-03-06 Download
⇒ Source Code for Apache Log4j Core Implementation
⇐ Downloading Apache Log4j Binary Package
2015-11-17, 23401👍, 0💬
Popular Posts:
JDK 11 jdk.hotspot.agent.jmod is the JMOD file for JDK 11 Hotspot Agent module. JDK 11 Hotspot Agent...
commons-lang-1.0.1.jar is the JAR file for Apache Commons Lang 1.0.1, which provides a host of helpe...
The Java Naming and Directory Interface (JNDI) is part of the Java platform, providing applications ...
Apache Log4j API provides the interface that applications should code to and provides the adapter co...
Guava is a suite of core and expanded libraries that include utility classes, google's collections, ...