org.alfresco.repo.transaction
Class SingleEntryTransactionResourceInterceptor

java.lang.Object
  extended by org.alfresco.repo.transaction.SingleEntryTransactionResourceInterceptor
All Implemented Interfaces:
org.aopalliance.aop.Advice, org.aopalliance.intercept.Interceptor, org.aopalliance.intercept.MethodInterceptor

public class SingleEntryTransactionResourceInterceptor
extends java.lang.Object
implements org.aopalliance.intercept.MethodInterceptor

This interceptor gathers basic method call statistics and calls the resource managers for further processing. The resource managers are called after the method invocations, but it doesn't matter too much since they are called on a time frequency basis.

It acts as a sampling tool, but doesn't make any decisions or take any action with regard system or transaction-related resources. All samples are stored against the current transaction. If there is no current transaction then no action will be taken with respect to the resource management.

The default is to activate after 10s and call through every 5s.

This class supports both interceptor-based calling as well as manual calling. Long-running processes can call an this manually on every iteration and get the same behaviour of regular calls to the resouce managers.

The current thread is marked on first entry and all subsequent nested re-entries will just get passed down to the underlying delegate invocation method.

Since:
2.1.3
See Also:
MethodResourceManager

Constructor Summary
SingleEntryTransactionResourceInterceptor()
           
 
Method Summary
 java.lang.Object invoke(org.aopalliance.intercept.MethodInvocation invocation)
           
 void performManualCheck(java.lang.reflect.Method calledMethod, long deltaNs)
          An alternative method allowing a manual call to check the resources.
 void setElapsedTimeBeforeActivationMillis(long elapsedTimeBeforeActivationMillis)
          Set the minimum number of seconds that a transaction must have been running for before method sampling begins.
 void setMethodResourceManagers(java.util.List methodResourceManagers)
          Set the method-based resource managers that will be notified of the statistics.
 void setResourceManagerCallFrequencyMillis(long resourceManagerCallFrequencyMillis)
          Set the approximate time between calls to the registered resource managers.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SingleEntryTransactionResourceInterceptor

public SingleEntryTransactionResourceInterceptor()
Method Detail

setMethodResourceManagers

public void setMethodResourceManagers(java.util.List methodResourceManagers)
Set the method-based resource managers that will be notified of the statistics.

Parameters:
methodResourceManagers - a list of resource managers - may be null or empty

setElapsedTimeBeforeActivationMillis

public void setElapsedTimeBeforeActivationMillis(long elapsedTimeBeforeActivationMillis)
Set the minimum number of seconds that a transaction must have been running for before method sampling begins. The interceptor does nothing prior to this.

Parameters:
elapsedTimeBeforeActivationMillis - an initial idle time in milliseconds

setResourceManagerCallFrequencyMillis

public void setResourceManagerCallFrequencyMillis(long resourceManagerCallFrequencyMillis)
Set the approximate time between calls to the registered resource managers. This applies to this instance of the interceptor and not to the transaction. If a single instance of this class is used in multiple places, then the resource managers will still only get called at a steady rate. This is mainly in order to streamline the interception prior to the activation phase, but suits the resource managers since they get given the exact methods that were called anyway.

Parameters:
resourceManagerCallFrequencyMillis - an approximate time between calls to the resource managers

invoke

public java.lang.Object invoke(org.aopalliance.intercept.MethodInvocation invocation)
                        throws java.lang.Throwable
Specified by:
invoke in interface org.aopalliance.intercept.MethodInterceptor
Throws:
java.lang.Throwable

performManualCheck

public void performManualCheck(java.lang.reflect.Method calledMethod,
                               long deltaNs)
An alternative method allowing a manual call to check the resources. This is useful in the cases where long running iterations don't necessarily pass through the necessary API stack, or where the specific resources in hand can't be dealt with blindly before and after resource management. The elapsed time should be that of the iteration within the method (it is assumed that there won't be more than one).

If you have a loop in a method that doesn't call anything that can be intercepted and handle safely, then get a pre-configured instance (usually from the application context) and mimic the interceptor call.

You should get the Method, which is used for informational purposes, in a single call when you calling code is loaded by the classloader. Introspecting every time you wish to call this method is unnecessary.

Parameters:
calledMethod - the method that this check applies to
deltaNs - the time in milliseconds that the repeated operation took


Copyright © 2005 - 2010 Alfresco Software, Inc. All Rights Reserved.