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 */ 017package org.slf4j.helpers; 018 019import java.util.concurrent.ConcurrentHashMap; 020import java.util.concurrent.ConcurrentMap; 021 022import org.slf4j.IMarkerFactory; 023import org.slf4j.Marker; 024 025/** 026 * 027 */ 028public class Log4jMarkerFactory implements IMarkerFactory { 029 030 private final ConcurrentMap<String, Marker> markerMap = new ConcurrentHashMap<String, Marker>(); 031 032 @Override 033 public Marker getMarker(final String name) { 034 if (name == null) { 035 throw new IllegalArgumentException("Marker name must not be null"); 036 } 037 Marker marker = markerMap.get(name); 038 if (marker != null) { 039 return marker; 040 } 041 marker = new MarkerWrapper(name); 042 final Marker existing = markerMap.putIfAbsent(name, marker); 043 return existing == null ? marker : existing; 044 } 045 046 @Override 047 public boolean exists(final String name) { 048 return markerMap.containsKey(name); 049 } 050 051 @Override 052 public boolean detachMarker(final String name) { 053 return false; 054 } 055 056 @Override 057 public Marker getDetachedMarker(final String name) { 058 return new MarkerWrapper(name); 059 } 060}