Commits

musachy  committed df6d78c

WW-3202 enable UtilTimerStack from system property in a static block

git-svn-id: http://svn.opensymphony.com/svn/xwork/trunk@2023e221344d-f017-0410-9bd5-d282ab1896d7

  • Participants
  • Parent commits eff3d9e

Comments (0)

Files changed (2)

File core/src/main/java/com/opensymphony/xwork2/util/profiling/UtilTimerStack.java

  * <!-- START SNIPPET: activationThroughCode -->
  *   
  *  UtilTimerStack.setActivate(true);
- *  
- *  // or 
- *  
- *  System.setProperty("xwork.profile.activate", "true");
- *   
- *  // or
- *  
- *  System.setProperty(UtilTimerStack.ACTIVATE_PROPERTY, "true");
- *  
+ *    
  * <!-- END SNIPPET: activationThroughCode --> 
  * </pre>
  * 
     private static final Logger LOG = LoggerFactory.getLogger(UtilTimerStack.class);
 
     /**
+     * Initialized in a static block, it can be changed at runtime by calling setActive(...)
+     */
+    private static boolean active;
+
+    static {
+        active = "true".equalsIgnoreCase(System.getProperty(ACTIVATE_PROPERTY));
+    }
+
+    /**
      * Create and start a performance profiling with the <code>name</code> given. Deal with 
      * profile hierarchy automatically, so caller don't have to be concern about it.
      * 
      */
     public static boolean isActive()
     {
-        return System.getProperty(ACTIVATE_PROPERTY) != null;
+        return active;
     }
 
     /**
             System.setProperty(ACTIVATE_PROPERTY, "true");
         else
         	System.clearProperty(ACTIVATE_PROPERTY);
+
+        UtilTimerStack.active = active; 
     }
 
 

File core/src/test/java/com/opensymphony/xwork2/util/profiling/UtilTimerStackTest.java

         minTimeProp = System.getProperty(UtilTimerStack.MIN_TIME);
 
         System.setProperty(UtilTimerStack.ACTIVATE_PROPERTY, "true");
+        UtilTimerStack.setActive(true);
         System.setProperty(UtilTimerStack.MIN_TIME, "0");
     }