FileDocCategorySizeDatePackage
AsyncHandler.javaAPI DocGlassfish v2 API20983Fri May 04 22:24:18 BST 2007com.sun.enterprise.admin.monitor.callflow

AsyncHandler

public class AsyncHandler extends Object implements AsyncHandlerIntf
This class asynchronously writes supplied input into a data base. That is, a separate asynchronous thread is used to write data to the data base. The implementation uses a typical producer - consumer model: The data produced by application threads is collected in unbounded queue objects; an asynchronous thread consumes the data from the queues and writes it out to the data base.
author
Ram Jeyaraman, Harpreet Singh
date
March 21, 2005

Fields Summary
private static final Logger
logger
Static fields
private static final int
WAIT_INTERVALS
private static final int
MAX_BULK_SIZE
private static final int
BUFFER_COUNT
private static final String
THREAD_NAME
private LinkedBlockingQueue
requestStartQ
Private fields
private LinkedBlockingQueue
requestEndQ
private LinkedBlockingQueue
methodStartQ
private LinkedBlockingQueue
methodEndQ
private LinkedBlockingQueue
startTimeQ
private LinkedBlockingQueue
endTimeQ
private ConcurrentLinkedQueue
requestStartFreeQ
private ConcurrentLinkedQueue
requestEndFreeQ
private ConcurrentLinkedQueue
methodStartFreeQ
private ConcurrentLinkedQueue
methodEndFreeQ
private ConcurrentLinkedQueue
startTimeFreeQ
private ConcurrentLinkedQueue
endTimeFreeQ
private AsyncThread
asyncThread
private boolean
enabled
Constructors Summary
AsyncHandler()

        
        requestStartQ = new LinkedBlockingQueue<RequestStartTO>();
        requestEndQ = new LinkedBlockingQueue<RequestEndTO>();
        methodStartQ = new LinkedBlockingQueue<MethodStartTO>();
        methodEndQ = new LinkedBlockingQueue<MethodEndTO>();
        startTimeQ = new LinkedBlockingQueue<StartTimeTO>();
        endTimeQ = new LinkedBlockingQueue<EndTimeTO>();
        
        requestStartFreeQ = new ConcurrentLinkedQueue<RequestStartTO>();
        requestEndFreeQ = new ConcurrentLinkedQueue<RequestEndTO>();
        methodStartFreeQ = new ConcurrentLinkedQueue<MethodStartTO>();
        methodEndFreeQ = new ConcurrentLinkedQueue<MethodEndTO>();
        startTimeFreeQ = new ConcurrentLinkedQueue<StartTimeTO>();
        endTimeFreeQ = new ConcurrentLinkedQueue<EndTimeTO>();
        
        asyncThread = new AsyncThread ();
    
Methods Summary
public synchronized voiddisable()

        asyncThread.shutdown();
        enabled = false;
        asyncThread = null;
    
public synchronized voidenable()

        if (!enabled){
            enabled = true;
            if (asyncThread == null)
                asyncThread = new AsyncThread ();
            asyncThread.start();
        }
    
public voidflush()

public voidhandleEndTime(java.lang.String requestId, long timeStamp, ContainerTypeOrApplicationType type)

        EndTimeTO etto = endTimeFreeQ.poll();
        if (etto == null) {
            etto = new EndTimeTO();
        }
        etto.setRequestId(requestId);
        etto.setTimeStamp(timeStamp);
        etto.setContainerTypeOrApplicationType(type);
        boolean success = false;
        while (!success) {
            try {
                endTimeQ.put(etto);
                success = true;
            } catch (InterruptedException e) {
                logger.log(
                        Level.FINE,
                        "callflow.transfer_to_async_thread_interrupted", e);
            }
        }
    
public voidhandleMethodEnd(java.lang.String requestId, long timeStamp, java.lang.Throwable exception)

        MethodEndTO meto = methodEndFreeQ.poll();
        if (meto == null) {
            meto = new MethodEndTO();
        }
        meto.setRequestId(requestId);
        meto.setTimeStamp(timeStamp);
        meto.setException(((exception == null) ? null : exception.toString()));
        
        boolean success = false;
        while (!success) {
            try {
                methodEndQ.put(meto);
                success = true;
            } catch (InterruptedException e) {
                logger.log(
                        Level.FINE,
                        "callflow.transfer_to_async_thread_interrupted", e);
            }
        }
    
public voidhandleMethodStart(java.lang.String requestId, long timeStamp, java.lang.String methodName, ComponentType componentType, java.lang.String applicationName, java.lang.String moduleName, java.lang.String componentName, java.lang.String threadId, java.lang.String transactionId, java.lang.String securityId)

        MethodStartTO msto = methodStartFreeQ.poll();
        if (msto == null) {
            msto = new MethodStartTO();
        }
        msto.setRequestId(requestId);
        msto.setTimeStamp(timeStamp);
        msto.setMethodName(methodName);
        msto.setComponentType(componentType);
        msto.setAppName(applicationName);
        msto.setModuleName(moduleName);
        msto.setComponentName(componentName);
        msto.setThreadId(threadId);
        msto.setTransactionId(transactionId);
        msto.setSecurityId(securityId);
        
        boolean success = false;
        while (!success) {
            try {
                methodStartQ.put(msto);
                success = true;
            } catch (InterruptedException e) {
                logger.log(
                        Level.FINE,
                        "callflow.transfer_to_async_thread_interrupted", e);
            }
        }
    
public voidhandleRequestEnd(java.lang.String requestId, long timeStamp)

        RequestEndTO reto = requestEndFreeQ.poll();
        if (reto == null) {
            reto = new RequestEndTO();
        }
        reto.setRequestId(requestId);
        reto.setTimeStamp(timeStamp);

        boolean success = false;
        while (!success) {
            try {
                requestEndQ.put(reto);
                success = true;
            } catch (InterruptedException e) {
                logger.log(
                        Level.FINE,
                        "callflow.transfer_to_async_thread_interrupted", e);
            }
        }
    
public voidhandleRequestStart(java.lang.String requestId, long timeStamp, long timeStampMillis, RequestType requestType, java.lang.String callerIPAddress, java.lang.String remoteUser)

        RequestStartTO rsto = requestStartFreeQ.poll();
        if (rsto == null) {
            rsto = new RequestStartTO();
        }
        rsto.setRequestId(requestId);
        rsto.setTimeStamp(timeStamp);
        rsto.setTimeStampMillis(timeStampMillis);
        rsto.setRequestType(requestType);
        rsto.setIpAddress(callerIPAddress);
        //rsto.setRemoteUser(remoteUser); // not currently in db schema.
        boolean success = false;
        while (!success) {
            try {
                requestStartQ.put(rsto);
                success = true;
            } catch (InterruptedException e) {
                logger.log(
                        Level.FINE,
                        "callflow.transfer_to_async_thread_interrupted", e);
            }
        }
    
public voidhandleStartTime(java.lang.String requestId, long timeStamp, ContainerTypeOrApplicationType type)

        StartTimeTO stto = startTimeFreeQ.poll();
        if (stto == null) {
            stto = new StartTimeTO();
        }
        stto.setRequestId(requestId);
        stto.setTimeStamp(timeStamp);
        stto.setContainerTypeOrApplicationType(type);
        boolean success = false;
        while (!success) {
            try {
                startTimeQ.put(stto);
                success = true;
            } catch (InterruptedException e) {
                logger.log(
                        Level.FINE,
                        "callflow.transfer_to_async_thread_interrupted", e);
            }
        }