Chapter 3. Configuration Reference

Table of Contents

Configuration Examples
The Behavior Tracking Servlet Filter
XML Schema Documentation for http://www.mantis-tgi.com/schema/bt/1.1
<bt:config>
<bt:manager>
<bt:advice>
<bt:xml-persister>
<bt:jdbc-persister>
<bt:custom-persister>
<bt:session-context>
Attribute bt:tracking-manager

Most configuration is accomplished by importing the custom config namespace into your Spring bean definition file, and then using it to define the appropriate elements. You can find probably find an example in the section called “Configuration Examples” and then customize it to suit your needs using the schema reference in the section called “XML Schema Documentation for http://www.mantis-tgi.com/schema/bt/1.1”.

Unless otherwise specified, all schema elements support the "id" attribute for injection into other Spring beans, in addition to those listed here.

Configuration Examples

The simplest example in Chapter 1, Quick Start should suit most applications. Here are some common (and less common) customizations:

Example 3.1. Store performance logs in the Tomcat logs directory

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:bt="http://www.mantis-tgi.com/schema/bt/1.1"
       xsi:schemaLocation="
          http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
          http://www.mantis-tgi.com/schema/bt         http://www.mantis-tgi.com/schema/bt/mtgi-bt-1.1.xsd">

   <bt:manager application="myapp">
      <bt:xml-persister file="${catalina.home}/logs/myapp-beet.xml"/>1
   </bt:manager>
1

Tomcat defines the catalina.home system property, which is useful for specifying server-relative paths in the configuration. The file extension listed here will be replaced at runtime with one appropriate to the log settings; for example, ".gz" is appended if log compression is enabled (which is the default).


Example 3.2. Use a custom SessionContext implementation to specify user IDs

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:bt="http://www.mantis-tgi.com/schema/bt/1.1"
       xsi:schemaLocation="
          http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
          http://www.mantis-tgi.com/schema/bt         http://www.mantis-tgi.com/schema/bt/mtgi-bt-1.1.xsd">
		
   <bt:manager application="myapp">
      <bt:session-context class="com.me.MySessionContextImpl1"/>
   </bt:manager>
1

This class must implement com.mtgi.analytics.SessionContext. The <bt:session-context> element is otherwise a normal Spring bean definition, and may include nested property elements and so on.


Example 3.3. Send tracking data for different packages to different log files

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:bt="http://www.mantis-tgi.com/schema/bt/1.1"
       xsi:schemaLocation="
          http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
          http://www.mantis-tgi.com/schema/bt         http://www.mantis-tgi.com/schema/bt/mtgi-bt-1.1.xsd">
		
   <bt:config>
      <bt:manager id="loggerA1" application="myapp"
                  track-method-expression="execution(* com.mtgi.package_a..*Tracked(..))">
         <bt:xml-persister file="log-a.xml"/>
      </bt:manager>
      <bt:manager id="loggerB" application="myapp"
                  track-method-expression="execution(* com.mtgi.package_b..*Tracked(..))">
         <bt:xml-persister file="log-b.xml"/>2
      </bt:manager>
   </bt:config>
1

When specifying multiple <bt:manager> instances in a single application, you must provide unique IDs for each.

2

An important consequence of having multiple managers in a single application is that each will define a private thread pool for persistence operations. If you want to have them all share a thread pool (which is not a bad idea), use the <bt:manager> attribute "task-executor".


Example 3.4. Integrate beet with other AOP advice

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:bt="http://www.mantis-tgi.com/schema/bt/1.1"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xsi:schemaLocation="
          http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
          http://www.springframework.org/schema/tx    http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
          http://www.mantis-tgi.com/schema/bt         http://www.mantis-tgi.com/schema/bt/mtgi-bt-1.1.xsd
          http://www.springframework.org/schema/aop   http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
		
   <bt:manager/>1
        
   <bt:advice id="btAdvice"/>2
   <tx:advice id="txAdvice"/>
                
   <aop:config>
      <aop:pointcut id="trackedOperations" expression="execution(* com.mtgi..*Service(..))" />
      <aop:advisor id="behaviorTrackingAdvisor" advice-ref="btAdvice" pointcut-ref="trackedOperations" order="1"/>
      <aop:advisor id="transactionAdvisor" advice-ref="txAdvice" pointcut-ref="trackedOperations" order="2"/>3
   </aop:config>
1

We have intentionally not specified a pointcut expression here, since we're going to be including that with the rest of our AOP config below.

2

If you want to associate behavior tracking advice with a manager other than the default instance, you can use the "tracking-manager" attribute to do so.

3

By specifying a lower order for the behavior tracking advice, we've ensured that behavior tracking metrics include time spent on transaction synchronization.


Example 3.5. Register MBeans on a JVM with multiple Beet applications

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:bt="http://www.mantis-tgi.com/schema/bt/1.1"
       xsi:schemaLocation="
          http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
          http://www.mantis-tgi.com/schema/bt         http://www.mantis-tgi.com/schema/bt/mtgi-bt-1.1.xsd">
		
   <bt:manager application="myapp"/>
		
   <!-- 
     setup automatic export of annotated MBeans to the platform mbean server.  
     Except where called out, most of this is boilerplate Spring/JMX configuration.
   -->
   <bean id="jmxAttributeSource" class="org.springframework.jmx.export.annotation.AnnotationJmxAttributeSource"/>
   <bean id="jmxExporter" class="org.springframework.jmx.export.MBeanExporter">
      <property name="assembler">
         <bean class="org.springframework.jmx.export.assembler.MetadataMBeanInfoAssembler">
            <property name="attributeSource" ref="jmxAttributeSource"/>
         </bean>
      </property>
      <property name="namingStrategy">
         <bean class="com.mtgi.jmx.export.naming.ApplicationNamingStrategy">1
            <property name="application" value="myapp"/>
            <property name="delegate">
               <bean class="org.springframework.jmx.export.naming.MetadataNamingStrategy">
                  <property name="attributeSource" ref="jmxAttributeSource"/>
               </bean>
            </property>
         </bean>
      </property>
      <property name="autodetect" value="true"/>
   </bean>
1

Here we add a naming strategy which puts all detected MBeans in a group called "myapp", see the ApplicationNamingStrategy JavaDoc. The "delegate" property can be any other valid naming strategy supported by Spring, which defines how the rest of the MBean names are constructed. You can choose different names for each application to keep them in separate branches of the JVM's platform MBean tree.