private static ThreadContextMap createDefaultThreadContextMap() { if (Constants.ENABLE_THREADLOCALS) { if (GcFreeThreadContextKey) { return new GarbageFreeSortedArrayThreadContextMap(); } return new CopyOnWriteSortedArrayThreadContextMap(); } return new DefaultThreadContextMap(true); } }
@Override protected StringMap childValue(final StringMap parentValue) { if (parentValue == null) { return null; } StringMap stringMap = createStringMap(parentValue); stringMap.freeze(); return stringMap; } };
public CopyOnWriteSortedArrayThreadContextMap() { this.localMap = createThreadLocalMap(); }
@Override public String get(final String key) { return (String) getValue(key); }
@Override public void put(final String key, final String value) { putValue(key, value); }
@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(); if (map == null) { if (otherMap != null) { return false; } } else if (!map.equals(otherMap)) { return false; } return true; } }
/** * Initializes static variables based on system properties. Normally called when this class is initialized by the VM * and when Log4j is reconfigured. */ public static void init() { CopyOnWriteSortedArrayThreadContextMap.init(); GarbageFreeSortedArrayThreadContextMap.init(); DefaultThreadContextMap.init(); initPrivate(); }
@Override public String get(final String key) { return (String) getValue(key); }
@Override public void put(final String key, final String value) { putValue(key, value); }
@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(); if (map == null) { if (otherMap != null) { return false; } } else if (!map.equals(otherMap)) { return false; } return true; } }
@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); }
private static ThreadContextMap createDefaultThreadContextMap() { if (Constants.ENABLE_THREADLOCALS) { if (PropertiesUtil.getProperties().getBooleanProperty(GC_FREE_THREAD_CONTEXT_KEY)) { return new GarbageFreeSortedArrayThreadContextMap(); } return new CopyOnWriteSortedArrayThreadContextMap(); } return new DefaultThreadContextMap(true); } }
public CopyOnWriteSortedArrayThreadContextMap() { this.localMap = createThreadLocalMap(); }
@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 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 protected StringMap childValue(final StringMap parentValue) { return parentValue != null ? createStringMap(parentValue) : null; } };
@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); }