org.e2etrace.trace
Class DefaultTraceSession

java.lang.Object
  extended by org.e2etrace.trace.DefaultTraceSession
All Implemented Interfaces:
ITraceSession

public class DefaultTraceSession
extends Object
implements ITraceSession

Default-Implementation of a trace session.

The session uses a default trace configuration (see DefaultTraceConfig). This can be changed by setConfig. As soon as a trace session manager that extends AbstractTraceSessionManager is in control of the session, the trace configuration assigned to the session manager will automatically be forwarded to the trace session.

Author:
Gunther Popp

Constructor Summary
DefaultTraceSession(String sessionId, ITraceStepFactory stepFactory)
          Default constructor.
 
Method Summary
 void enterStep(Class clazz, String method)
          Wrapper for ITraceSession.enterStep(ITraceStepId) using a MethodTraceStepId as TraceStep-IDs.
 void enterStep(ITraceStepId id)
          Enters a new trace step with the supplied id.
 void enterStep(String id)
          Wrapper for ITraceSession.enterStep(ITraceStepId) using a String as TraceStep-IDs.
 ITraceConfig getConfig()
          Returns the trace configuration of the session.
 ITraceStep getCurrentStep()
          Returns the active trace step.
 long getDuration()
          Returns the execution time of the complete trace session.
 ITraceStep getRootStep()
          Returns the the root step.
 void leaveStep(Class clazz, String method)
          Wrapper for ITraceSession.leaveStep(ITraceStepId) using a MethodTraceStepId as TraceStep-IDs.
 void leaveStep(ITraceStepId id)
          Leaves the trace step with the given id.
 void leaveStep(String id)
          Wrapper for ITraceSession.leaveStep(ITraceStepId) using a String as TraceStep-IDs.
 void setConfig(ITraceConfig tc)
          Assigns a new trace configuratio to the trace session.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultTraceSession

public DefaultTraceSession(String sessionId,
                           ITraceStepFactory stepFactory)
Default constructor.

Parameters:
sessionId - id of the session. This id will be used for the root step of the session. It will be prefixed by a dollar sign ($) (see TraceSessionRootStep and TraceSessionRootStepId)
stepFactory - Factory used for the concrete trace steps in the context of this session
Method Detail

enterStep

public void enterStep(Class clazz,
                      String method)
Wrapper for ITraceSession.enterStep(ITraceStepId) using a MethodTraceStepId as TraceStep-IDs.

Specified by:
enterStep in interface ITraceSession
Parameters:
clazz - Class instance to which the method belongs
method - Name of the executed method

leaveStep

public void leaveStep(Class clazz,
                      String method)
Wrapper for ITraceSession.leaveStep(ITraceStepId) using a MethodTraceStepId as TraceStep-IDs.

Specified by:
leaveStep in interface ITraceSession
Parameters:
clazz - Class instance to which the method belongs
method - Name of the executed method

enterStep

public void enterStep(String id)
Wrapper for ITraceSession.enterStep(ITraceStepId) using a String as TraceStep-IDs.

Specified by:
enterStep in interface ITraceSession
Parameters:
id - String used as id

leaveStep

public void leaveStep(String id)
Wrapper for ITraceSession.leaveStep(ITraceStepId) using a String as TraceStep-IDs.

Specified by:
leaveStep in interface ITraceSession
Parameters:
id - String used as id

enterStep

public void enterStep(ITraceStepId id)
Enters a new trace step with the supplied id.

In reality, a trace step covers for example the execution of a single method. In this case, enterStep must be called when the method starts and leaveStep when the method ends.

To get exact results, each call of enterStep should be matched by a corresponding call of leaveStep. A trace session can handle missing leaveStep calls. In this case, leaveStep will be automatically invoked when the parent step ends (if any). If no parent exists, no duration will be calculated.

Specified by:
enterStep in interface ITraceSession
Parameters:
id - ID of the trace step

leaveStep

public void leaveStep(ITraceStepId id)
Leaves the trace step with the given id.

Specified by:
leaveStep in interface ITraceSession
Parameters:
id - ID of the trace step

getRootStep

public ITraceStep getRootStep()
Returns the the root step.

The root step is the step that covers the complete service call (i.e. that has no parent step). The id of the root step is used as id for the complete trace session.

Specified by:
getRootStep in interface ITraceSession
Returns:
root step (null: no trace data has been collected for this session)

getDuration

public long getDuration()
Returns the execution time of the complete trace session.

Normally for each service call a separate trace session exist. So the returned duration is the overall execution time of the service call.

Specified by:
getDuration in interface ITraceSession
Returns:
execution time of the trace session

setConfig

public void setConfig(ITraceConfig tc)
Assigns a new trace configuratio to the trace session.

Specified by:
setConfig in interface ITraceSession
Parameters:
tc - trace configuration

getConfig

public ITraceConfig getConfig()
Returns the trace configuration of the session.

Specified by:
getConfig in interface ITraceSession
Returns:
trace configuration

getCurrentStep

public ITraceStep getCurrentStep()
Returns the active trace step.

The active trace step is determined by the last call to enterStep. If enterStep has not been called yet, the method returns the root step of the trace session (see getRootStep).

Specified by:
getCurrentStep in interface ITraceSession
Returns:
active trace step (null: no trace data is collected for this session)


Copyright © 2013 Gunther Popp. All Rights Reserved.