JBoss LogManager 1.1.0.CR6

org.jboss.logmanager
Class ClassLoaderLogContextSelector

java.lang.Object
  extended by org.jboss.logmanager.ClassLoaderLogContextSelector
All Implemented Interfaces:
LogContextSelector

public final class ClassLoaderLogContextSelector
extends Object
implements LogContextSelector

A log context selector which chooses a log context based on the caller's classloader. This selector maintains weak references to the classloader as well as the log context; if either is collected, the association is broken. Therefore, strong references must be kept external to this class.


Constructor Summary
ClassLoaderLogContextSelector()
          Construct a new instance.
ClassLoaderLogContextSelector(LogContextSelector defaultSelector)
          Construct a new instance.
 
Method Summary
 LogContext getLogContext()
          Get the current log context.
 void registerLogContext(ClassLoader classLoader, LogContext logContext)
          Register a class loader with a log context.
 boolean unregisterLogContext(ClassLoader classLoader, LogContext logContext)
          Unregister a class loader/log context association.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClassLoaderLogContextSelector

public ClassLoaderLogContextSelector(LogContextSelector defaultSelector)
Construct a new instance. If no matching log context is found, the provided default selector is consulted.

Parameters:
defaultSelector - the selector to consult if no matching log context is found

ClassLoaderLogContextSelector

public ClassLoaderLogContextSelector()
Construct a new instance. If no matching log context is found, the system context is used.

Method Detail

getLogContext

public LogContext getLogContext()
Get the current log context. This instance will consult the call stack to see if any calling classloader is associated with any log context.

Specified by:
getLogContext in interface LogContextSelector
Returns:
the current log context

registerLogContext

public void registerLogContext(ClassLoader classLoader,
                               LogContext logContext)
                        throws IllegalArgumentException
Register a class loader with a log context. This method requires the registerLogContext RuntimePermission.

Parameters:
classLoader - the classloader
logContext - the log context
Throws:
IllegalArgumentException - if the classloader is already associated with a log context

unregisterLogContext

public boolean unregisterLogContext(ClassLoader classLoader,
                                    LogContext logContext)
Unregister a class loader/log context association. This method requires the unregisterLogContext RuntimePermission.

Parameters:
classLoader - the classloader
logContext - the log context
Returns:
true if the association exists and was removed, false otherwise

JBoss LogManager 1.1.0.CR6

Copyright © 2009 JBoss, a division of Red Hat, Inc.