Modified: turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/interceptor/logging/LoggingInterceptorServiceImpl.java URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/interceptor/logging/LoggingInterceptorServiceImpl.java?rev=1848876&r1=1848875&r2=1848876&view=diff ============================================================================== --- turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/interceptor/logging/LoggingInterceptorServiceImpl.java (original) +++ turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/interceptor/logging/LoggingInterceptorServiceImpl.java Thu Dec 13 18:17:39 2018 @@ -35,358 +35,306 @@ import org.apache.fulcrum.yaafi.intercep import org.apache.fulcrum.yaafi.interceptor.util.StopWatch; /** - * A service logging of service invocations. The service allows to monitor - * a list of services defined in the configuration. + * A service logging of service invocations. The service allows to monitor a + * list of services defined in the configuration. * * @author <a href="mailto:[email protected]">Siegfried Goeschl</a> */ -public class LoggingInterceptorServiceImpl - extends BaseInterceptorServiceImpl - implements LoggingInterceptorService, Reconfigurable, Initializable -{ - /** the maximum length of a dumped argument */ - private static final int MAX_ARG_LENGTH = 2000; - - /** seperator for the arguments in the logfile */ - private static final String SEPERATOR = ";"; - - /** maximum argument length for dumping arguments */ - private int maxArgLength; - - /** the class name of the string builder to use */ - private String toStringBuilderClassName; - - /** monitor all excpetions independent from the monitored services */ - private boolean monitorAllExceptions; - - /** the ReflectionToStringBuilder class */ - private Class<?> toStringBuilderClass; - - ///////////////////////////////////////////////////////////////////////// - // Avalon Service Lifecycle Implementation - ///////////////////////////////////////////////////////////////////////// - - /** - * Constructor - */ - public LoggingInterceptorServiceImpl() - { - super(); - this.maxArgLength = MAX_ARG_LENGTH; - } - - /** - * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration) - */ - public void configure(Configuration configuration) throws ConfigurationException - { - super.configure(configuration); - - this.maxArgLength = configuration.getChild("maxArgLength").getValueAsInteger(MAX_ARG_LENGTH); - this.toStringBuilderClassName = configuration.getChild("toStringBuilderClass").getValue(ArgumentToStringBuilderImpl.class.getName()); - this.monitorAllExceptions = configuration.getChild("monitorAllExceptions").getValueAsBoolean(true); - } - - /** - * @see org.apache.avalon.framework.activity.Initializable#initialize() - */ - public void initialize() throws Exception - { - // load the string builder class - - ClassLoader classLoader = this.getClass().getClassLoader(); - - if( Clazz.hasClazz(classLoader, this.getToStringBuilderClassName()) ) - { - this.toStringBuilderClass = Clazz.getClazz( - classLoader, - this.getToStringBuilderClassName() - ); - } - - // create an instance of the StringBuilder to see if everything works - - InterceptorToStringBuilder interceptorToStringBuilder = this.createArgumentToStringBuilder( - this - ); - - interceptorToStringBuilder.toString(); - } - - /** - * @see org.apache.avalon.framework.configuration.Reconfigurable#reconfigure(org.apache.avalon.framework.configuration.Configuration) - */ - public void reconfigure(Configuration configuration) throws ConfigurationException - { - super.reconfigure(configuration); - this.configure(configuration); - } - - ///////////////////////////////////////////////////////////////////////// - // Service interface implementation - ///////////////////////////////////////////////////////////////////////// - - /** - * @see org.apache.fulcrum.yaafi.framework.interceptor.AvalonInterceptorService#onEntry(org.apache.fulcrum.yaafi.framework.interceptor.AvalonInterceptorContext) - */ - public void onEntry(AvalonInterceptorContext interceptorContext) - { - if( this.isServiceMonitored(interceptorContext ) ) - { - if( this.getLogger().isInfoEnabled() ) - { - String msg = this.toString(interceptorContext,null,ON_ENTRY); - this.getLogger().info(msg); - this.createStopWatch(interceptorContext); - } - } - } - - /** - * @see org.apache.fulcrum.yaafi.framework.interceptor.AvalonInterceptorService#onError(org.apache.fulcrum.yaafi.framework.interceptor.AvalonInterceptorContext, java.lang.Throwable) - */ - public void onError(AvalonInterceptorContext interceptorContext,Throwable t) - { - if( this.getLogger().isErrorEnabled() ) - { - if( this.isMonitorAllExceptions() || this.isServiceMonitored(interceptorContext) ) - { - StopWatch stopWatch = this.getStopWatch(interceptorContext); - stopWatch.stop(); - String msg = this.toString(interceptorContext, stopWatch, t); - this.getLogger().error(msg); - } - } - } - - /** - * @see org.apache.fulcrum.yaafi.framework.interceptor.AvalonInterceptorService#onExit(org.apache.fulcrum.yaafi.framework.interceptor.AvalonInterceptorContext, java.lang.Object) - */ - public void onExit(AvalonInterceptorContext interceptorContext, Object result) - { - if( this.isServiceMonitored(interceptorContext) ) - { - if( this.getLogger().isDebugEnabled() ) - { - StopWatch stopWatch = this.getStopWatch(interceptorContext); - stopWatch.stop(); - String msg = this.toString(interceptorContext, stopWatch, result); - this.getLogger().debug(msg); - } - } - } - - ///////////////////////////////////////////////////////////////////////// - // Service Implementation - ///////////////////////////////////////////////////////////////////////// - - /** - * Creates a stop watch - * - * @param interceptorContext the current interceptor context - */ - protected void createStopWatch( - AvalonInterceptorContext interceptorContext ) - { - StopWatch stopWatch = new StopWatch(); - stopWatch.start(); - interceptorContext.getRequestContext().put(this.getServiceName(),stopWatch); - } - - /** - * Gets the stop watch. Even if none is defined we return one - * in a proper state. - * - * @param interceptorContext the current interceptor context - * @return the stop watch - */ - protected StopWatch getStopWatch( - AvalonInterceptorContext interceptorContext ) - { - StopWatch result = (StopWatch) interceptorContext.getRequestContext().remove( - this.getServiceName() - ); - - if( result == null ) - { - result = new StopWatch(); - result.start(); - } - - return result; - } - - /** - * @return Returns the maxLineLength. - */ - protected int getMaxArgLength() - { - return maxArgLength; - } - - /** - * @return Returns the monitorAllExceptions. - */ - protected boolean isMonitorAllExceptions() - { - return monitorAllExceptions; - } - - /** - * @return Returns the toStringBuilderClass. - */ - protected Class<?> getToStringBuilderClass() - { - return toStringBuilderClass; - } - - /** - * @return Returns the toStringBuilderClassName. - */ - protected String getToStringBuilderClassName() - { - return toStringBuilderClassName; - } - - /** - * Create an instance of an InterceptorToStringBuilder - * - * @param target the object to stringify - * @return the string builder - */ - protected InterceptorToStringBuilder createArgumentToStringBuilder(Object target) - { - InterceptorToStringBuilder result = null; - - try - { - result = (InterceptorToStringBuilder) - this.getToStringBuilderClass().newInstance(); - } - catch (Exception e) - { - String msg = "Unable to create an instance for " + this.getToStringBuilderClassName(); - this.getLogger().error(msg,e); - result = new DefaultToStringBuilderImpl(); - } - - result.setTarget(target); - result.setMaxArgLength(this.getMaxArgLength()); - result.setMode(1); - - return result; - } - - /** - * Create a string representation of a service invocation returning a result. - * - * @param avalonInterceptorContext the interceptor context - * @param stopWatch the stopwatch for the execution time - * @param result the result of the service invocation - * @return the string representation of the result - */ - protected String toString( - AvalonInterceptorContext avalonInterceptorContext, - StopWatch stopWatch, - Object result ) - { - StringBuilder methodSignature = new StringBuilder(); - InterceptorToStringBuilder toStringBuilder = this.createArgumentToStringBuilder(result); - - methodSignature.append( this.toString(avalonInterceptorContext, stopWatch, ON_EXIT) ); - methodSignature.append(SEPERATOR); - methodSignature.append( "result={" ); - methodSignature.append( toStringBuilder.toString() ); - methodSignature.append( "}" ); - - return methodSignature.toString(); - } - - /** - * Create a string representation of a service invocation throwing a Throwable - * - * @param avalonInterceptorContext the interceptor context - * @param stopWatch the stopwatch for the execution time - * @param throwable the result of the service invocation - * @return the string representation of the result - */ - protected String toString( - AvalonInterceptorContext avalonInterceptorContext, - StopWatch stopWatch, - Throwable throwable ) - { - StringBuilder methodSignature = new StringBuilder(); - InterceptorToStringBuilder toStringBuilder = this.createArgumentToStringBuilder(throwable); - - methodSignature.append( this.toString(avalonInterceptorContext, stopWatch, ON_ERROR) ); - methodSignature.append(SEPERATOR); - methodSignature.append( throwable.getClass().getName() ); - methodSignature.append(SEPERATOR); - methodSignature.append( toStringBuilder.toString() ); - - return methodSignature.toString(); - } - - /** - * Create a method signature. - * - * @param interceptorContext the avalonInterceptorContext - * @param stopWatch the stopwatch for the execution time - * @param mode the mode (onEntry, onExit, onError) - * @return the debug output - */ - protected String toString( - AvalonInterceptorContext interceptorContext, StopWatch stopWatch, int mode ) - { - StringBuilder result = new StringBuilder(); - Method method = interceptorContext.getMethod(); - Object[] args = interceptorContext.getArgs(); - InterceptorToStringBuilder toStringBuilder = null; - MethodToStringBuilderImpl methodToStringBuilder = new MethodToStringBuilderImpl(method); - - if( args == null ) - { - args = new Object[0]; - } - - result.append(interceptorContext.getTransactionId()); - result.append(SEPERATOR); - result.append(interceptorContext.getInvocationId()); - result.append(SEPERATOR); - result.append(interceptorContext.getInvocationDepth()); - result.append(SEPERATOR); - result.append(mode); - result.append(SEPERATOR); - result.append(interceptorContext.getServiceShorthand()); - result.append(SEPERATOR); - result.append(method.getName()); - result.append(SEPERATOR); - - if( stopWatch != null ) - { - result.append(stopWatch.getTime()); - } - else - { - result.append('0'); - } - - result.append(SEPERATOR); - result.append(methodToStringBuilder.toString()); - - if( (ON_ENTRY == mode) || (ON_ERROR == mode) ) - { - for( int i=0; i<args.length; i++ ) - { - toStringBuilder = this.createArgumentToStringBuilder(args[i]); - result.append(SEPERATOR); - result.append("arg[" + i + "]:={"); - result.append( toStringBuilder.toString()); - result.append("}"); - } - } +public class LoggingInterceptorServiceImpl extends BaseInterceptorServiceImpl + implements LoggingInterceptorService, Reconfigurable, Initializable { + /** the maximum length of a dumped argument */ + private static final int MAX_ARG_LENGTH = 2000; + + /** seperator for the arguments in the logfile */ + private static final String SEPERATOR = ";"; + + /** maximum argument length for dumping arguments */ + private int maxArgLength; + + /** the class name of the string builder to use */ + private String toStringBuilderClassName; + + /** monitor all excpetions independent from the monitored services */ + private boolean monitorAllExceptions; + + /** the ReflectionToStringBuilder class */ + private Class<?> toStringBuilderClass; + + ///////////////////////////////////////////////////////////////////////// + // Avalon Service Lifecycle Implementation + ///////////////////////////////////////////////////////////////////////// + + /** + * Constructor + */ + public LoggingInterceptorServiceImpl() { + super(); + this.maxArgLength = MAX_ARG_LENGTH; + } + + /** + * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration) + */ + public void configure(Configuration configuration) throws ConfigurationException { + super.configure(configuration); + + this.maxArgLength = configuration.getChild("maxArgLength").getValueAsInteger(MAX_ARG_LENGTH); + this.toStringBuilderClassName = configuration.getChild("toStringBuilderClass") + .getValue(ArgumentToStringBuilderImpl.class.getName()); + this.monitorAllExceptions = configuration.getChild("monitorAllExceptions").getValueAsBoolean(true); + } + + /** + * @see org.apache.avalon.framework.activity.Initializable#initialize() + */ + public void initialize() throws Exception { + // load the string builder class + + ClassLoader classLoader = this.getClass().getClassLoader(); + + if (Clazz.hasClazz(classLoader, this.getToStringBuilderClassName())) { + this.toStringBuilderClass = Clazz.getClazz(classLoader, this.getToStringBuilderClassName()); + } + + // create an instance of the StringBuilder to see if everything works + + InterceptorToStringBuilder interceptorToStringBuilder = this.createArgumentToStringBuilder(this); + + interceptorToStringBuilder.toString(); + } + + /** + * @see org.apache.avalon.framework.configuration.Reconfigurable#reconfigure(org.apache.avalon.framework.configuration.Configuration) + */ + public void reconfigure(Configuration configuration) throws ConfigurationException { + super.reconfigure(configuration); + this.configure(configuration); + } + + ///////////////////////////////////////////////////////////////////////// + // Service interface implementation + ///////////////////////////////////////////////////////////////////////// + + /* + * (non-Javadoc) + * + * @see + * org.apache.fulcrum.yaafi.interceptor.baseservice.BaseInterceptorServiceImpl# + * onEntry(org.apache.fulcrum.yaafi.framework.interceptor. + * AvalonInterceptorContext) + */ + public void onEntry(AvalonInterceptorContext interceptorContext) { + if (this.isServiceMonitored(interceptorContext) && this.getLogger().isInfoEnabled() == true) { + String msg = this.toString(interceptorContext, null, ON_ENTRY); + this.getLogger().info(msg); + this.createStopWatch(interceptorContext); + } + } + + /* (non-Javadoc) + * @see org.apache.fulcrum.yaafi.interceptor.baseservice.BaseInterceptorServiceImpl#onError(org.apache.fulcrum.yaafi.framework.interceptor.AvalonInterceptorContext, java.lang.Throwable) + */ + public void onError(AvalonInterceptorContext interceptorContext, Throwable t) { + if (this.getLogger().isErrorEnabled() + && (this.isMonitorAllExceptions() || this.isServiceMonitored(interceptorContext))) { + StopWatch stopWatch = this.getStopWatch(interceptorContext); + stopWatch.stop(); + String msg = this.toString(interceptorContext, stopWatch, t); + this.getLogger().error(msg); + } + } + + /* (non-Javadoc) + * @see org.apache.fulcrum.yaafi.interceptor.baseservice.BaseInterceptorServiceImpl#onExit(org.apache.fulcrum.yaafi.framework.interceptor.AvalonInterceptorContext, java.lang.Object) + */ + public void onExit(AvalonInterceptorContext interceptorContext, Object result) { + if (this.isServiceMonitored(interceptorContext) && this.getLogger().isDebugEnabled() == true) { + StopWatch stopWatch = this.getStopWatch(interceptorContext); + stopWatch.stop(); + String msg = this.toString(interceptorContext, stopWatch, result); + this.getLogger().debug(msg); + } + } + + ///////////////////////////////////////////////////////////////////////// + // Service Implementation + ///////////////////////////////////////////////////////////////////////// + + /** + * Creates a stop watch + * + * @param interceptorContext the current interceptor context + */ + protected void createStopWatch(AvalonInterceptorContext interceptorContext) { + StopWatch stopWatch = new StopWatch(); + stopWatch.start(); + interceptorContext.getRequestContext().put(this.getServiceName(), stopWatch); + } + + /** + * Gets the stop watch. Even if none is defined we return one in a proper state. + * + * @param interceptorContext the current interceptor context + * @return the stop watch + */ + protected StopWatch getStopWatch(AvalonInterceptorContext interceptorContext) { + StopWatch result = (StopWatch) interceptorContext.getRequestContext().remove(this.getServiceName()); + + if (result == null) { + result = new StopWatch(); + result.start(); + } + + return result; + } + + /** + * @return Returns the maxLineLength. + */ + protected int getMaxArgLength() { + return maxArgLength; + } + + /** + * @return Returns the monitorAllExceptions. + */ + protected boolean isMonitorAllExceptions() { + return monitorAllExceptions; + } + + /** + * @return Returns the toStringBuilderClass. + */ + protected Class<?> getToStringBuilderClass() { + return toStringBuilderClass; + } + + /** + * @return Returns the toStringBuilderClassName. + */ + protected String getToStringBuilderClassName() { + return toStringBuilderClassName; + } + + /** + * Create an instance of an InterceptorToStringBuilder + * + * @param target the object to stringify + * @return the string builder + */ + protected InterceptorToStringBuilder createArgumentToStringBuilder(Object target) { + InterceptorToStringBuilder result = null; + + try { + result = (InterceptorToStringBuilder) this.getToStringBuilderClass().newInstance(); + } catch (Exception e) { + String msg = "Unable to create an instance for " + this.getToStringBuilderClassName(); + this.getLogger().error(msg, e); + result = new DefaultToStringBuilderImpl(); + } + + result.setTarget(target); + result.setMaxArgLength(this.getMaxArgLength()); + result.setMode(1); + + return result; + } + + /** + * Create a string representation of a service invocation returning a result. + * + * @param avalonInterceptorContext the interceptor context + * @param stopWatch the stopwatch for the execution time + * @param result the result of the service invocation + * @return the string representation of the result + */ + protected String toString(AvalonInterceptorContext avalonInterceptorContext, StopWatch stopWatch, Object result) { + StringBuilder methodSignature = new StringBuilder(); + InterceptorToStringBuilder toStringBuilder = this.createArgumentToStringBuilder(result); + + methodSignature.append(this.toString(avalonInterceptorContext, stopWatch, ON_EXIT)); + methodSignature.append(SEPERATOR); + methodSignature.append("result={"); + methodSignature.append(toStringBuilder.toString()); + methodSignature.append("}"); + + return methodSignature.toString(); + } + + /** + * Create a string representation of a service invocation throwing a Throwable + * + * @param avalonInterceptorContext the interceptor context + * @param stopWatch the stopwatch for the execution time + * @param throwable the result of the service invocation + * @return the string representation of the result + */ + protected String toString(AvalonInterceptorContext avalonInterceptorContext, StopWatch stopWatch, + Throwable throwable) { + StringBuilder methodSignature = new StringBuilder(); + InterceptorToStringBuilder toStringBuilder = this.createArgumentToStringBuilder(throwable); + + methodSignature.append(this.toString(avalonInterceptorContext, stopWatch, ON_ERROR)); + methodSignature.append(SEPERATOR); + methodSignature.append(throwable.getClass().getName()); + methodSignature.append(SEPERATOR); + methodSignature.append(toStringBuilder.toString()); + + return methodSignature.toString(); + } + + /** + * Create a method signature. + * + * @param interceptorContext the avalonInterceptorContext + * @param stopWatch the stopwatch for the execution time + * @param mode the mode (onEntry, onExit, onError) + * @return the debug output + */ + protected String toString(AvalonInterceptorContext interceptorContext, StopWatch stopWatch, int mode) { + StringBuilder result = new StringBuilder(); + Method method = interceptorContext.getMethod(); + Object[] args = interceptorContext.getArgs(); + InterceptorToStringBuilder toStringBuilder = null; + MethodToStringBuilderImpl methodToStringBuilder = new MethodToStringBuilderImpl(method); + + if (args == null) { + args = new Object[0]; + } + + result.append(interceptorContext.getTransactionId()); + result.append(SEPERATOR); + result.append(interceptorContext.getInvocationId()); + result.append(SEPERATOR); + result.append(interceptorContext.getInvocationDepth()); + result.append(SEPERATOR); + result.append(mode); + result.append(SEPERATOR); + result.append(interceptorContext.getServiceShorthand()); + result.append(SEPERATOR); + result.append(method.getName()); + result.append(SEPERATOR); + + if (stopWatch != null) { + result.append(stopWatch.getTime()); + } else { + result.append('0'); + } + + result.append(SEPERATOR); + result.append(methodToStringBuilder.toString()); + + if (ON_ENTRY == mode || ON_ERROR == mode) { + for (int i = 0; i < args.length; i++) { + toStringBuilder = this.createArgumentToStringBuilder(args[i]); + result.append(SEPERATOR); + result.append("arg[" + i + "]:={"); + result.append(toStringBuilder.toString()); + result.append("}"); + } + } - return result.toString(); - } + return result.toString(); + } }
Modified: turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/interceptor/performance/PerformanceInterceptorServiceImpl.java URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/interceptor/performance/PerformanceInterceptorServiceImpl.java?rev=1848876&r1=1848875&r2=1848876&view=diff ============================================================================== --- turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/interceptor/performance/PerformanceInterceptorServiceImpl.java (original) +++ turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/interceptor/performance/PerformanceInterceptorServiceImpl.java Thu Dec 13 18:17:39 2018 @@ -38,266 +38,231 @@ import org.apache.fulcrum.yaafi.intercep * @author <a href="mailto:[email protected]">Siegfried Goeschl</a> */ -public class PerformanceInterceptorServiceImpl - extends BaseInterceptorServiceImpl - implements PerformanceInterceptorService, Reconfigurable, Contextualizable, ThreadSafe -{ - /** the maximum length of a dumped argument */ - private static final int MAX_ARG_LENGTH = 100; - - /** default length of the StringBuilder */ - private static final int BUFFER_LENGTH = 2000; - - /** seperator for the arguments in the logfile */ - private static final String SEPERATOR = ";"; - - /** the tresholds in milliseconds to determine the loglevel */ - private int[] tresholdList; - - /** maximum argument length for dumping arguments */ - private int maxArgLength; - - ///////////////////////////////////////////////////////////////////////// - // Avalon Service Lifecycle Implementation - ///////////////////////////////////////////////////////////////////////// - - /** - * Constructor - */ - public PerformanceInterceptorServiceImpl() - { - super(); - this.tresholdList = new int[5]; - } - - /** - * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration) - */ - public void configure(Configuration configuration) throws ConfigurationException - { - super.configure(configuration); - - this.maxArgLength = configuration.getChild("maxArgLength").getValueAsInteger(MAX_ARG_LENGTH); - Configuration tresholdConfiguration = configuration.getChild("tresholds"); - this.tresholdList[0] = tresholdConfiguration.getChild("fatal").getAttributeAsInteger("millis", 5000); - this.tresholdList[1] = tresholdConfiguration.getChild("error").getAttributeAsInteger("millis", 1000); - this.tresholdList[2] = tresholdConfiguration.getChild("warn").getAttributeAsInteger("millis", 500); - this.tresholdList[3] = tresholdConfiguration.getChild("info").getAttributeAsInteger("millis", 100); - this.tresholdList[4] = tresholdConfiguration.getChild("debug").getAttributeAsInteger("millis", 10); - } - - /** - * @see org.apache.avalon.framework.configuration.Reconfigurable#reconfigure(org.apache.avalon.framework.configuration.Configuration) - */ - public void reconfigure(Configuration configuration) throws ConfigurationException - { - super.reconfigure(configuration); - this.configure(configuration); - } - - ///////////////////////////////////////////////////////////////////////// - // Service interface implementation - ///////////////////////////////////////////////////////////////////////// - - /** - * @see org.apache.fulcrum.yaafi.framework.interceptor.AvalonInterceptorService#onEntry(org.apache.fulcrum.yaafi.framework.interceptor.AvalonInterceptorContext) - */ - public void onEntry(AvalonInterceptorContext interceptorContext) - { - if( this.isServiceMonitored(interceptorContext ) ) - { - this.createStopWatch(interceptorContext); - } - } - - /** - * @see org.apache.fulcrum.yaafi.framework.interceptor.AvalonInterceptorService#onError(org.apache.fulcrum.yaafi.framework.interceptor.AvalonInterceptorContext, java.lang.Throwable) - */ - public void onError(AvalonInterceptorContext interceptorContext,Throwable t) - { - if( this.isServiceMonitored(interceptorContext) ) - { - StopWatch stopWatch = this.getStopWatch(interceptorContext); - stopWatch.stop(); - this.log( ON_ERROR, interceptorContext, stopWatch ); - } - } - - /** - * @see org.apache.fulcrum.yaafi.framework.interceptor.AvalonInterceptorService#onExit(org.apache.fulcrum.yaafi.framework.interceptor.AvalonInterceptorContext, java.lang.Object) - */ - public void onExit(AvalonInterceptorContext interceptorContext, Object result) - { - if( this.isServiceMonitored(interceptorContext) ) - { - if( this.isServiceMonitored(interceptorContext) ) - { - StopWatch stopWatch = this.getStopWatch(interceptorContext); - stopWatch.stop(); - this.log( ON_EXIT, interceptorContext, stopWatch ); - } - } - } - - ///////////////////////////////////////////////////////////////////////// - // Service Implementation - ///////////////////////////////////////////////////////////////////////// - - /** - * Creates a stop watch - * - * @param interceptorContext the current interceptor context - */ - protected void createStopWatch( - AvalonInterceptorContext interceptorContext ) - { - StopWatch stopWatch = new StopWatch(); - stopWatch.start(); - interceptorContext.getRequestContext().put(this.getServiceName(),stopWatch); - } - - /** - * Gets the stop watch - * - * @param interceptorContext the current interceptor context - * @return the stop watch - */ - protected StopWatch getStopWatch( - AvalonInterceptorContext interceptorContext ) - { - return (StopWatch) interceptorContext.getRequestContext().remove( - this.getServiceName() - ); - } - - /** - * Logs the execution time. - * - * @param mode the invocation mode (onEntry, onExit, onError) - * @param interceptorContext the current interceptor context - * @param stopWatch the stop watch - */ - protected void log( - int mode, - AvalonInterceptorContext interceptorContext, - StopWatch stopWatch - ) - { - String msg = null; - long time = stopWatch.getTime(); - - if( time >= tresholdList[0] ) - { - if( this.getLogger().isFatalErrorEnabled() ) - { - msg = this.toString(interceptorContext,stopWatch,mode); - this.getLogger().fatalError(msg); - } - } - else if( time >= tresholdList[1] ) - { - if( this.getLogger().isErrorEnabled() ) - { - msg = this.toString(interceptorContext,stopWatch,mode); - this.getLogger().error(msg); - } - } - else if( time >= tresholdList[2] ) - { - if( this.getLogger().isWarnEnabled() ) - { - msg = this.toString(interceptorContext,stopWatch,mode); - this.getLogger().warn(msg); - } - } - else if( time >= tresholdList[3] ) - { - if( this.getLogger().isInfoEnabled() ) - { - msg = this.toString(interceptorContext,stopWatch,mode); - this.getLogger().info(msg); - } - } - else if( time >= tresholdList[4] ) - { - if( this.getLogger().isDebugEnabled() ) - { - msg = this.toString(interceptorContext,stopWatch,mode); - this.getLogger().debug(msg); - } - } - } - - /** - * Create the log message for the performance logfile. - * - * @param interceptorContext the context - * @param stopWatch the stopwatch - * @param mode the mode (onEntry, onExit, onError) - * @return the log message - */ - protected String toString( - AvalonInterceptorContext interceptorContext, - StopWatch stopWatch, - int mode - ) - { - Method method = interceptorContext.getMethod(); - Object[] args = interceptorContext.getArgs(); - MethodToStringBuilderImpl methodToStringBuilder = new MethodToStringBuilderImpl(method); - StringBuilder result = new StringBuilder(BUFFER_LENGTH); - - result.append(interceptorContext.getTransactionId()); - result.append(SEPERATOR); - result.append(interceptorContext.getInvocationId()); - result.append(SEPERATOR); - result.append(interceptorContext.getInvocationDepth()); - result.append(SEPERATOR); - result.append(mode); - result.append(SEPERATOR); - result.append(interceptorContext.getServiceShorthand()); - result.append(SEPERATOR); - result.append(method.getName()); - result.append(SEPERATOR); - result.append(stopWatch.getTime()); - result.append(SEPERATOR); - result.append(methodToStringBuilder.toString()); - result.append(SEPERATOR); - result.append(this.toString(args)); - - return result.toString(); - } - - /** - * Prints the argument list. - * - * @param args array of arguments - * @return the debug output - */ - protected String toString( Object[] args ) - { - StringBuilder result = new StringBuilder(); - ArgumentToStringBuilderImpl toStringBuilder = null; - - if( args == null ) - { - args = new Object[0]; - } - - for( int i=0; i<args.length; i++ ) - { - toStringBuilder = new ArgumentToStringBuilderImpl(args[i],this.maxArgLength,1); - result.append("arg[" + i + "]:={"); - result.append( toStringBuilder.toString()); - result.append("}"); - - if( i<args.length-1) - { - result.append(SEPERATOR); - } - } +public class PerformanceInterceptorServiceImpl extends BaseInterceptorServiceImpl + implements PerformanceInterceptorService, Reconfigurable, Contextualizable, ThreadSafe { + /** the maximum length of a dumped argument */ + private static final int MAX_ARG_LENGTH = 100; + + /** default length of the StringBuilder */ + private static final int BUFFER_LENGTH = 2000; + + /** seperator for the arguments in the logfile */ + private static final String SEPERATOR = ";"; + + /** the tresholds in milliseconds to determine the loglevel */ + private int[] tresholdList; + + /** maximum argument length for dumping arguments */ + private int maxArgLength; + + ///////////////////////////////////////////////////////////////////////// + // Avalon Service Lifecycle Implementation + ///////////////////////////////////////////////////////////////////////// + + /** + * Constructor + */ + public PerformanceInterceptorServiceImpl() { + super(); + this.tresholdList = new int[5]; + } + + /** + * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration) + */ + public void configure(Configuration configuration) throws ConfigurationException { + super.configure(configuration); + + this.maxArgLength = configuration.getChild("maxArgLength").getValueAsInteger(MAX_ARG_LENGTH); + Configuration tresholdConfiguration = configuration.getChild("tresholds"); + this.tresholdList[0] = tresholdConfiguration.getChild("fatal").getAttributeAsInteger("millis", 5000); + this.tresholdList[1] = tresholdConfiguration.getChild("error").getAttributeAsInteger("millis", 1000); + this.tresholdList[2] = tresholdConfiguration.getChild("warn").getAttributeAsInteger("millis", 500); + this.tresholdList[3] = tresholdConfiguration.getChild("info").getAttributeAsInteger("millis", 100); + this.tresholdList[4] = tresholdConfiguration.getChild("debug").getAttributeAsInteger("millis", 10); + } + + /** + * @see org.apache.avalon.framework.configuration.Reconfigurable#reconfigure(org.apache.avalon.framework.configuration.Configuration) + */ + public void reconfigure(Configuration configuration) throws ConfigurationException { + super.reconfigure(configuration); + this.configure(configuration); + } + + ///////////////////////////////////////////////////////////////////////// + // Service interface implementation + ///////////////////////////////////////////////////////////////////////// + + /* + * (non-Javadoc) + * + * @see + * org.apache.fulcrum.yaafi.interceptor.baseservice.BaseInterceptorServiceImpl# + * onEntry(org.apache.fulcrum.yaafi.framework.interceptor. + * AvalonInterceptorContext) + */ + public void onEntry(AvalonInterceptorContext interceptorContext) { + if (this.isServiceMonitored(interceptorContext)) { + this.createStopWatch(interceptorContext); + } + } + + /* + * (non-Javadoc) + * + * @see + * org.apache.fulcrum.yaafi.interceptor.baseservice.BaseInterceptorServiceImpl# + * onError(org.apache.fulcrum.yaafi.framework.interceptor. + * AvalonInterceptorContext, java.lang.Throwable) + */ + public void onError(AvalonInterceptorContext interceptorContext, Throwable t) { + if (this.isServiceMonitored(interceptorContext)) { + StopWatch stopWatch = this.getStopWatch(interceptorContext); + stopWatch.stop(); + this.log(ON_ERROR, interceptorContext, stopWatch); + } + } + + /* + * (non-Javadoc) + * + * @see + * org.apache.fulcrum.yaafi.interceptor.baseservice.BaseInterceptorServiceImpl# + * onExit(org.apache.fulcrum.yaafi.framework.interceptor. + * AvalonInterceptorContext, java.lang.Object) + */ + public void onExit(AvalonInterceptorContext interceptorContext, Object result) { + if (this.isServiceMonitored(interceptorContext)) { + StopWatch stopWatch = this.getStopWatch(interceptorContext); + stopWatch.stop(); + this.log(ON_EXIT, interceptorContext, stopWatch); + } + } + + ///////////////////////////////////////////////////////////////////////// + // Service Implementation + ///////////////////////////////////////////////////////////////////////// + + /** + * Creates a stop watch + * + * @param interceptorContext the current interceptor context + */ + protected void createStopWatch(AvalonInterceptorContext interceptorContext) { + StopWatch stopWatch = new StopWatch(); + stopWatch.start(); + interceptorContext.getRequestContext().put(this.getServiceName(), stopWatch); + } + + /** + * Gets the stop watch + * + * @param interceptorContext the current interceptor context + * @return the stop watch + */ + protected StopWatch getStopWatch(AvalonInterceptorContext interceptorContext) { + return (StopWatch) interceptorContext.getRequestContext().remove(this.getServiceName()); + } + + /** + * Logs the execution time. + * + * @param mode the invocation mode (onEntry, onExit, onError) + * @param interceptorContext the current interceptor context + * @param stopWatch the stop watch + */ + protected void log(int mode, AvalonInterceptorContext interceptorContext, StopWatch stopWatch) { + String msg = null; + long time = stopWatch.getTime(); + + if (time >= tresholdList[0]) { + if (this.getLogger().isFatalErrorEnabled()) { + msg = this.toString(interceptorContext, stopWatch, mode); + this.getLogger().fatalError(msg); + } + } else if (time >= tresholdList[1]) { + if (this.getLogger().isErrorEnabled()) { + msg = this.toString(interceptorContext, stopWatch, mode); + this.getLogger().error(msg); + } + } else if (time >= tresholdList[2]) { + if (this.getLogger().isWarnEnabled()) { + msg = this.toString(interceptorContext, stopWatch, mode); + this.getLogger().warn(msg); + } + } else if (time >= tresholdList[3]) { + if (this.getLogger().isInfoEnabled()) { + msg = this.toString(interceptorContext, stopWatch, mode); + this.getLogger().info(msg); + } + } else if (time >= tresholdList[4] && this.getLogger().isDebugEnabled() == true) { + msg = this.toString(interceptorContext, stopWatch, mode); + this.getLogger().debug(msg); + } + } + + /** + * Create the log message for the performance logfile. + * + * @param interceptorContext the context + * @param stopWatch the stopwatch + * @param mode the mode (onEntry, onExit, onError) + * @return the log message + */ + protected String toString(AvalonInterceptorContext interceptorContext, StopWatch stopWatch, int mode) { + Method method = interceptorContext.getMethod(); + Object[] args = interceptorContext.getArgs(); + MethodToStringBuilderImpl methodToStringBuilder = new MethodToStringBuilderImpl(method); + StringBuilder result = new StringBuilder(BUFFER_LENGTH); + + result.append(interceptorContext.getTransactionId()); + result.append(SEPERATOR); + result.append(interceptorContext.getInvocationId()); + result.append(SEPERATOR); + result.append(interceptorContext.getInvocationDepth()); + result.append(SEPERATOR); + result.append(mode); + result.append(SEPERATOR); + result.append(interceptorContext.getServiceShorthand()); + result.append(SEPERATOR); + result.append(method.getName()); + result.append(SEPERATOR); + result.append(stopWatch.getTime()); + result.append(SEPERATOR); + result.append(methodToStringBuilder.toString()); + result.append(SEPERATOR); + result.append(this.toString(args)); + + return result.toString(); + } + + /** + * Prints the argument list. + * + * @param args array of arguments + * @return the debug output + */ + protected String toString(Object[] args) { + StringBuilder result = new StringBuilder(); + ArgumentToStringBuilderImpl toStringBuilder = null; + + if (args == null) { + args = new Object[0]; + } + + for (int i = 0; i < args.length; i++) { + toStringBuilder = new ArgumentToStringBuilderImpl(args[i], this.maxArgLength, 1); + result.append("arg[" + i + "]:={"); + result.append(toStringBuilder.toString()); + result.append("}"); + + if (i < args.length - 1) { + result.append(SEPERATOR); + } + } - return result.toString(); - } + return result.toString(); + } } Modified: turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/interceptor/util/InterceptorToStringBuilder.java URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/interceptor/util/InterceptorToStringBuilder.java?rev=1848876&r1=1848875&r2=1848876&view=diff ============================================================================== --- turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/interceptor/util/InterceptorToStringBuilder.java (original) +++ turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/interceptor/util/InterceptorToStringBuilder.java Thu Dec 13 18:17:39 2018 @@ -41,10 +41,4 @@ public interface InterceptorToStringBuil */ void setMode(int mode); - /** - * Invokes the string builder. - * - * @see java.lang.Object#toString() - */ - public String toString(); } Modified: turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/interceptor/util/StopWatch.java URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/interceptor/util/StopWatch.java?rev=1848876&r1=1848875&r2=1848876&view=diff ============================================================================== --- turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/interceptor/util/StopWatch.java (original) +++ turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/interceptor/util/StopWatch.java Thu Dec 13 18:17:39 2018 @@ -19,31 +19,42 @@ package org.apache.fulcrum.yaafi.interceptor.util; /** - * <p><code>StopWatch</code> provides a convenient API for timings.</p> + * <p> + * <code>StopWatch</code> provides a convenient API for timings. + * </p> * - * <p>To start the watch, call {@link #start()}. At this point you can:</p> + * <p> + * To start the watch, call {@link #start()}. At this point you can: + * </p> * <ul> - * <li>{@link #split()} the watch to get the time whilst the watch continues in the - * background. {@link #unsplit()} will remove the effect of the split. At this point, - * these three options are available again.</li> - * <li>{@link #suspend()} the watch to pause it. {@link #resume()} allows the watch - * to continue. Any time between the suspend and resume will not be counted in - * the total. At this point, these three options are available again.</li> - * <li>{@link #stop()} the watch to complete the timing session.</li> + * <li>{@link #split()} the watch to get the time whilst the watch continues in + * the background. {@link #unsplit()} will remove the effect of the split. At + * this point, these three options are available again.</li> + * <li>{@link #suspend()} the watch to pause it. {@link #resume()} allows the + * watch to continue. Any time between the suspend and resume will not be + * counted in the total. At this point, these three options are available + * again.</li> + * <li>{@link #stop()} the watch to complete the timing session.</li> * </ul> * - * <p>It is intended that the output methods {@link #toString()} and {@link #getTime()} - * should only be called after stop, split or suspend, however a suitable result will - * be returned at other points.</p> + * <p> + * It is intended that the output methods {@link #toString()} and + * {@link #getTime()} should only be called after stop, split or suspend, + * however a suitable result will be returned at other points. + * </p> * - * <p>NOTE: As from v2.1, the methods protect against inappropriate calls. - * Thus you cannot now call stop before start, resume before suspend or - * unsplit before split.</p> + * <p> + * NOTE: As from v2.1, the methods protect against inappropriate calls. Thus you + * cannot now call stop before start, resume before suspend or unsplit before + * split. + * </p> * - * <p>1. split(), suspend(), or stop() cannot be invoked twice <br> + * <p> + * 1. split(), suspend(), or stop() cannot be invoked twice <br> * 2. unsplit() may only be called if the watch has been split()<br> * 3. resume() may only be called if the watch has been suspend()<br> - * 4. start() cannot be called twice without calling reset()</p> + * 4. start() cannot be called twice without calling reset() + * </p> * * @author Henri Yandell * @author Stephen Colebourne @@ -52,225 +63,225 @@ package org.apache.fulcrum.yaafi.interce */ public class StopWatch { - // running states - private static final int STATE_UNSTARTED = 0; - private static final int STATE_RUNNING = 1; - private static final int STATE_STOPPED = 2; - private static final int STATE_SUSPENDED = 3; - - // split state - private static final int STATE_UNSPLIT = 10; - private static final int STATE_SPLIT = 11; - - /** - * The current running state of the StopWatch. - */ - private int runningState = STATE_UNSTARTED; - - /** - * Whether the stopwatch has a split time recorded. - */ - private int splitState = STATE_UNSPLIT; - - /** - * The start time. - */ - private long startTime = -1; - /** - * The stop time. - */ - private long stopTime = -1; - - /** - * <p>Constructor.</p> - */ - public StopWatch() { - // nothing to do - } - - /** - * <p>Start the stopwatch.</p> - * - * <p>This method starts a new timing session, clearing any previous values.</p> - * - * @throws IllegalStateException if the StopWatch is already running. - */ - public void start() - { - if (this.runningState == STATE_STOPPED) - { - throw new IllegalStateException( - "Stopwatch must be reset before being restarted. " ); - } - if (this.runningState != STATE_UNSTARTED) - { - throw new IllegalStateException( "Stopwatch already started. " ); - } - stopTime = -1; - startTime = System.currentTimeMillis(); - this.runningState = STATE_RUNNING; - } - - /** - * <p>Stop the stopwatch.</p> - * - * <p>This method ends a new timing session, allowing the time to be retrieved.</p> - * - * @throws IllegalStateException if the StopWatch is not running. - */ - public void stop() - { - if (this.runningState != STATE_RUNNING - && this.runningState != STATE_SUSPENDED) - { - throw new IllegalStateException( "Stopwatch is not running. " ); - } - stopTime = System.currentTimeMillis(); - this.runningState = STATE_STOPPED; - } - - /** - * <p>Resets the stopwatch. Stops it if need be. </p> - * - * <p>This method clears the internal values to allow the object to be reused.</p> - */ - public void reset() - { - this.runningState = STATE_UNSTARTED; - this.splitState = STATE_UNSPLIT; - startTime = -1; - stopTime = -1; - } - - /** - * <p>Split the time.</p> - * - * <p>This method sets the stop time of the watch to allow a time to be extracted. - * The start time is unaffected, enabling {@link #unsplit()} to continue the - * timing from the original start point.</p> - * - * @throws IllegalStateException if the StopWatch is not running. - */ - public void split() - { - if (this.runningState != STATE_RUNNING) - { - throw new IllegalStateException( "Stopwatch is not running. " ); - } - stopTime = System.currentTimeMillis(); - this.splitState = STATE_SPLIT; - } - - /** - * <p>Remove a split.</p> - * - * <p>This method clears the stop time. The start time is unaffected, enabling - * timing from the original start point to continue.</p> - * - * @throws IllegalStateException if the StopWatch has not been split. - */ - public void unsplit() - { - if (this.splitState != STATE_SPLIT) - { - throw new IllegalStateException( "Stopwatch has not been split. " ); - } - stopTime = -1; - this.splitState = STATE_UNSPLIT; - } - - /** - * <p>Suspend the stopwatch for later resumption.</p> - * - * <p>This method suspends the watch until it is resumed. The watch will not include - * time between the suspend and resume calls in the total time.</p> - * - * @throws IllegalStateException if the StopWatch is not currently running. - */ - public void suspend() - { - if (this.runningState != STATE_RUNNING) - { - throw new IllegalStateException( - "Stopwatch must be running to suspend. " ); - } - stopTime = System.currentTimeMillis(); - this.runningState = STATE_SUSPENDED; - } - - /** - * <p>Resume the stopwatch after a suspend.</p> - * - * <p>This method resumes the watch after it was suspended. The watch will not include - * time between the suspend and resume calls in the total time.</p> - * - * @throws IllegalStateException if the StopWatch has not been suspended. - */ - public void resume() - { - if (this.runningState != STATE_SUSPENDED) - { - throw new IllegalStateException( - "Stopwatch must be suspended to resume. " ); - } - startTime += (System.currentTimeMillis() - stopTime); - stopTime = -1; - this.runningState = STATE_RUNNING; - } - - /** - * <p>Get the time on the stopwatch.</p> - * - * <p>This is either the time between the start and the moment this method - * is called, or the amount of time between start and stop.</p> - * - * @return the time in milliseconds - */ - public long getTime() - { - if (this.runningState == STATE_STOPPED - || this.runningState == STATE_SUSPENDED) - { - return this.stopTime - this.startTime; - } - else if (this.runningState == STATE_UNSTARTED) - { - return 0; - } - else if (this.runningState == STATE_RUNNING) - { - return System.currentTimeMillis() - this.startTime; - } - throw new RuntimeException( "Illegal running state has occured. " ); - } - - /** - * <p>Get the split time on the stopwatch.</p> - * - * <p>This is the time between start and latest split. </p> - * - * @return the split time in milliseconds - * - * @throws IllegalStateException if the StopWatch has not yet been split. - * @since 2.1 - */ - public long getSplitTime() - { - if (this.splitState != STATE_SPLIT) - { - throw new IllegalStateException( - "Stopwatch must be split to get the split time. " - ); - } - return this.stopTime - this.startTime; - } - - /** - * <p>Gets a summary of the time that the stopwatch recorded as a string.</p> - * - * @return the time as a String - */ - public String toString() { - return getTime()+"ms"; - } + // running states + private static final int STATE_UNSTARTED = 0; + private static final int STATE_RUNNING = 1; + private static final int STATE_STOPPED = 2; + private static final int STATE_SUSPENDED = 3; + + // split state + private static final int STATE_UNSPLIT = 10; + private static final int STATE_SPLIT = 11; + + /** + * The current running state of the StopWatch. + */ + private int runningState = STATE_UNSTARTED; + + /** + * Whether the stopwatch has a split time recorded. + */ + private int splitState = STATE_UNSPLIT; + + /** + * The start time. + */ + private long startTime = -1; + /** + * The stop time. + */ + private long stopTime = -1; + + /** + * <p> + * Constructor. + * </p> + */ + public StopWatch() { + // nothing to do + } + + /** + * <p> + * Start the stopwatch. + * </p> + * + * <p> + * This method starts a new timing session, clearing any previous values. + * </p> + * + * @throws IllegalStateException if the StopWatch is already running. + */ + public void start() { + if (this.runningState == STATE_STOPPED) { + throw new IllegalStateException("Stopwatch must be reset before being restarted. "); + } + if (this.runningState != STATE_UNSTARTED) { + throw new IllegalStateException("Stopwatch already started. "); + } + stopTime = -1; + startTime = System.currentTimeMillis(); + this.runningState = STATE_RUNNING; + } + + /** + * <p> + * Stop the stopwatch. + * </p> + * + * <p> + * This method ends a new timing session, allowing the time to be retrieved. + * </p> + * + * @throws IllegalStateException if the StopWatch is not running. + */ + public void stop() { + if (this.runningState != STATE_RUNNING && this.runningState != STATE_SUSPENDED) { + throw new IllegalStateException("Stopwatch is not running. "); + } + stopTime = System.currentTimeMillis(); + this.runningState = STATE_STOPPED; + } + + /** + * <p> + * Resets the stopwatch. Stops it if need be. + * </p> + * + * <p> + * This method clears the internal values to allow the object to be reused. + * </p> + */ + public void reset() { + this.runningState = STATE_UNSTARTED; + this.splitState = STATE_UNSPLIT; + startTime = -1; + stopTime = -1; + } + + /** + * <p> + * Split the time. + * </p> + * + * <p> + * This method sets the stop time of the watch to allow a time to be extracted. + * The start time is unaffected, enabling {@link #unsplit()} to continue the + * timing from the original start point. + * </p> + * + * @throws IllegalStateException if the StopWatch is not running. + */ + public void split() { + if (this.runningState != STATE_RUNNING) { + throw new IllegalStateException("Stopwatch is not running. "); + } + stopTime = System.currentTimeMillis(); + this.splitState = STATE_SPLIT; + } + + /** + * <p> + * Remove a split. + * </p> + * + * <p> + * This method clears the stop time. The start time is unaffected, enabling + * timing from the original start point to continue. + * </p> + * + * @throws IllegalStateException if the StopWatch has not been split. + */ + public void unsplit() { + if (this.splitState != STATE_SPLIT) { + throw new IllegalStateException("Stopwatch has not been split. "); + } + stopTime = -1; + this.splitState = STATE_UNSPLIT; + } + + /** + * <p> + * Suspend the stopwatch for later resumption. + * </p> + * + * <p> + * This method suspends the watch until it is resumed. The watch will not + * include time between the suspend and resume calls in the total time. + * </p> + * + * @throws IllegalStateException if the StopWatch is not currently running. + */ + public void suspend() { + if (this.runningState != STATE_RUNNING) { + throw new IllegalStateException("Stopwatch must be running to suspend. "); + } + stopTime = System.currentTimeMillis(); + this.runningState = STATE_SUSPENDED; + } + + /** + * <p> + * Resume the stopwatch after a suspend. + * </p> + * + * <p> + * This method resumes the watch after it was suspended. The watch will not + * include time between the suspend and resume calls in the total time. + * </p> + * + * @throws IllegalStateException if the StopWatch has not been suspended. + */ + public void resume() { + if (this.runningState != STATE_SUSPENDED) { + throw new IllegalStateException("Stopwatch must be suspended to resume. "); + } + startTime += System.currentTimeMillis() - stopTime; + stopTime = -1; + this.runningState = STATE_RUNNING; + } + + /** + * Get the time on the stopwatch. + * + * This is either the time between the start and the moment this method is + * called, or the amount of time between start and stop. + * + * @return the time in milliseconds + */ + public long getTime() { + if (this.runningState == STATE_STOPPED || this.runningState == STATE_SUSPENDED) { + return this.stopTime - this.startTime; + } else if (this.runningState == STATE_UNSTARTED) { + return 0; + } else if (this.runningState == STATE_RUNNING) { + return System.currentTimeMillis() - this.startTime; + } + throw new RuntimeException("Illegal running state has occured. "); + } + + /** + * Get the split time on the stopwatch. + * + * This is the time between start and latest split. + * + * @return the split time in milliseconds + * @throws IllegalStateException if the StopWatch has not yet been split. + * @since 2.1 + */ + public long getSplitTime() { + if (this.splitState != STATE_SPLIT) { + throw new IllegalStateException("Stopwatch must be split to get the split time. "); + } + return this.stopTime - this.startTime; + } + + /** + * Gets a summary of the time that the stopwatch recorded as a string. + * + * @return the time as a String + */ + public String toString() { + return getTime() + "ms"; + } } Modified: turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/service/advice/AdviceServiceImpl.java URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/service/advice/AdviceServiceImpl.java?rev=1848876&r1=1848875&r2=1848876&view=diff ============================================================================== --- turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/service/advice/AdviceServiceImpl.java (original) +++ turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/service/advice/AdviceServiceImpl.java Thu Dec 13 18:17:39 2018 @@ -100,18 +100,23 @@ public class AdviceServiceImpl extends A return this.advice(this.getDefaultInterceptorList(), object); } - /** - * @see org.apache.fulcrum.yaafi.service.advice.AdviceService#advice(java.lang.String, - * java.lang.Object) + /* + * (non-Javadoc) + * + * @see org.apache.fulcrum.yaafi.service.advice.AdviceService#advice(java.lang. + * String, java.lang.Object) */ public Object advice(String name, Object object) { Validate.notNull(object, "object"); return this.doAdvice(name, this.getDefaultInterceptorList(), object); } - /** - * @see org.apache.fulcrum.yaafi.service.advice.AdviceService#advice(java.lang.String[], - * java.lang.Object) + /* + * (non-Javadoc) + * + * @see + * org.apache.fulcrum.yaafi.service.advice.AdviceService#advice(java.lang.String + * [], java.lang.Object) */ public Object advice(String[] interceptorList, Object object) { Validate.notNull(object, "object"); @@ -119,22 +124,28 @@ public class AdviceServiceImpl extends A return this.doAdvice(className, interceptorList, object); } - /** - * @see org.apache.fulcrum.yaafi.service.advice.AdviceService#advice(java.lang.String, - * java.lang.String[], java.lang.Object) + /* + * (non-Javadoc) + * + * @see org.apache.fulcrum.yaafi.service.advice.AdviceService#advice(java.lang. + * String, java.lang.String[], java.lang.Object) */ public Object advice(String name, String[] interceptorList, Object object) { Validate.notNull(object, "object"); return this.doAdvice(name, interceptorList, object); } - /** - * @see org.apache.fulcrum.yaafi.service.advice.AdviceService#isAdviced(java.lang.Object) + /* + * (non-Javadoc) + * + * @see + * org.apache.fulcrum.yaafi.service.advice.AdviceService#isAdviced(java.lang. + * Object) */ public boolean isAdviced(Object object) { InvocationHandler invocationHandler = null; - if ((object != null) && Proxy.isProxyClass(object.getClass())) { + if (object != null && Proxy.isProxyClass(object.getClass())) { invocationHandler = Proxy.getInvocationHandler(object); return invocationHandler instanceof AvalonInterceptorInvocationHandler; } Modified: turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/service/reconfiguration/ReconfigurationEntry.java URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/service/reconfiguration/ReconfigurationEntry.java?rev=1848876&r1=1848875&r2=1848876&view=diff ============================================================================== --- turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/service/reconfiguration/ReconfigurationEntry.java (original) +++ turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/service/reconfiguration/ReconfigurationEntry.java Thu Dec 13 18:17:39 2018 @@ -1,29 +1,8 @@ package org.apache.fulcrum.yaafi.service.reconfiguration; -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; import java.io.InputStream; -import java.io.OutputStream; import java.security.MessageDigest; import java.util.Arrays; @@ -88,7 +67,7 @@ public class ReconfigurationEntry { if (is == null) { String msg = "Unable to find the following resource : " + this.getLocation(); - this.getLogger().warn(msg); + this.logger.warn(msg); } else { // calculate a SHA-1 digest currDigest = this.getDigest(is); @@ -97,11 +76,11 @@ public class ReconfigurationEntry { if (this.isFirstInvocation() == true) { isFirstInvocation = false; - this.getLogger().debug("Storing SHA-1 digest of " + this.getLocation()); + this.logger.debug("Storing SHA-1 digest of " + this.getLocation()); this.setDigest(currDigest); } else { if (equals(this.digest, currDigest) == false) { - this.getLogger().debug("The following resource has changed : " + this.getLocation()); + this.logger.debug("The following resource has changed : " + this.getLocation()); this.setDigest(currDigest); result = true; } @@ -111,7 +90,7 @@ public class ReconfigurationEntry { return result; } catch (Exception e) { String msg = "The ShutdownService encountered an internal error"; - this.getLogger().error(msg, e); + this.logger.error(msg, e); return false; } finally { if (is != null) { @@ -119,7 +98,7 @@ public class ReconfigurationEntry { is.close(); } catch (Exception e) { String msg = "Can't close the InputStream during error recovery"; - this.getLogger().error(msg, e); + this.logger.error(msg, e); } } } @@ -148,20 +127,13 @@ public class ReconfigurationEntry { } /** - * @return Returns the locator. - */ - private InputStreamLocator getLocator() { - return locator; - } - - /** * Creates an InputStream. * * @return the input stream * @throws IOException the creation failed */ public InputStream locate() throws IOException { - return this.getLocator().locate(this.getLocation()); + return this.locator.locate(this.getLocation()); } /** @@ -175,10 +147,8 @@ public class ReconfigurationEntry { byte[] result = null; byte[] content = null; - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - copy(is, baos); - content = baos.toByteArray(); - baos.close(); + // convert to byte array + content = IOUtils.toByteArray(is); MessageDigest sha1 = MessageDigest.getInstance("SHA1"); sha1.update(content); @@ -206,22 +176,4 @@ public class ReconfigurationEntry { return Arrays.equals(lhs, rhs); } - /** - * Pumps the input stream to the output stream. - * - * @param is the source input stream - * @param os the target output stream - * @throws IOException the copying failed - */ - private static void copy(InputStream is, OutputStream os) throws IOException { - // Use commons managed code - IOUtils.copy(is, os); - } - - /** - * @return Returns the logger. - */ - private Logger getLogger() { - return logger; - } } Modified: turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/service/reconfiguration/ReconfigurationServiceImpl.java URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/service/reconfiguration/ReconfigurationServiceImpl.java?rev=1848876&r1=1848875&r2=1848876&view=diff ============================================================================== --- turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/service/reconfiguration/ReconfigurationServiceImpl.java (original) +++ turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/service/reconfiguration/ReconfigurationServiceImpl.java Thu Dec 13 18:17:39 2018 @@ -40,290 +40,251 @@ import org.apache.avalon.framework.servi import org.apache.avalon.framework.service.Serviceable; import org.apache.fulcrum.yaafi.framework.container.ServiceLifecycleManager; - /** - * Monitors the componentConfiguration.xml and triggers a reconfiguration - * if the content of the component configuration file has changed. + * Monitors the componentConfiguration.xml and triggers a reconfiguration if the + * content of the component configuration file has changed. * * @author <a href="mailto:[email protected]">Siegfried Goeschl</a> */ -public class ReconfigurationServiceImpl - extends AbstractLogEnabled - implements ReconfigurationService, Serviceable, Contextualizable, - Reconfigurable, Initializable, Runnable, Startable, Disposable -{ - /** the interval between two checks in ms */ - private int interval; - - /** shall the worker thread terminate immediately */ - private boolean terminateNow; - - /** the worker thread polling the componentConfiguraton */ - private Thread workerThread; - - /** the ServiceManager to use */ - private ServiceManager serviceManager; - - /** the application directory */ - private File applicationDir; - - /** our list of resources to monitor */ - private ReconfigurationEntry[] reconfigurationEntryList; - - /** the interface to reconfigure individual services */ - private ServiceLifecycleManager serviceLifecycleManager; - - ///////////////////////////////////////////////////////////////////////// - // Avalon Service Lifecycle Implementation - ///////////////////////////////////////////////////////////////////////// - - /** - * Constructor - */ - public ReconfigurationServiceImpl() - { - this.terminateNow = false; - } - - /** - * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager) - */ - public void service(ServiceManager manager) throws ServiceException - { - this.serviceManager = manager; - this.serviceLifecycleManager = (ServiceLifecycleManager) manager; - } - - /** - * @see org.apache.avalon.framework.context.Contextualizable#contextualize(org.apache.avalon.framework.context.Context) - */ - public void contextualize(Context context) throws ContextException - { - this.applicationDir = (File) context.get("urn:avalon:home"); - } - - /** - * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration) - */ - public void configure(Configuration configuration) throws ConfigurationException - { - // limit to minimum interval of 1 second - - this.interval = Math.max( configuration.getAttributeAsInteger("interval",5000), 1000 ); - - this.getLogger().debug( "Monitoring the resources every " + this.interval + " ms" ); - - // parse the resources to monitor - - // Configuration entry = null; - Configuration services = null; - Configuration[] serviceEntries = null; - Configuration[] entryList = configuration.getChildren("entry"); - - String location = null; - String serviceName = null; - String[] serviceNameList = null; - ReconfigurationEntry reconfigurationEntry = null; - ReconfigurationEntry[] list = new ReconfigurationEntry[entryList.length]; - int listIndex = 0; - for ( Configuration entry : entryList ) - { - location = entry.getChild("location").getValue(); - services = entry.getChild("services",false); - - this.getLogger().debug( "Adding the following resource to monitor : " + location ); - - if( services != null ) - { - serviceEntries = services.getChildren("service"); - serviceNameList = new String[serviceEntries.length]; - - for( int j=0; j<serviceEntries.length; j++ ) - { - serviceName = serviceEntries[j].getAttribute("name"); - serviceNameList[j] = serviceName; - } - } - - reconfigurationEntry = new ReconfigurationEntry( - this.getLogger(), - this.applicationDir, - location, - serviceNameList - ); - - list[listIndex++] = reconfigurationEntry; - } - - this.getLogger().debug( "Monitoring " + list.length + " resources" ); - - this.setReconfigurationEntryList(list); - } - - /** - * @see org.apache.avalon.framework.activity.Initializable#initialize() - */ - public void initialize() throws Exception - { - // request a SHA-1 to make sure that it is supported - MessageDigest.getInstance( "SHA1" ); - - // check that the ServiceManager implements Reconfigurable - if( (this.serviceManager instanceof ServiceLifecycleManager) == false ) - throw new IllegalArgumentException( "The ServiceManager instance does not implement ServiceLifecycleManager!" ); - - // create the worker thread polling the target - this.workerThread = new Thread( this, "ReconfigurationService" ); - } - - /** - * @see org.apache.avalon.framework.activity.Startable#start() - */ - public void start() throws Exception - { - this.getLogger().debug( "Starting worker thread ..." ); - this.workerThread.start(); - } - - /** - * @see org.apache.avalon.framework.activity.Startable#stop() - */ - public void stop() throws Exception - { - this.getLogger().debug( "Stopping worker thread ..." ); - this.terminateNow = true; - this.workerThread.interrupt(); - this.workerThread.join( 10000 ); - } - - /** - * @see org.apache.avalon.framework.activity.Disposable#dispose() - */ - public void dispose() - { - this.terminateNow = false; - this.applicationDir = null; - this.workerThread = null; - this.serviceManager = null; - this.reconfigurationEntryList = null; - } - - /** - * @see org.apache.avalon.framework.configuration.Reconfigurable#reconfigure(org.apache.avalon.framework.configuration.Configuration) - */ - public void reconfigure(Configuration configuration) - throws ConfigurationException - { - this.configure(configuration); - } - - ///////////////////////////////////////////////////////////////////////// - // Service interface implementation - ///////////////////////////////////////////////////////////////////////// - - /** - * Polls for changes in the confguration to reconfigure either the - * whole container or just a list of services. - * - * @see java.lang.Runnable#run() - */ - public void run() - { - ReconfigurationEntry[] list = null; - while( this.terminateNow == false ) - { - list = this.getReconfigurationEntryList(); - try - { - for ( ReconfigurationEntry reconfigurationEntry : list ) - { - if( reconfigurationEntry.hasChanged() ) - this.onReconfigure( reconfigurationEntry ); - } - - Thread.sleep( this.interval ); - } - catch( InterruptedException e ) - { - continue; - } - catch(Exception e) - { - String msg = "The ReconfigurationService had a problem"; - this.getLogger().error(msg,e); - continue; - } - } - } - - ///////////////////////////////////////////////////////////////////////// - // Service implementation - ///////////////////////////////////////////////////////////////////////// - - /** - * Reconfigure either the whole container or a list of services. This - * method is called within a seperate worker thred. - * - * @param reconfigurationEntry the configuration what to reconfigure - * @throws Exception the reconfiguration failed - */ - protected void onReconfigure( ReconfigurationEntry reconfigurationEntry ) - throws Exception - { - if( reconfigurationEntry.getServiceList() == null ) - { - // reconfigure the whole container using Avalon Lifecycle Spec - InputStream is = reconfigurationEntry.locate(); - DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder(); - Configuration configuration = builder.build(is); - is.close(); - is = null; - - this.getLogger().warn( "Starting to reconfigure the container" ); - - if( this.serviceManager instanceof Suspendable) - { - this.getLogger().info( "Calling suspend() of the container" ); - ((Suspendable) this.serviceManager).suspend(); - } - - if( this.serviceManager instanceof Reconfigurable) - { - this.getLogger().info( "Calling reconfigure() of the container" ); - ((Reconfigurable) this.serviceManager).reconfigure(configuration); - } - - if( this.serviceManager instanceof Suspendable) - { - this.getLogger().info( "Calling resume() of the container" ); - ((Suspendable) this.serviceManager).resume(); - } - - this.getLogger().info( "Reconfiguring the container was successful" ); - } - else - { - String[] serviceList = reconfigurationEntry.getServiceList(); - this.getLogger().warn( "Calling reconfigure() on individual services : " + serviceList.length ); - this.serviceLifecycleManager.reconfigure(serviceList); - } - } - - /** - * @return Returns the reconfigurationEntryList. - */ - private synchronized ReconfigurationEntry [] getReconfigurationEntryList() - { - return reconfigurationEntryList; - } - - /** - * @param reconfigurationEntryList The reconfigurationEntryList to set. - */ - private synchronized void setReconfigurationEntryList( - ReconfigurationEntry [] reconfigurationEntryList) - { - this.reconfigurationEntryList = reconfigurationEntryList; - } +public class ReconfigurationServiceImpl extends AbstractLogEnabled implements ReconfigurationService, Serviceable, + Contextualizable, Reconfigurable, Initializable, Runnable, Startable, Disposable { + /** the interval between two checks in ms */ + private int interval; + + /** shall the worker thread terminate immediately */ + private boolean terminateNow; + + /** the worker thread polling the componentConfiguraton */ + private Thread workerThread; + + /** the ServiceManager to use */ + private ServiceManager serviceManager; + + /** the application directory */ + private File applicationDir; + + /** our list of resources to monitor */ + private ReconfigurationEntry[] reconfigurationEntryList; + + /** the interface to reconfigure individual services */ + private ServiceLifecycleManager serviceLifecycleManager; + + ///////////////////////////////////////////////////////////////////////// + // Avalon Service Lifecycle Implementation + ///////////////////////////////////////////////////////////////////////// + + /** + * Constructor + */ + public ReconfigurationServiceImpl() { + this.terminateNow = false; + } + + /** + * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager) + */ + public void service(ServiceManager manager) throws ServiceException { + this.serviceManager = manager; + this.serviceLifecycleManager = (ServiceLifecycleManager) manager; + } + + /** + * @see org.apache.avalon.framework.context.Contextualizable#contextualize(org.apache.avalon.framework.context.Context) + */ + public void contextualize(Context context) throws ContextException { + this.applicationDir = (File) context.get("urn:avalon:home"); + } + + /** + * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration) + */ + public void configure(Configuration configuration) throws ConfigurationException { + // limit to minimum interval of 1 second + + this.interval = Math.max(configuration.getAttributeAsInteger("interval", 5000), 1000); + + this.getLogger().debug("Monitoring the resources every " + this.interval + " ms"); + + // parse the resources to monitor + + // Configuration entry = null; + Configuration services = null; + Configuration[] serviceEntries = null; + Configuration[] entryList = configuration.getChildren("entry"); + + String location = null; + String serviceName = null; + String[] serviceNameList = null; + ReconfigurationEntry reconfigurationEntry = null; + ReconfigurationEntry[] list = new ReconfigurationEntry[entryList.length]; + int listIndex = 0; + for (Configuration entry : entryList) { + location = entry.getChild("location").getValue(); + services = entry.getChild("services", false); + + this.getLogger().debug("Adding the following resource to monitor : " + location); + + if (services != null) { + serviceEntries = services.getChildren("service"); + serviceNameList = new String[serviceEntries.length]; + + for (int j = 0; j < serviceEntries.length; j++) { + serviceName = serviceEntries[j].getAttribute("name"); + serviceNameList[j] = serviceName; + } + } + + reconfigurationEntry = new ReconfigurationEntry(this.getLogger(), this.applicationDir, location, + serviceNameList); + + list[listIndex++] = reconfigurationEntry; + } + + this.getLogger().debug("Monitoring " + list.length + " resources"); + + this.setReconfigurationEntryList(list); + } + + /** + * @see org.apache.avalon.framework.activity.Initializable#initialize() + */ + public void initialize() throws Exception { + // request a SHA-1 to make sure that it is supported + MessageDigest.getInstance("SHA1"); + + // check that the ServiceManager implements Reconfigurable + if (this.serviceManager instanceof ServiceLifecycleManager == false) + throw new IllegalArgumentException( + "The ServiceManager instance does not implement ServiceLifecycleManager!"); + + // create the worker thread polling the target + this.workerThread = new Thread(this, "ReconfigurationService"); + } + + /** + * @see org.apache.avalon.framework.activity.Startable#start() + */ + public void start() throws Exception { + this.getLogger().debug("Starting worker thread ..."); + this.workerThread.start(); + } + + /** + * @see org.apache.avalon.framework.activity.Startable#stop() + */ + public void stop() throws Exception { + this.getLogger().debug("Stopping worker thread ..."); + this.terminateNow = true; + this.workerThread.interrupt(); + this.workerThread.join(10000); + } + + /** + * @see org.apache.avalon.framework.activity.Disposable#dispose() + */ + public void dispose() { + this.terminateNow = false; + this.applicationDir = null; + this.workerThread = null; + this.serviceManager = null; + this.reconfigurationEntryList = null; + } + + /** + * @see org.apache.avalon.framework.configuration.Reconfigurable#reconfigure(org.apache.avalon.framework.configuration.Configuration) + */ + public void reconfigure(Configuration configuration) throws ConfigurationException { + this.configure(configuration); + } + + ///////////////////////////////////////////////////////////////////////// + // Service interface implementation + ///////////////////////////////////////////////////////////////////////// + + /** + * Polls for changes in the confguration to reconfigure either the whole + * container or just a list of services. + * + * @see java.lang.Runnable#run() + */ + public void run() { + ReconfigurationEntry[] list = null; + while (this.terminateNow == false) { + list = this.getReconfigurationEntryList(); + try { + for (ReconfigurationEntry reconfigurationEntry : list) { + if (reconfigurationEntry.hasChanged()) + this.onReconfigure(reconfigurationEntry); + } + + Thread.sleep(this.interval); + } catch (InterruptedException e) { + continue; + } catch (Exception e) { + String msg = "The ReconfigurationService had a problem"; + this.getLogger().error(msg, e); + continue; + } + } + } + + ///////////////////////////////////////////////////////////////////////// + // Service implementation + ///////////////////////////////////////////////////////////////////////// + + /** + * Reconfigure either the whole container or a list of services. This method is + * called within a seperate worker thred. + * + * @param reconfigurationEntry the configuration what to reconfigure + * @throws Exception the reconfiguration failed + */ + protected void onReconfigure(ReconfigurationEntry reconfigurationEntry) throws Exception { + if (reconfigurationEntry.getServiceList() == null) { + // reconfigure the whole container using Avalon Lifecycle Spec + InputStream is = reconfigurationEntry.locate(); + DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder(); + Configuration configuration = builder.build(is); + is.close(); + is = null; + + this.getLogger().warn("Starting to reconfigure the container"); + + if (this.serviceManager instanceof Suspendable) { + this.getLogger().info("Calling suspend() of the container"); + ((Suspendable) this.serviceManager).suspend(); + } + + if (this.serviceManager instanceof Reconfigurable) { + this.getLogger().info("Calling reconfigure() of the container"); + ((Reconfigurable) this.serviceManager).reconfigure(configuration); + } + + if (this.serviceManager instanceof Suspendable) { + this.getLogger().info("Calling resume() of the container"); + ((Suspendable) this.serviceManager).resume(); + } + + this.getLogger().info("Reconfiguring the container was successful"); + } else { + String[] serviceList = reconfigurationEntry.getServiceList(); + this.getLogger().warn("Calling reconfigure() on individual services : " + serviceList.length); + this.serviceLifecycleManager.reconfigure(serviceList); + } + } + + /** + * @return Returns the reconfigurationEntryList. + */ + private synchronized ReconfigurationEntry[] getReconfigurationEntryList() { + return reconfigurationEntryList; + } + + /** + * @param reconfigurationEntryList The reconfigurationEntryList to set. + */ + private synchronized void setReconfigurationEntryList(ReconfigurationEntry[] reconfigurationEntryList) { + this.reconfigurationEntryList = reconfigurationEntryList; + } }
