001 /*****************************************************************************
002 * Copyright (C) PicoContainer Organization. All rights reserved. *
003 * ------------------------------------------------------------------------- *
004 * The software in this package is published under the terms of the BSD *
005 * style license a copy of which has been included with this distribution in *
006 * the LICENSE.txt file. *
007 * *
008 * Original code by Paul Hammant & Obie Fernandez & Aslak *
009 *****************************************************************************/
010
011 package org.picocontainer;
012
013 import java.lang.reflect.Constructor;
014 import java.lang.reflect.Member;
015 import java.lang.reflect.Method;
016
017 /**
018 * A component monitor is responsible for monitoring the component instantiation
019 * and method invocation.
020 *
021 * @author Paul Hammant
022 * @author Obie Fernandez
023 * @author Aslak Hellesøy
024 * @author Mauro Talevi
025 */
026 public interface ComponentMonitor {
027
028 /**
029 * Event thrown as the component is being instantiated using the given constructor
030 *
031 * @param container
032 * @param componentAdapter
033 * @param constructor the Constructor used to instantiate the addComponent @return the constructor to use in instantiation (nearly always the same one as passed in)
034 */
035 Constructor instantiating(PicoContainer container, ComponentAdapter componentAdapter,
036 Constructor constructor
037 );
038
039 /**
040 * Event thrown after the component has been instantiated using the given constructor.
041 * This should be called for both Constructor and Setter DI.
042 *
043 * @param container
044 * @param componentAdapter
045 * @param constructor the Constructor used to instantiate the addComponent
046 * @param instantiated the component that was instantiated by PicoContainer
047 * @param injected the components during instantiation.
048 * @param duration the duration in millis of the instantiation
049 */
050
051 void instantiated(PicoContainer container, ComponentAdapter componentAdapter,
052 Constructor constructor,
053 Object instantiated,
054 Object[] injected,
055 long duration);
056
057 /**
058 * Event thrown if the component instantiation failed using the given constructor
059 *
060 * @param container
061 * @param componentAdapter
062 * @param constructor the Constructor used to instantiate the addComponent
063 * @param cause the Exception detailing the cause of the failure
064 */
065 void instantiationFailed(PicoContainer container,
066 ComponentAdapter componentAdapter,
067 Constructor constructor,
068 Exception cause);
069
070 /**
071 * Event thrown as the component method is being invoked on the given instance
072 *
073 * @param container
074 * @param componentAdapter
075 * @param member
076 * @param instance the component instance
077 */
078 void invoking(PicoContainer container, ComponentAdapter componentAdapter, Member member, Object instance);
079
080 /**
081 * Event thrown after the component method has been invoked on the given instance
082 *
083 * @param container
084 * @param componentAdapter
085 * @param method the Method invoked on the component instance
086 * @param instance the component instance
087 * @param duration the duration in millis of the invocation
088 */
089 void invoked(PicoContainer container,
090 ComponentAdapter componentAdapter,
091 Method method,
092 Object instance,
093 long duration);
094
095 /**
096 * Event thrown if the component method invocation failed on the given instance
097 *
098 * @param member
099 * @param instance the component instance
100 * @param cause the Exception detailing the cause of the failure
101 */
102 void invocationFailed(Member member, Object instance, Exception cause);
103
104 /**
105 * Event thrown if a lifecycle method invocation - start, stop or dispose -
106 * failed on the given instance
107 *
108 * @param container
109 * @param componentAdapter
110 * @param method the lifecycle Method invoked on the component instance
111 * @param instance the component instance
112 * @param cause the RuntimeException detailing the cause of the failure
113 */
114 void lifecycleInvocationFailed(MutablePicoContainer container,
115 ComponentAdapter componentAdapter, Method method,
116 Object instance,
117 RuntimeException cause);
118
119
120 /**
121 *
122 * @param container
123 * @param componentKey
124 */
125 Object noComponentFound(MutablePicoContainer container, Object componentKey);
126 }