org.e2etrace.trace
Class ThreadedTraceSessionManager

java.lang.Object
  extended by org.e2etrace.trace.AbstractTraceSessionManager
      extended by org.e2etrace.trace.ThreadedTraceSessionManager
All Implemented Interfaces:
ITraceSessionManager

public class ThreadedTraceSessionManager
extends AbstractTraceSessionManager

Thread-Aware implementation of a trace session manager.

This session manager is targeted for a multi-threaded environment (e.g. application servers). It maintains a ITraceSession for every running thread.

Note: The implementation uses a synchronized WeakHashMap to cache the sessions (using the threads as keys). Hence, as soon as a thread terminates, the GC will remove the respective cache entry automatically. This design works for multi-threaded applications and for application servers using thread pools. An alternative design would have been to use ThreadLocal instead. However, there are discussions going on that ThreadLocal may cause memory leaks on application servers if applications are hot-deployed (just google for threadlocal+leak). Personally, I would prefer ThreadLocal instead of the custom cache that is currently implemented, because the ThreadLocal approache doesn´t require a synchronized map that stores the trace sessions. I´ll monitor the memory-leak discussion and decide later, if a re-design is appropriate.

This class implements the singleton pattern.

Author:
Gunther Popp

Method Summary
protected  void assignCurrentSession(ITraceSession session)
          CALL-BACK: Forward a newly assigned current trace session to sub-classes.
static ThreadedTraceSessionManager getInstance()
          Returns the singleton instance of the session manager.
 void releaseCurrentSession()
          Release current session.
protected  ITraceSession requestCurrentSession()
          CALL-BACK: Request the current trace session from sub-classes.
 
Methods inherited from class org.e2etrace.trace.AbstractTraceSessionManager
getConfig, getCurrentSession, setConfig, setCurrentSession
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static ThreadedTraceSessionManager getInstance()
Returns the singleton instance of the session manager.

Returns:
trace session manager

requestCurrentSession

protected ITraceSession requestCurrentSession()
CALL-BACK: Request the current trace session from sub-classes.

This call-back is triggered for every invokation of getCurrentSession.

Specified by:
requestCurrentSession in class AbstractTraceSessionManager
Returns:
current (active) trace session

assignCurrentSession

protected void assignCurrentSession(ITraceSession session)
CALL-BACK: Forward a newly assigned current trace session to sub-classes.

This call-back is triggered for every invokation of setCurrentSession.

Specified by:
assignCurrentSession in class AbstractTraceSessionManager
Parameters:
session - new current (active) trace session

releaseCurrentSession

public void releaseCurrentSession()
Release current session.

This call releases the reference to the current trace session. It should be called in when all trace data for the current trace session has been collected and the session is no longer needed.



Copyright © 2013 Gunther Popp. All Rights Reserved.