velocity-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From by...@apache.org
Subject svn commit: r737363 - in /velocity/engine/trunk: experimental/benchmark/Benchmark.java src/changes/changes.xml src/java/org/apache/velocity/app/VelocityEngine.java src/java/org/apache/velocity/runtime/RuntimeInstance.java
Date Sat, 24 Jan 2009 14:26:23 GMT
Author: byron
Date: Sat Jan 24 14:26:23 2009
New Revision: 737363

URL: http://svn.apache.org/viewvc?rev=737363&view=rev
Log:
VELOCITY-673 Remove runtime initialization from non default VelocityEngine constructors

Modified:
    velocity/engine/trunk/experimental/benchmark/Benchmark.java
    velocity/engine/trunk/src/changes/changes.xml
    velocity/engine/trunk/src/java/org/apache/velocity/app/VelocityEngine.java
    velocity/engine/trunk/src/java/org/apache/velocity/runtime/RuntimeInstance.java

Modified: velocity/engine/trunk/experimental/benchmark/Benchmark.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/experimental/benchmark/Benchmark.java?rev=737363&r1=737362&r2=737363&view=diff
==============================================================================
--- velocity/engine/trunk/experimental/benchmark/Benchmark.java (original)
+++ velocity/engine/trunk/experimental/benchmark/Benchmark.java Sat Jan 24 14:26:23 2009
@@ -33,7 +33,7 @@
 
 public class Benchmark
 {
-  int threadCnt = 10;
+  int threadCnt = 2;
   int runCnt = 500;
   
   public static final void main(String[] argv) throws Exception
@@ -52,13 +52,10 @@
     
     Properties props = new Properties();
     props.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_CACHE, "true");
-    props.setProperty(RuntimeConstants.VM_LIBRARY, "vmlib1.vm,vmlib2.vm");
     props.setProperty(RuntimeConstants.RESOURCE_MANAGER_DEFAULTCACHE_SIZE, "20");
     props.setProperty(RuntimeConstants.RUNTIME_REFERENCES_STRICT, "true");
     VelocityEngine vengine = new VelocityEngine(props);
-    vengine.init();
-    System.out.println("blaa:  " + vengine.getProperty(RuntimeConstants.RUNTIME_REFERENCES_STRICT));
-
+    vengine.setProperty(RuntimeConstants.VM_LIBRARY, "vmlib1.vm,vmlib2.vm");
     log("Starting " + threadCnt + " threads which will run " + runCnt + " times");
     ArrayList list = new ArrayList(threadCnt);    
     for (int i = 0; i < threadCnt; i++)

Modified: velocity/engine/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/changes/changes.xml?rev=737363&r1=737362&r2=737363&view=diff
==============================================================================
--- velocity/engine/trunk/src/changes/changes.xml (original)
+++ velocity/engine/trunk/src/changes/changes.xml Sat Jan 24 14:26:23 2009
@@ -26,6 +26,12 @@
 
   <body>
     <release version="1.7" date="In Subversion">
+
+      <action type="add" dev="byron"  issue="VELOCITY-673">
+	The non default VelocityEngine construtors now do not initialize the runtime
+	system so that properties may be set after constrution.  Also fixes an
+	Initialization race condition.
+      </action>
       
       <action type="fix" dev="nbubna" issue="VELOCITY-685" due-to="Jarkko Viinamäki">
         Make velocimacro.arguments.strict=true work with block macros.

