org.picocontainer.gems.monitors
Class Log4JComponentMonitor

java.lang.Object
  extended by org.picocontainer.gems.monitors.Log4JComponentMonitor
All Implemented Interfaces:
Serializable, ComponentMonitor

public class Log4JComponentMonitor
extends Object
implements ComponentMonitor, Serializable

A ComponentMonitor which writes to a Log4J Logger instance. The Logger instance can either be injected or, if not set, the LogManager will be used to retrieve it at every invocation of the monitor.

Author:
Paul Hammant, Mauro Talevi
See Also:
Serialized Form

Constructor Summary
Log4JComponentMonitor()
          Creates a Log4JComponentMonitor with no Logger instance set.
Log4JComponentMonitor(Class<?> loggerClass)
          Creates a Log4JComponentMonitor with a given Logger instance class.
Log4JComponentMonitor(Class<?> loggerClass, ComponentMonitor delegate)
          Creates a Log4JComponentMonitor with a given Logger instance class.
Log4JComponentMonitor(ComponentMonitor delegate)
           
Log4JComponentMonitor(org.apache.log4j.Logger logger)
          Creates a Log4JComponentMonitor with a given Logger instance
Log4JComponentMonitor(org.apache.log4j.Logger logger, ComponentMonitor delegate)
          Creates a Log4JComponentMonitor with a given Logger instance
Log4JComponentMonitor(String loggerName)
          Creates a Log4JComponentMonitor with a given Logger instance name.
Log4JComponentMonitor(String loggerName, ComponentMonitor delegate)
          Creates a Log4JComponentMonitor with a given Logger instance name.
 
Method Summary
protected  org.apache.log4j.Logger getLogger(Member member)
           
<T> void
instantiated(PicoContainer container, ComponentAdapter<T> componentAdapter, Constructor<T> constructor, Object instantiated, Object[] parameters, long duration)
          Event thrown after the component has been instantiated using the given constructor.
<T> Constructor<T>
instantiating(PicoContainer container, ComponentAdapter<T> componentAdapter, Constructor<T> constructor)
          Event thrown as the component is being instantiated using the given constructor
<T> void
instantiationFailed(PicoContainer container, ComponentAdapter<T> componentAdapter, Constructor<T> constructor, Exception cause)
          Event thrown if the component instantiation failed using the given constructor
 void invocationFailed(Member member, Object instance, Exception cause)
          Event thrown if the component method invocation failed on the given instance
 void invoked(PicoContainer container, ComponentAdapter<?> componentAdapter, Method method, Object instance, long duration)
          Event thrown after the component method has been invoked on the given instance
 void invoking(PicoContainer container, ComponentAdapter<?> componentAdapter, Member member, Object instance)
          Event thrown as the component method is being invoked on the given instance
 void lifecycleInvocationFailed(MutablePicoContainer container, ComponentAdapter<?> componentAdapter, Method method, Object instance, RuntimeException cause)
          Event thrown if a lifecycle method invocation - start, stop or dispose - failed on the given instance
 AbstractInjector newInjectionFactory(AbstractInjector abstractInjector)
          A mechanism to monitor or override the AbstractInjectors being made for components.
 Object noComponentFound(MutablePicoContainer container, Object componentKey)
          No Component has been found for the key in question.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Log4JComponentMonitor

public Log4JComponentMonitor()
Creates a Log4JComponentMonitor with no Logger instance set. The LogManager will be used to retrieve the Logger instance at every invocation of the monitor.


Log4JComponentMonitor

public Log4JComponentMonitor(Class<?> loggerClass)
Creates a Log4JComponentMonitor with a given Logger instance class. The class name is used to retrieve the Logger instance.

Parameters:
loggerClass - the class of the Logger

Log4JComponentMonitor

public Log4JComponentMonitor(String loggerName)
Creates a Log4JComponentMonitor with a given Logger instance name. It uses the LogManager to create the Logger instance.

Parameters:
loggerName - the name of the Log

Log4JComponentMonitor

public Log4JComponentMonitor(org.apache.log4j.Logger logger)
Creates a Log4JComponentMonitor with a given Logger instance

Parameters:
logger - the Logger to write to

Log4JComponentMonitor

public Log4JComponentMonitor(Class<?> loggerClass,
                             ComponentMonitor delegate)
Creates a Log4JComponentMonitor with a given Logger instance class. The class name is used to retrieve the Logger instance.

