com.mtgi.analytics
Class XmlBehaviorEventPersisterImpl

java.lang.Object
  extended by com.mtgi.analytics.XmlBehaviorEventPersisterImpl
All Implemented Interfaces:
BehaviorEventPersister, org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.InitializingBean

@ManagedResource(objectName="com.mtgi:group=analytics,name=BehaviorTrackingLog",
                 description="Perform maintenance on BehaviorTracking XML logfiles")
public class XmlBehaviorEventPersisterImpl
extends Object
implements BehaviorEventPersister, org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.DisposableBean

Behavior Tracking persister which writes events to an XML log file, either as plain text or FastInfoset binary XML. Which format is selected by setBinary(boolean). Log rotation can be accomplished by rotateLog().


Nested Class Summary
protected static class XmlBehaviorEventPersisterImpl.FileOrder
           
 
Constructor Summary
XmlBehaviorEventPersisterImpl()
           
 
Method Summary
 void afterPropertiesSet()
           
 void destroy()
           
 RelocatableFile downloadLogFile(String name)
           
 String getFile()
           
 long getFileSize()
           
 File getLogFile(File file)
          get the active log file, modifying the supplied base name to reflect compressed / binary options.
 boolean isBinary()
           
 boolean isCompress()
           
 StringBuffer listLogFiles()
          JMX operation to list archived xml data files available for download.
 int persist(Queue<BehaviorEvent> events)
          Drain the given event queue, persisting all instances to the database.
 String rotateLog()
          Force a rotation of the log.
 void setBinary(boolean binary)
          Set to true to log in FastInfoset binary XML format.
 void setCompress(boolean compress)
          Set to true to log in ZLIB compressed format.
 void setDateFormat(String dateFormat)
          override the default log name date format
 void setFile(String path)
          set the destination log file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XmlBehaviorEventPersisterImpl

public XmlBehaviorEventPersisterImpl()
Method Detail

setBinary

@ManagedAttribute(description="Can be used to switch between binary and text XML.  Changes take affect after the next log rotation.")
public void setBinary(boolean binary)
Set to true to log in FastInfoset binary XML format. Defaults to false.


isBinary

@ManagedAttribute(description="Can be used to switch between binary and text XML.  Changes take affect after the next log rotation.")
public boolean isBinary()

isCompress

@ManagedAttribute(description="Can be used to turn on/off log file compression.  Changes take affect after the next log rotation.")
public boolean isCompress()

setCompress

@ManagedAttribute(description="Can be used to turn on/off log file compression.  Changes take affect after the next log rotation.")
public void setCompress(boolean compress)
Set to true to log in ZLIB compressed format. Changes take affect after the next log rotation. Defaults to false.


setDateFormat

public void setDateFormat(String dateFormat)
override the default log name date format


listLogFiles

@ManagedOperation(description="List all archived performance data log files available for download")
public StringBuffer listLogFiles()
JMX operation to list archived xml data files available for download.


downloadLogFile

@ManagedOperation(description="directly access a performance log file by name; use listLogFiles to determine valid file names")
public RelocatableFile downloadLogFile(String name)
                                throws IOException
Throws:
IOException

setFile

public void setFile(String path)
set the destination log file. The file extension will be modified based on compression / binary settings.


getFile

public String getFile()

afterPropertiesSet

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

destroy

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

getFileSize

@ManagedAttribute(description="Report the current size of the XML log, in bytes")
public long getFileSize()

persist

public int persist(Queue<BehaviorEvent> events)
Description copied from interface: BehaviorEventPersister
Drain the given event queue, persisting all instances to the database. Persisters must support the persisting of child events before their parents, since this is generally the natural order in which events are completed. This method returns when the queue is empty.

Specified by:
persist in interface BehaviorEventPersister
Returns:
the number of persisted events

rotateLog

@ManagedOperation(description="Force a rotation of the behavior tracking log")
public String rotateLog()
                 throws IOException,
                        javax.xml.stream.XMLStreamException
Force a rotation of the log. The new archive log will be named [logfile].yyyyMMddHHmmss. If a file of that name already exists, an extra _N will be appended to it, where N is an integer sufficiently large to make the name unique. This method can be called externally by the Quartz scheduler for periodic rotation, or by an administrator via JMX.

Throws:
IOException
javax.xml.stream.XMLStreamException

getLogFile

public File getLogFile(File file)
get the active log file, modifying the supplied base name to reflect compressed / binary options.