3030import java .util .concurrent .locks .Lock ;
3131import java .util .concurrent .locks .ReadWriteLock ;
3232import java .util .concurrent .locks .ReentrantReadWriteLock ;
33- import java .util .function .BiFunction ;
3433import org .apache .logging .log4j .message .MessageFactory ;
3534import org .apache .logging .log4j .message .ParameterizedMessageFactory ;
36- import org .apache .logging .log4j .status .StatusLogger ;
37- import org .jspecify .annotations .NullMarked ;
38- import org .jspecify .annotations .Nullable ;
3935
4036/**
4137 * Convenience class to be used as an {@link ExtendedLogger} registry by {@code LoggerContext} implementations.
4238 */
43- @ NullMarked
4439public class LoggerRegistry <T extends ExtendedLogger > {
4540
4641 private final Map <String , Map <MessageFactory , WeakReference <T >>> loggerRefByMessageFactoryByName = new HashMap <>();
@@ -55,9 +50,7 @@ public class LoggerRegistry<T extends ExtendedLogger> {
5550 * Data structure contract for the internal storage of admitted loggers.
5651 *
5752 * @param <T> subtype of {@code ExtendedLogger}
58- * @deprecated As of version {@code 2.25.0}, planned to be removed!
5953 */
60- @ Deprecated
6154 public interface MapFactory <T extends ExtendedLogger > {
6255
6356 Map <String , T > createInnerMap ();
@@ -71,9 +64,7 @@ public interface MapFactory<T extends ExtendedLogger> {
7164 * {@link MapFactory} implementation using {@link ConcurrentHashMap}.
7265 *
7366 * @param <T> subtype of {@code ExtendedLogger}
74- * @deprecated As of version {@code 2.25.0}, planned to be removed!
7567 */
76- @ Deprecated
7768 public static class ConcurrentMapFactory <T extends ExtendedLogger > implements MapFactory <T > {
7869
7970 @ Override
@@ -96,9 +87,7 @@ public void putIfAbsent(final Map<String, T> innerMap, final String name, final
9687 * {@link MapFactory} implementation using {@link WeakHashMap}.
9788 *
9889 * @param <T> subtype of {@code ExtendedLogger}
99- * @deprecated As of version {@code 2.25.0}, planned to be removed!
10090 */
101- @ Deprecated
10291 public static class WeakMapFactory <T extends ExtendedLogger > implements MapFactory <T > {
10392
10493 @ Override
@@ -123,10 +112,8 @@ public LoggerRegistry() {}
123112 * Constructs an instance <b>ignoring</b> the given the map factory.
124113 *
125114 * @param mapFactory a map factory
126- * @deprecated As of version {@code 2.25.0}, planned to be removed!
127115 */
128- @ Deprecated
129- public LoggerRegistry (@ Nullable final MapFactory <T > mapFactory ) {
116+ public LoggerRegistry (final MapFactory <T > mapFactory ) {
130117 this ();
131118 }
132119
@@ -139,10 +126,7 @@ public LoggerRegistry(@Nullable final MapFactory<T> mapFactory) {
139126 *
140127 * @param name a logger name
141128 * @return the logger associated with the name
142- * @deprecated As of version {@code 2.25.0}, planned to be removed!
143- * Use {@link #getLogger(String, MessageFactory)} instead.
144129 */
145- @ Deprecated
146130 public T getLogger (final String name ) {
147131 requireNonNull (name , "name" );
148132 return getLogger (name , null );
@@ -160,7 +144,7 @@ public T getLogger(final String name) {
160144 * @param messageFactory a message factory
161145 * @return the logger associated with the given name and message factory
162146 */
163- public T getLogger (final String name , @ Nullable final MessageFactory messageFactory ) {
147+ public T getLogger (final String name , final MessageFactory messageFactory ) {
164148 requireNonNull (name , "name" );
165149 readLock .lock ();
166150 try {
@@ -209,10 +193,7 @@ public Collection<T> getLoggers(final Collection<T> destination) {
209193 *
210194 * @param name a logger name
211195 * @return {@code true}, if the logger exists; {@code false} otherwise.
212- * @deprecated As of version {@code 2.25.0}, planned to be removed!
213- * Use {@link #hasLogger(String, MessageFactory)} instead.
214196 */
215- @ Deprecated
216197 public boolean hasLogger (final String name ) {
217198 requireNonNull (name , "name" );
218199 final T logger = getLogger (name );
@@ -232,7 +213,7 @@ public boolean hasLogger(final String name) {
232213 * @return {@code true}, if the logger exists; {@code false} otherwise.
233214 * @since 2.5
234215 */
235- public boolean hasLogger (final String name , @ Nullable final MessageFactory messageFactory ) {
216+ public boolean hasLogger (final String name , final MessageFactory messageFactory ) {
236217 requireNonNull (name , "name" );
237218 final T logger = getLogger (name , messageFactory );
238219 return logger != null ;
@@ -265,23 +246,18 @@ public boolean hasLogger(final String name, final Class<? extends MessageFactory
265246 * @param name ignored – kept for backward compatibility
266247 * @param messageFactory ignored – kept for backward compatibility
267248 * @param logger a logger instance
268- * @deprecated As of version {@code 2.25.0}, planned to be removed!
269- * Use {@link #computeIfAbsent(String, MessageFactory, BiFunction)} instead.
270249 */
271- @ Deprecated
272- public void putIfAbsent (
273- @ Nullable final String name , @ Nullable final MessageFactory messageFactory , final T logger ) {
250+ public void putIfAbsent (final String name , final MessageFactory messageFactory , final T logger ) {
274251
275252 // Check arguments
276253 requireNonNull (logger , "logger" );
277254
278255 // Insert the logger
279256 writeLock .lock ();
280257 try {
281- final String loggerName = logger .getName ();
282258 final Map <MessageFactory , WeakReference <T >> loggerRefByMessageFactory =
283259 loggerRefByMessageFactoryByName .computeIfAbsent (
284- loggerName , this ::createLoggerRefByMessageFactoryMap );
260+ logger . getName () , this ::createLoggerRefByMessageFactoryMap );
285261 final MessageFactory loggerMessageFactory = logger .getMessageFactory ();
286262 final WeakReference <T > loggerRef = loggerRefByMessageFactory .get (loggerMessageFactory );
287263 if (loggerRef == null || loggerRef .get () == null ) {
@@ -292,60 +268,6 @@ public void putIfAbsent(
292268 }
293269 }
294270
295- public T computeIfAbsent (
296- final String name ,
297- final MessageFactory messageFactory ,
298- final BiFunction <String , MessageFactory , T > loggerSupplier ) {
299-
300- // Check arguments
301- requireNonNull (name , "name" );
302- requireNonNull (messageFactory , "messageFactory" );
303- requireNonNull (loggerSupplier , "loggerSupplier" );
304-
305- // Read lock fast path: See if logger already exists
306- T logger = getLogger (name , messageFactory );
307- if (logger != null ) {
308- return logger ;
309- }
310-
311- // Write lock slow path: Insert the logger
312- writeLock .lock ();
313- try {
314-
315- // See if the logger is created by another thread in the meantime
316- final Map <MessageFactory , WeakReference <T >> loggerRefByMessageFactory =
317- loggerRefByMessageFactoryByName .computeIfAbsent (name , this ::createLoggerRefByMessageFactoryMap );
318- final WeakReference <T > loggerRef ;
319- if ((loggerRef = loggerRefByMessageFactory .get (messageFactory )) != null
320- && (logger = loggerRef .get ()) != null ) {
321- return logger ;
322- }
323-
324- // Create the logger
325- logger = loggerSupplier .apply (name , messageFactory );
326-
327- // Report message factory mismatches, if there is any
328- final MessageFactory loggerMessageFactory = logger .getMessageFactory ();
329- if (!loggerMessageFactory .equals (messageFactory )) {
330- StatusLogger .getLogger ()
331- .error (
332- "Newly registered logger with name `{}` and message factory `{}`, is requested to be associated with a different message factory: `{}`.\n "
333- + "Effectively the message factory of the logger will be used and the other one will be ignored.\n "
334- + "This generally hints a problem at the logger context implementation.\n "
335- + "Please report this using the Log4j project issue tracker." ,
336- name ,
337- loggerMessageFactory ,
338- messageFactory );
339- }
340-
341- // Insert the logger
342- loggerRefByMessageFactory .put (loggerMessageFactory , new WeakReference <>(logger ));
343- return logger ;
344- } finally {
345- writeLock .unlock ();
346- }
347- }
348-
349271 private Map <MessageFactory , WeakReference <T >> createLoggerRefByMessageFactoryMap (final String ignored ) {
350272 return new WeakHashMap <>();
351273 }
0 commit comments