com.mtgi.analytics
Class BehaviorTrackingManagerImpl

java.lang.Object
  extended by com.mtgi.analytics.BehaviorTrackingManagerImpl
All Implemented Interfaces:
BehaviorTrackingManager, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.InitializingBean

@ManagedResource(objectName="com.mtgi:group=analytics,name=BehaviorTracking",
                 description="Monitor and control user behavior tracking")
public class BehaviorTrackingManagerImpl
extends Object
implements BehaviorTrackingManager, org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.BeanNameAware

Standard implementation of BehaviorTrackingManager. BehaviorEvent instances are asynchronously committed to a BehaviorEventPersister when they are complete; user and session IDs for the events are provided by an implementation of SessionContext.

Event persistence occurs when flush() is called (either via JMX control or by the Quartz scheduler), or when the queue of uncommitted events exceeds the configured threshold value. The flush threshold can be configured with setFlushThreshold(int).


Nested Class Summary
protected  class BehaviorTrackingManagerImpl.FlushEvent
           
 
Constructor Summary
BehaviorTrackingManagerImpl()
           
 
Method Summary
 void afterPropertiesSet()
           
 BehaviorEvent createEvent(String type, String name)
          Create a new event of the given type and name.
 int flush()
          Flush any completed events to the event persister.
 String getApplication()
           
 String getBeanName()
           
 int getEventsPendingFlush()
           
 org.springframework.core.task.TaskExecutor getExecutor()
           
 BehaviorEventPersister getPersister()
           
 SessionContext getSessionContext()
           
 boolean isSuspended()
           
 String resume()
           
 void setApplication(String application)
          Set the name of the application in which this manager operates, for logging purposes.
 void setBeanName(String name)
           
 void setExecutor(org.springframework.core.task.TaskExecutor executor)
          Provide a task executor on which persistence operations will be performed.
 void setFlushThreshold(int flushThreshold)
          Specify the maximum number of completed events to queue in memory before forcing a flush to the persister.
 void setPersister(BehaviorEventPersister persister)
          Provide a persister for saving finished events to the behavior tracking database.
 void setSessionContext(SessionContext sessionContext)
          Set a session context for the application, used to determine the current user and session ID for a calling thread.
 void start(BehaviorEvent evt)
          Set the given event as the currently executing event for this thread, and start measuring event time.
 void stop(BehaviorEvent evt)
          Stop measuring execution time for the given event, and set the current event for this thread to be the parent of the given event, if any.
 String suspend()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BehaviorTrackingManagerImpl

public BehaviorTrackingManagerImpl()
Method Detail

setBeanName

public void setBeanName(String name)
Specified by:
setBeanName in interface org.springframework.beans.factory.BeanNameAware

getBeanName

public String getBeanName()

createEvent

public BehaviorEvent createEvent(String type,
                                 String name)
Description copied from interface: BehaviorTrackingManager
Create a new event of the given type and name. If another event is still pending on the current thread, the pending event will become the parent of the newly created event. The returned event will also reflect the user Id and session Id associated with the current thread, if any. The returned event does not become active until BehaviorTrackingManager.start(BehaviorEvent) is called, which should be done after all event metadata has been gathered.

Specified by:
createEvent in interface BehaviorTrackingManager
See Also:
SessionContext, BehaviorTrackingManager.start(BehaviorEvent)

start

public void start(BehaviorEvent evt)
Description copied from interface: BehaviorTrackingManager
Set the given event as the currently executing event for this thread, and start measuring event time.

Specified by:
start in interface BehaviorTrackingManager

stop

public void stop(BehaviorEvent evt)
Description copied from interface: BehaviorTrackingManager
Stop measuring execution time for the given event, and set the current event for this thread to be the parent of the given event, if any. The event data will subsequently be logged to the behavior tracking database.

Specified by:
stop in interface BehaviorTrackingManager

isSuspended

@ManagedAttribute(description="Returns true if event logging has been temporarily disabled with the suspend() operation.")
public boolean isSuspended()

suspend

@ManagedOperation(description="Temporarily suspend logging of behavior events.")
public String suspend()

resume

@ManagedOperation(description="Resume logging of behavior events after a previous call to suspend().")
public String resume()

flush

@ManagedOperation(description="Immediately flush all completed events to the behavior tracking database.  Returns the number of events written to the database (not counting the flush event that is also logged)")
public int flush()
Flush any completed events to the event persister. This operation can be called manually via JMX, or can be called on a fixed interval via the Quartz Scheduler. This operation results in the logging of a "flush" event to the database.

Returns:
the number of events persisted

getApplication

@ManagedAttribute(description="The application name for events published by this manager")
public String getApplication()

getEventsPendingFlush

@ManagedAttribute(description="The number of completed events not yet flushed")
public int getEventsPendingFlush()

setApplication

public void setApplication(String application)
Set the name of the application in which this manager operates, for logging purposes. This will be the value of BehaviorEvent.getApplication() for all events created by this manager.


setSessionContext

public void setSessionContext(SessionContext sessionContext)
Set a session context for the application, used to determine the current user and session ID for a calling thread.


getSessionContext

public SessionContext getSessionContext()

setPersister

public void setPersister(BehaviorEventPersister persister)
Provide a persister for saving finished events to the behavior tracking database.

Parameters:
persister -

getPersister

public BehaviorEventPersister getPersister()

setExecutor

public void setExecutor(org.springframework.core.task.TaskExecutor executor)
Provide a task executor on which persistence operations will be performed.


getExecutor

public org.springframework.core.task.TaskExecutor getExecutor()

setFlushThreshold

public void setFlushThreshold(int flushThreshold)
Specify the maximum number of completed events to queue in memory before forcing a flush to the persister. Default is 100 if unspecified. Note that this value is treated as advice and not strictly obeyed. For example, additional events may accumulate during the time it takes to rotate the event buffer after the flush threshold is first observed crossed. In other words, persister implementations must not assume that the flush threshold is a hard upper limit on the batch size of persistence operations.


afterPropertiesSet

public void afterPropertiesSet()
                        throws Exception
Specified by:
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
Throws:
Exception