Modified: velocity/engine/trunk/src/java/org/apache/velocity/app/VelocityEngine.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/app/VelocityEngine.java?rev=737363&r1=737362&r2=737363&view=diff
==============================================================================
--- velocity/engine/trunk/src/java/org/apache/velocity/app/VelocityEngine.java (original)
+++ velocity/engine/trunk/src/java/org/apache/velocity/app/VelocityEngine.java Sat Jan 24
14:26:23 2009
@@ -59,7 +59,6 @@
 {
     private RuntimeInstance ri = new RuntimeInstance();
 
-
     /**
      *  Init-less CTOR
      */
@@ -69,27 +68,20 @@
     }
 
     /**
-     *  CTOR that invokes an init(String), initializing
-     *  the engine using the properties file specified
-     *
-     * @param propsFilename name of properties file to init with
-     * @since 1.5
+     * Construct a VelocityEngine with the initial properties defined in the file
+     * propsFilename
      */
     public VelocityEngine(String propsFilename)
     {
-        ri.init(propsFilename);
+        ri.setProperties(propsFilename);
     }
 
     /**
-     *  CTOR that invokes an init(String), initializing
-     *  the engine using the Properties specified
-     *
-     * @param p name of properties  to init with
-     * @since 1.5
+     * Construct a VelocityEngine instance with the specified initial properties.
      */
     public VelocityEngine(Properties p)
     {
-        ri.init(p);
+        ri.setProperties(p);
     }
 
     /**

Modified: velocity/engine/trunk/src/java/org/apache/velocity/runtime/RuntimeInstance.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/runtime/RuntimeInstance.java?rev=737363&r1=737362&r2=737363&view=diff
==============================================================================
--- velocity/engine/trunk/src/java/org/apache/velocity/runtime/RuntimeInstance.java (original)
+++ velocity/engine/trunk/src/java/org/apache/velocity/runtime/RuntimeInstance.java Sat Jan
24 14:26:23 2009
@@ -142,7 +142,7 @@
     /**
      * Indicate whether the Runtime has been fully initialized.
      */
-    private boolean initialized = false;
+    private volatile boolean initialized = false;
 
     /**
      * These are the properties that are laid down over top
@@ -240,6 +240,7 @@
     {
         if (!initialized && !initializing)
         {
+            log.debug("Initializing Velocity, Calling init()...");
             initializing = true;
 
             log.trace("*******************************************************************");
@@ -282,9 +283,8 @@
      */
     private void requireInitialization()
     {
-        if (!initialized && !initializing)
+        if (!initialized)
         {
-            log.debug("Velocity was not initialized! Calling init()...");
             try
             {
                 init();
@@ -451,8 +451,47 @@
 
         overridingProperties.setProperty(key, value);
     }
+    
+
+    /**
+     * Add all properties contained in the file fileName to the RuntimeInstance properties
+     */
+    public void setProperties(String fileName)
+    {
+        ExtendedProperties props = null;
+        try
+        {
+              props = new ExtendedProperties(fileName);
+        } 
+        catch (IOException e)
+        {
+              throw new VelocityException("Error reading properties from '" 
+                + fileName + "'", e);
+        }
+        
+        Enumeration en = props.keys();
+        while (en.hasMoreElements())
+        {
+            String key = en.nextElement().toString();
+            setProperty(key, props.get(key));
+        }
+    }
+    
 
     /**
+     * Add all the properties in props to the RuntimeInstance properties
+     */
+    public void setProperties(Properties props)
+    {
+        Enumeration en = props.keys();
+        while (en.hasMoreElements())
+        {
+            String key = en.nextElement().toString();
+            setProperty(key, props.get(key));
+        }
+    }
+        
+    /**
      * Allow an external system to set an ExtendedProperties
      * object to use. This is useful where the external
      * system also uses the ExtendedProperties class and
@@ -536,7 +575,7 @@
         /**
          * Before initialization, check the user-entered properties first.
          */
-        if (!initialized && !initializing && overridingProperties != null)

+        if (!initialized && overridingProperties != null) 
         {
             o = overridingProperties.get(key);
         }
@@ -632,8 +671,7 @@
     {
         /*
          * Which resource manager?
-         */
-
+         */      
         String rm = getString(RuntimeConstants.RESOURCE_MANAGER_CLASS);
 
         if (rm != null && rm.length() > 0)



Mime
View raw message