Parameters:
loggerClass - the class of the Logger
delegate - the delegate

Log4JComponentMonitor

public Log4JComponentMonitor(String loggerName,
                             ComponentMonitor delegate)
Creates a Log4JComponentMonitor with a given Logger instance name. It uses the LogManager to create the Logger instance.

Parameters:
loggerName - the name of the Log
delegate - the delegate

Log4JComponentMonitor

public Log4JComponentMonitor(org.apache.log4j.Logger logger,
                             ComponentMonitor delegate)
Creates a Log4JComponentMonitor with a given Logger instance

Parameters:
logger - the Logger to write to
delegate - the delegate

Log4JComponentMonitor

public Log4JComponentMonitor(ComponentMonitor delegate)
Method Detail

instantiating

public <T> Constructor<T> instantiating(PicoContainer container,
                                        ComponentAdapter<T> componentAdapter,
                                        Constructor<T> constructor)
Event thrown as the component is being instantiated using the given constructor

Specified by:
instantiating in interface ComponentMonitor
constructor - the Constructor used to instantiate the addComponent @return the constructor to use in instantiation (nearly always the same one as passed in)

instantiated

public <T> void instantiated(PicoContainer container,
                             ComponentAdapter<T> componentAdapter,
                             Constructor<T> constructor,
                             Object instantiated,
                             Object[] parameters,
                             long duration)
Event thrown after the component has been instantiated using the given constructor. This should be called for both Constructor and Setter DI.

Specified by:
instantiated in interface ComponentMonitor
constructor - the Constructor used to instantiate the addComponent
instantiated - the component that was instantiated by PicoContainer
parameters - the components during instantiation.
duration - the duration in milliseconds of the instantiation

instantiationFailed

public <T> void instantiationFailed(PicoContainer container,
                                    ComponentAdapter<T> componentAdapter,
                                    Constructor<T> constructor,
                                    Exception cause)
Event thrown if the component instantiation failed using the given constructor

Specified by:
instantiationFailed in interface ComponentMonitor
constructor - the Constructor used to instantiate the addComponent
cause - the Exception detailing the cause of the failure

invoking

public void invoking(PicoContainer container,
                     ComponentAdapter<?> componentAdapter,
                     Member member,
                     Object instance)
Event thrown as the component method is being invoked on the given instance

Specified by:
invoking in interface ComponentMonitor
instance - the component instance

invoked

public void invoked(PicoContainer container,
                    ComponentAdapter<?> componentAdapter,
                    Method method,
                    Object instance,
                    long duration)
Event thrown after the component method has been invoked on the given instance

Specified by:
invoked in interface ComponentMonitor
method - the Method invoked on the component instance
instance - the component instance
duration - the duration in millis of the invocation

invocationFailed

public void invocationFailed(Member member,
                             Object instance,
                             Exception cause)
Event thrown if the component method invocation failed on the given instance

Specified by:
invocationFailed in interface ComponentMonitor
instance - the component instance
cause - the Exception detailing the cause of the failure

lifecycleInvocationFailed

public void lifecycleInvocationFailed(MutablePicoContainer container,
                                      ComponentAdapter<?> componentAdapter,
                                      Method method,
                                      Object instance,
                                      RuntimeException cause)
Event thrown if a lifecycle method invocation - start, stop or dispose - failed on the given instance

Specified by:
lifecycleInvocationFailed in interface ComponentMonitor
method - the lifecycle Method invoked on the component instance
instance - the component instance
cause - the RuntimeException detailing the cause of the failure

noComponentFound

public Object noComponentFound(MutablePicoContainer container,
                               Object componentKey)
No Component has been found for the key in question. Implementors of this have a last ditch opportunity to specify something for the need.

Specified by:
noComponentFound in interface ComponentMonitor

newInjectionFactory

public AbstractInjector newInjectionFactory(AbstractInjector abstractInjector)
A mechanism to monitor or override the AbstractInjectors being made for components.

Specified by:
newInjectionFactory in interface ComponentMonitor
Parameters:
abstractInjector - the abstract injector the container intends to use for the component currently being added.
Returns:
an abstract Injector. For most implementations, the same one as was passed in.

getLogger

protected org.apache.log4j.Logger getLogger(Member member)


Copyright © 2003-2010 Codehaus. All Rights Reserved.