[jboss-cvs] jboss-profiler/java/src/productionProfiler/org/jboss/profiler/production/interceptors/aop ...

Clebert Suconic csuconic at jboss.com
Wed Jun 27 15:44:15 EDT 2007


  User: csuconic
  Date: 07/06/27 15:44:15

  Modified:    java/src/productionProfiler/org/jboss/profiler/production/interceptors/aop 
                        AOPInterceptor.java
  Log:
  Temporarily commented out until we have time to fix the build for this class dependency!
  
  Revision  Changes    Path
  1.2       +238 -237  jboss-profiler/java/src/productionProfiler/org/jboss/profiler/production/interceptors/aop/AOPInterceptor.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: AOPInterceptor.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-profiler/java/src/productionProfiler/org/jboss/profiler/production/interceptors/aop/AOPInterceptor.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -b -r1.1 -r1.2
  --- AOPInterceptor.java	27 Jun 2006 20:59:14 -0000	1.1
  +++ AOPInterceptor.java	27 Jun 2007 19:44:15 -0000	1.2
  @@ -14,19 +14,19 @@
   import java.util.concurrent.TimeUnit;
   import java.util.concurrent.atomic.AtomicBoolean;
   
  -import org.apache.log4j.Logger;
  -import org.jboss.aop.advice.Interceptor;
  -import org.jboss.aop.joinpoint.CallerInvocation;
  -import org.jboss.aop.joinpoint.ConstructorCalledByConstructorInvocation;
  -import org.jboss.aop.joinpoint.ConstructorCalledByMethodInvocation;
  -import org.jboss.aop.joinpoint.ConstructorInvocation;
  -import org.jboss.aop.joinpoint.FieldInvocation;
  -import org.jboss.aop.joinpoint.Invocation;
  -import org.jboss.aop.joinpoint.MethodCalledByConstructorInvocation;
  -import org.jboss.aop.joinpoint.MethodCalledByMethodInvocation;
  -import org.jboss.aop.joinpoint.MethodInvocation;
  -import org.jboss.profiler.production.collector.OperationMetricCollector;
  -import org.jboss.profiler.production.collector.OperationMetricCollectorFactory;
  +//import org.apache.log4j.Logger;
  +//import org.jboss.aop.advice.Interceptor;
  +//import org.jboss.aop.joinpoint.CallerInvocation;
  +//import org.jboss.aop.joinpoint.ConstructorCalledByConstructorInvocation;
  +//import org.jboss.aop.joinpoint.ConstructorCalledByMethodInvocation;
  +//import org.jboss.aop.joinpoint.ConstructorInvocation;
  +//import org.jboss.aop.joinpoint.FieldInvocation;
  +//import org.jboss.aop.joinpoint.Invocation;
  +//import org.jboss.aop.joinpoint.MethodCalledByConstructorInvocation;
  +//import org.jboss.aop.joinpoint.MethodCalledByMethodInvocation;
  +//import org.jboss.aop.joinpoint.MethodInvocation;
  +//import org.jboss.profiler.production.collector.OperationMetricCollector;
  +//import org.jboss.profiler.production.collector.OperationMetricCollectorFactory;
   
   /**
   *
  @@ -36,230 +36,231 @@
   * @author <a href="mailto:nwhitehe at yahoo.com">Nicholas Whitehead</a>
   * @version $Revision$
   */
  -public class AOPInterceptor implements Interceptor {
  -
  -	protected String performanceServiceObjectName = null;
  -	protected String category = null;
  -	private OperationMetricCollectorFactory operationMetricCollectorFactory = null;
  -	protected transient static Logger log = Logger.getLogger(AOPInterceptor.class);
  -	protected AtomicBoolean inited = new AtomicBoolean(false); 
  -	protected boolean async = false;
  -	protected ThreadPoolExecutor threadPool = null;
  -	protected BlockingQueue<Runnable> metricsQueue = null;
  -	protected int queueSize = 200;
  -	protected int corePoolSize = 1;
  -	protected int maxPoolSize = 10;
  -	protected long keepAliveTime = 1000;
  -	protected String timeUnit = TimeUnit.MILLISECONDS.name();
  -	protected TimeUnit tUnit = TimeUnit.MILLISECONDS;
  -	
  -	
  -
  -	/**
  -	 * Constructor
  -	 */
  -	public AOPInterceptor() {
  -		super();
  -		log.info("\n\t==============================================\n\tInstantiated PerformanceAOPInterceptor\n\t==============================================");
  -	}
  -	
  -	
  -	/**
  -	 * Initializes the async handler. 
  -	 *
  -	 */
  -	private synchronized void init() {
  -		if(inited.get()) return;
  -		metricsQueue = new ArrayBlockingQueue<Runnable>(queueSize, true);
  -		threadPool = new ThreadPoolExecutor(corePoolSize, maxPoolSize, keepAliveTime, tUnit, metricsQueue, new ThreadPoolExecutor.DiscardPolicy() );		
  -		inited.set(true);
  -	}
  -
  -	/** 
  -	 * Returns the name of the interceptor.
  -	 * @return The name of the interceptor.
  -	 */
  -	public String getName() {
  -		return category==null ? "PerformanceAOPInterceptor" : "PerformanceAOPInterceptor_" + category; 
  -	}
  -	
  -	/**
  -	 * Processes the performance collection on the invocation.
  -	 * @param invocation
  -	 */
  -	public void processAsyncCollection(Invocation invocation, OperationMetricCollector collector) {
  -		String operationName = invocation.getTargetObject().getClass().getName();	
  -		if(invocation instanceof MethodInvocation) {
  -			MethodInvocation m = (MethodInvocation) invocation;
  -			Method method = m.getActualMethod();
  -			String[] splitMethod = method.getName().split("\\$");
  -			operationName = method.getDeclaringClass().getName() + "." + splitMethod[splitMethod.length-2];
  -		} else if(invocation instanceof MethodInvocation) {
  -			FieldInvocation fieldInvocation = (FieldInvocation)invocation;
  -			operationName = fieldInvocation.getTargetObject().getClass().getName() + "." + fieldInvocation.getField().getName();
  -		} else if(invocation instanceof ConstructorInvocation) {
  -			ConstructorInvocation constructorInvocation = (ConstructorInvocation)invocation;
  -			operationName = constructorInvocation.getTargetObject() + "." + constructorInvocation.getConstructor().getName();
  -		} else if(invocation instanceof CallerInvocation) {
  -			CallerInvocation callerInvocation = (CallerInvocation)invocation;
  -			operationName = callerInvocation.getTargetObject().getClass().getName() + ".";
  -			if(callerInvocation instanceof ConstructorCalledByConstructorInvocation) {
  -				ConstructorCalledByConstructorInvocation constructorCalledByConstructorInvocation = (ConstructorCalledByConstructorInvocation)callerInvocation;
  -				operationName.concat(constructorCalledByConstructorInvocation.getCalledConstructor().getName());					
  -			} else if(callerInvocation instanceof ConstructorCalledByMethodInvocation) {
  -				ConstructorCalledByMethodInvocation constructorCalledByMethodInvocation = (ConstructorCalledByMethodInvocation)callerInvocation;
  -				operationName.concat(constructorCalledByMethodInvocation.getCalledConstructor().getName());
  -			} else if(callerInvocation instanceof MethodCalledByConstructorInvocation) {
  -				MethodCalledByConstructorInvocation methodCalledByConstructorInvocation = (MethodCalledByConstructorInvocation)callerInvocation;
  -				operationName.concat(methodCalledByConstructorInvocation.getCalledMethod().getName());
  -			} else if(callerInvocation instanceof MethodCalledByMethodInvocation) {
  -				MethodCalledByMethodInvocation methodCalledByMethodInvocation = (MethodCalledByMethodInvocation)callerInvocation;
  -				operationName.concat(methodCalledByMethodInvocation.getCalledMethod().getName());
  -			} else {
  -				operationName.concat("Unknown");
  -			}
  -		}
  -		collector.setOperationName(operationName);
  -		try {
  -			operationMetricCollectorFactory.submitCollector(collector);
  -		} catch (Exception e) {
  -			
  -		}
  -		
  -	}
  -		
  -
  -
  -	/**
  -	 * Intercepts the invocation and submits a performance reading.
  -	 * @param invocation The invocation to be measured.
  -	 * @return The return value of the intercepted method.
  -	 */
  -	public Object invoke(Invocation invocation) throws Throwable {
  -		if(async && !inited.get()) {
  -			init();
  -		}
  -		Object retVal = null;			
  -		long start = System.nanoTime();
  -		OperationMetricCollector collector = null;
  -		collector = operationMetricCollectorFactory.newCollector(category, "");		
  -		retVal = invocation.invokeNext();
  -		operationMetricCollectorFactory.closeCollector(collector);
  -		if(async) {			
  -			// handle the name resolution and submission asynchronously
  -			threadPool.execute(new InvocationSubmissionWrapper(this, invocation, collector));
  -		} else {
  -			// handle the name resolution and submission synchronously
  -			processAsyncCollection(invocation, collector);
  -		}
  -		
  -		
  -		float elapsed = (System.nanoTime()-start)/1000000;
  -		if(log.isDebugEnabled())log.debug("Intercepted Call for " + invocation.getTargetObject().getClass().getName() + " in " + elapsed + " ms.");			
  -		
  -		return retVal;
  -	}
  -	
  -
  -	/**
  -	 * Sets the category.
  -	 * @param category The category that metric submitted from this interceptor will be recorded under.
  -	 */
  -	public void setCategory(String category) {
  -		this.category = category;
  -	}
  -
  -	/**
  -	 * Sets the object name of the performance service.
  -	 * @param performanceServiceObjectName
  -	 */
  -	public void setPerformanceServiceObjectName(String performanceServiceObjectName) {
  -		this.performanceServiceObjectName = performanceServiceObjectName;
  -		operationMetricCollectorFactory = OperationMetricCollectorFactory.getInstance(performanceServiceObjectName, true);
  -	}
  -
  -	/**
  -	 * Sets the async of the interceptor to allow metrics to be submitted asynchronously 
  -	 * and have less elapsed time overhead on the actual invocation.
  -	 * @param async If true, metrics are captured asynchronously. Default is false.
  -	 */
  -	public void setAsync(boolean async) {
  -		this.async = async;
  -	}
  -
  -	/**
  -	 * Sets the size of the thread pool's queue.
  -	 * Default is 200.
  -	 * @param queueSize The queue size of the async thread pool. 
  -	 */
  -	public void setQueueSize(int queueSize) {
  -		this.queueSize = queueSize;
  -	}
  -	
  -	/**
  -	 * Sets the core number of threads for the async handler.
  -	 * Defaults to 1.
  -	 * @param corePoolSize The core number of threads.
  -	 */
  -	public void setCorePoolSize(int corePoolSize) {
  -		this.corePoolSize = corePoolSize;
  -	}
  -
  -	/**
  -	 * Sets the time limit for which threads may remain idle before being terminated in the async handler.
  -	 * Defaults to 1000.
  -	 * The unit will be set in the TimeUnit attribute or default to MILLISECONDS. 
  -	 * @param keepAliveTime
  -	 */
  -	public void setKeepAliveTime(long keepAliveTime) {
  -		this.keepAliveTime = keepAliveTime;
  -	}
  -
  -	/**
  -	 * Sets the maximum number of threads for the async handler.
  -	 * Defaults to 10.
  -	 * @param maxPoolSize The maximum number of threads.
  -	 */
  -	public void setMaxPoolSize(int maxPoolSize) {
  -		this.maxPoolSize = maxPoolSize;
  -	}
  -
  -	/**
  -	 * Sets the units of time for the keepAlive time.
  -	 * Defaults to milliseconds.
  -	 * @param timeUnit A valid string representation of a TimeUnit.
  -	 */
  -	public void setTimeUnit(String timeUnit) {
  -		try {
  -			tUnit = TimeUnit.valueOf(timeUnit);
  -		} catch (Exception e) {
  -			
  -		}
  -	}
  -
  -}
  -
  -class InvocationSubmissionWrapper extends Thread {
  -	private AOPInterceptor interceptor = null;
  -	private Invocation invocation = null;
  -	private OperationMetricCollector collector = null;
  -	
  -	public InvocationSubmissionWrapper(AOPInterceptor interceptor, Invocation invocation, OperationMetricCollector collector) {
  -		this.interceptor = interceptor;
  -		this.invocation = invocation;
  -		this.collector = collector;
  -	}
  -	
  -	/**
  -	 * Runs the invocation submission under a seperate thread.
  -	 */
  -	public void run() {
  -		try {
  -			interceptor.processAsyncCollection(invocation, collector);
  -		} catch (Exception e) {
  -			
  -		}
  -	}
  +public class AOPInterceptor //implements Interceptor 
  +{
   	
  +//	protected String performanceServiceObjectName = null;
  +//	protected String category = null;
  +//	private OperationMetricCollectorFactory operationMetricCollectorFactory = null;
  +//	protected transient static Logger log = Logger.getLogger(AOPInterceptor.class);
  +//	protected AtomicBoolean inited = new AtomicBoolean(false); 
  +//	protected boolean async = false;
  +//	protected ThreadPoolExecutor threadPool = null;
  +//	protected BlockingQueue<Runnable> metricsQueue = null;
  +//	protected int queueSize = 200;
  +//	protected int corePoolSize = 1;
  +//	protected int maxPoolSize = 10;
  +//	protected long keepAliveTime = 1000;
  +//	protected String timeUnit = TimeUnit.MILLISECONDS.name();
  +//	protected TimeUnit tUnit = TimeUnit.MILLISECONDS;
  +//	
  +//	
  +//
  +//	/**
  +//	 * Constructor
  +//	 */
  +//	public AOPInterceptor() {
  +//		super();
  +//		log.info("\n\t==============================================\n\tInstantiated PerformanceAOPInterceptor\n\t==============================================");
  +//	}
  +//	
  +//	
  +//	/**
  +//	 * Initializes the async handler. 
  +//	 *
  +//	 */
  +//	private synchronized void init() {
  +//		if(inited.get()) return;
  +//		metricsQueue = new ArrayBlockingQueue<Runnable>(queueSize, true);
  +//		threadPool = new ThreadPoolExecutor(corePoolSize, maxPoolSize, keepAliveTime, tUnit, metricsQueue, new ThreadPoolExecutor.DiscardPolicy() );		
  +//		inited.set(true);
  +//	}
  +//
  +//	/** 
  +//	 * Returns the name of the interceptor.
  +//	 * @return The name of the interceptor.
  +//	 */
  +//	public String getName() {
  +//		return category==null ? "PerformanceAOPInterceptor" : "PerformanceAOPInterceptor_" + category; 
  +//	}
  +//	
  +//	/**
  +//	 * Processes the performance collection on the invocation.
  +//	 * @param invocation
  +//	 */
  +//	public void processAsyncCollection(Invocation invocation, OperationMetricCollector collector) {
  +//		String operationName = invocation.getTargetObject().getClass().getName();	
  +//		if(invocation instanceof MethodInvocation) {
  +//			MethodInvocation m = (MethodInvocation) invocation;
  +//			Method method = m.getActualMethod();
  +//			String[] splitMethod = method.getName().split("\\$");
  +//			operationName = method.getDeclaringClass().getName() + "." + splitMethod[splitMethod.length-2];
  +//		} else if(invocation instanceof MethodInvocation) {
  +//			FieldInvocation fieldInvocation = (FieldInvocation)invocation;
  +//			operationName = fieldInvocation.getTargetObject().getClass().getName() + "." + fieldInvocation.getField().getName();
  +//		} else if(invocation instanceof ConstructorInvocation) {
  +//			ConstructorInvocation constructorInvocation = (ConstructorInvocation)invocation;
  +//			operationName = constructorInvocation.getTargetObject() + "." + constructorInvocation.getConstructor().getName();
  +//		} else if(invocation instanceof CallerInvocation) {
  +//			CallerInvocation callerInvocation = (CallerInvocation)invocation;
  +//			operationName = callerInvocation.getTargetObject().getClass().getName() + ".";
  +//			if(callerInvocation instanceof ConstructorCalledByConstructorInvocation) {
  +//				ConstructorCalledByConstructorInvocation constructorCalledByConstructorInvocation = (ConstructorCalledByConstructorInvocation)callerInvocation;
  +//				operationName.concat(constructorCalledByConstructorInvocation.getCalledConstructor().getName());					
  +//			} else if(callerInvocation instanceof ConstructorCalledByMethodInvocation) {
  +//				ConstructorCalledByMethodInvocation constructorCalledByMethodInvocation = (ConstructorCalledByMethodInvocation)callerInvocation;
  +//				operationName.concat(constructorCalledByMethodInvocation.getCalledConstructor().getName());
  +//			} else if(callerInvocation instanceof MethodCalledByConstructorInvocation) {
  +//				MethodCalledByConstructorInvocation methodCalledByConstructorInvocation = (MethodCalledByConstructorInvocation)callerInvocation;
  +//				operationName.concat(methodCalledByConstructorInvocation.getCalledMethod().getName());
  +//			} else if(callerInvocation instanceof MethodCalledByMethodInvocation) {
  +//				MethodCalledByMethodInvocation methodCalledByMethodInvocation = (MethodCalledByMethodInvocation)callerInvocation;
  +//				operationName.concat(methodCalledByMethodInvocation.getCalledMethod().getName());
  +//			} else {
  +//				operationName.concat("Unknown");
  +//			}
  +//		}
  +//		collector.setOperationName(operationName);
  +//		try {
  +//			operationMetricCollectorFactory.submitCollector(collector);
  +//		} catch (Exception e) {
  +//			
  +//		}
  +//		
  +//	}
  +//		
  +//
  +//
  +//	/**
  +//	 * Intercepts the invocation and submits a performance reading.
  +//	 * @param invocation The invocation to be measured.
  +//	 * @return The return value of the intercepted method.
  +//	 */
  +//	public Object invoke(Invocation invocation) throws Throwable {
  +//		if(async && !inited.get()) {
  +//			init();
  +//		}
  +//		Object retVal = null;			
  +//		long start = System.nanoTime();
  +//		OperationMetricCollector collector = null;
  +//		collector = operationMetricCollectorFactory.newCollector(category, "");		
  +//		retVal = invocation.invokeNext();
  +//		operationMetricCollectorFactory.closeCollector(collector);
  +//		if(async) {			
  +//			// handle the name resolution and submission asynchronously
  +//			threadPool.execute(new InvocationSubmissionWrapper(this, invocation, collector));
  +//		} else {
  +//			// handle the name resolution and submission synchronously
  +//			processAsyncCollection(invocation, collector);
  +//		}
  +//		
  +//		
  +//		float elapsed = (System.nanoTime()-start)/1000000;
  +//		if(log.isDebugEnabled())log.debug("Intercepted Call for " + invocation.getTargetObject().getClass().getName() + " in " + elapsed + " ms.");			
  +//		
  +//		return retVal;
  +//	}
  +//	
  +//
  +//	/**
  +//	 * Sets the category.
  +//	 * @param category The category that metric submitted from this interceptor will be recorded under.
  +//	 */
  +//	public void setCategory(String category) {
  +//		this.category = category;
  +//	}
  +//
  +//	/**
  +//	 * Sets the object name of the performance service.
  +//	 * @param performanceServiceObjectName
  +//	 */
  +//	public void setPerformanceServiceObjectName(String performanceServiceObjectName) {
  +//		this.performanceServiceObjectName = performanceServiceObjectName;
  +//		operationMetricCollectorFactory = OperationMetricCollectorFactory.getInstance(performanceServiceObjectName, true);
  +//	}
  +//
  +//	/**
  +//	 * Sets the async of the interceptor to allow metrics to be submitted asynchronously 
  +//	 * and have less elapsed time overhead on the actual invocation.
  +//	 * @param async If true, metrics are captured asynchronously. Default is false.
  +//	 */
  +//	public void setAsync(boolean async) {
  +//		this.async = async;
  +//	}
  +//
  +//	/**
  +//	 * Sets the size of the thread pool's queue.
  +//	 * Default is 200.
  +//	 * @param queueSize The queue size of the async thread pool. 
  +//	 */
  +//	public void setQueueSize(int queueSize) {
  +//		this.queueSize = queueSize;
  +//	}
  +//	
  +//	/**
  +//	 * Sets the core number of threads for the async handler.
  +//	 * Defaults to 1.
  +//	 * @param corePoolSize The core number of threads.
  +//	 */
  +//	public void setCorePoolSize(int corePoolSize) {
  +//		this.corePoolSize = corePoolSize;
  +//	}
  +//
  +//	/**
  +//	 * Sets the time limit for which threads may remain idle before being terminated in the async handler.
  +//	 * Defaults to 1000.
  +//	 * The unit will be set in the TimeUnit attribute or default to MILLISECONDS. 
  +//	 * @param keepAliveTime
  +//	 */
  +//	public void setKeepAliveTime(long keepAliveTime) {
  +//		this.keepAliveTime = keepAliveTime;
  +//	}
  +//
  +//	/**
  +//	 * Sets the maximum number of threads for the async handler.
  +//	 * Defaults to 10.
  +//	 * @param maxPoolSize The maximum number of threads.
  +//	 */
  +//	public void setMaxPoolSize(int maxPoolSize) {
  +//		this.maxPoolSize = maxPoolSize;
  +//	}
  +//
  +//	/**
  +//	 * Sets the units of time for the keepAlive time.
  +//	 * Defaults to milliseconds.
  +//	 * @param timeUnit A valid string representation of a TimeUnit.
  +//	 */
  +//	public void setTimeUnit(String timeUnit) {
  +//		try {
  +//			tUnit = TimeUnit.valueOf(timeUnit);
  +//		} catch (Exception e) {
  +//			
  +//		}
  +//	}
  +//
  +//}
  +//
  +//class InvocationSubmissionWrapper extends Thread {
  +//	private AOPInterceptor interceptor = null;
  +//	private Invocation invocation = null;
  +//	private OperationMetricCollector collector = null;
  +//	
  +//	public InvocationSubmissionWrapper(AOPInterceptor interceptor, Invocation invocation, OperationMetricCollector collector) {
  +//		this.interceptor = interceptor;
  +//		this.invocation = invocation;
  +//		this.collector = collector;
  +//	}
  +//	
  +//	/**
  +//	 * Runs the invocation submission under a seperate thread.
  +//	 */
  +//	public void run() {
  +//		try {
  +//			interceptor.processAsyncCollection(invocation, collector);
  +//		} catch (Exception e) {
  +//			
  +//		}
  +//	}
  +//	
   	
   }
  
  
  



More information about the jboss-cvs-commits mailing list