You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sirona.apache.org by rm...@apache.org on 2014/04/06 14:04:13 UTC

svn commit: r1585294 - in /incubator/sirona/trunk/server/reporting: pom.xml src/main/java/org/apache/sirona/reporting/web/template/Templates.java src/main/resources/templates/pathtracking/home.vm

Author: rmannibucau
Date: Sun Apr  6 12:04:12 2014
New Revision: 1585294

URL: http://svn.apache.org/r1585294
Log:
getting rid of velocity-tools

Modified:
    incubator/sirona/trunk/server/reporting/pom.xml
    incubator/sirona/trunk/server/reporting/src/main/java/org/apache/sirona/reporting/web/template/Templates.java
    incubator/sirona/trunk/server/reporting/src/main/resources/templates/pathtracking/home.vm

Modified: incubator/sirona/trunk/server/reporting/pom.xml
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/server/reporting/pom.xml?rev=1585294&r1=1585293&r2=1585294&view=diff
==============================================================================
--- incubator/sirona/trunk/server/reporting/pom.xml (original)
+++ incubator/sirona/trunk/server/reporting/pom.xml Sun Apr  6 12:04:12 2014
@@ -69,17 +69,6 @@
       <artifactId>velocity</artifactId>
       <version>1.7</version>
     </dependency>
-    <dependency>
-      <groupId>org.apache.velocity</groupId>
-      <artifactId>velocity-tools</artifactId>
-      <version>2.0</version>
-      <exclusions>
-        <exclusion>
-          <groupId>javax.servlet</groupId>
-          <artifactId>servlet-api</artifactId>
-        </exclusion>
-      </exclusions>
-    </dependency>
 
     <dependency>
       <groupId>junit</groupId>

Modified: incubator/sirona/trunk/server/reporting/src/main/java/org/apache/sirona/reporting/web/template/Templates.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/server/reporting/src/main/java/org/apache/sirona/reporting/web/template/Templates.java?rev=1585294&r1=1585293&r2=1585294&view=diff
==============================================================================
--- incubator/sirona/trunk/server/reporting/src/main/java/org/apache/sirona/reporting/web/template/Templates.java (original)
+++ incubator/sirona/trunk/server/reporting/src/main/java/org/apache/sirona/reporting/web/template/Templates.java Sun Apr  6 12:04:12 2014
@@ -24,11 +24,16 @@ import org.apache.velocity.app.VelocityE
 import org.apache.velocity.runtime.RuntimeConstants;
 import org.apache.velocity.runtime.log.JdkLogChute;
 import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader;
-import org.apache.velocity.tools.generic.DateTool;
 
 import java.io.PrintWriter;
+import java.text.SimpleDateFormat;
+import java.util.Date;
 import java.util.Map;
 import java.util.Properties;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.LinkedBlockingDeque;
 
 public final class Templates
 {
@@ -105,7 +110,7 @@ public final class Templates
         {
             context = new VelocityContext( variables );
         }
-        context.put( "dateTool", new DateTool() );
+        context.put( "dateTool", DateTool.INSTANCE );
         return context;
     }
 
@@ -114,6 +119,50 @@ public final class Templates
         return engine.getProperty( key );
     }
 
+    // velocity tool brings so much dependencies we really don't want
+    // and implementation is so simple we can just do it here
+    public static class DateTool {
+        public static final DateTool INSTANCE = new DateTool();
+
+        private static final int POOL_SIZE = Configuration.getInteger(Configuration.CONFIG_PROPERTY_PREFIX + "dateformat.pool.size", 10);
+
+        private final ConcurrentMap<String, BlockingQueue<SimpleDateFormat>> formats = new ConcurrentHashMap<String, BlockingQueue<SimpleDateFormat>>();
+
+        public String format(final String format, final Date date) {
+            BlockingQueue<SimpleDateFormat> dateFormats = formats.get(format);
+            if (dateFormats == null) {
+                dateFormats = new LinkedBlockingDeque<SimpleDateFormat>(POOL_SIZE);
+                final BlockingQueue<SimpleDateFormat> existing = formats.putIfAbsent(format, dateFormats);
+                if (existing != null) {
+                    dateFormats = existing;
+                } else { // init pool
+                    for (int i = 0; i < POOL_SIZE; i++) {
+                        dateFormats.offer(new SimpleDateFormat(format));
+                    }
+                }
+            }
+
+            final SimpleDateFormat take;
+            try {
+                take = dateFormats.take();
+            } catch (final InterruptedException e) {
+                // at this point the JVM should be in a state we can't do anything to help but
+                // just try to return a new instance, we don't care about perf anymore here
+                return new SimpleDateFormat(format).format(date);
+            }
+
+            try {
+                return take.format(date);
+            } finally {
+                dateFormats.add(take);
+            }
+        }
+
+        private DateTool() {
+            // no-op
+        }
+    }
+
     private Templates()
     {
         // no-op

Modified: incubator/sirona/trunk/server/reporting/src/main/resources/templates/pathtracking/home.vm
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/server/reporting/src/main/resources/templates/pathtracking/home.vm?rev=1585294&r1=1585293&r2=1585294&view=diff
==============================================================================
--- incubator/sirona/trunk/server/reporting/src/main/resources/templates/pathtracking/home.vm (original)
+++ incubator/sirona/trunk/server/reporting/src/main/resources/templates/pathtracking/home.vm Sun Apr  6 12:04:12 2014
@@ -19,7 +19,7 @@
         <div class="col-lg-9">
             <ul>
             #foreach( $pathCallInformation in $pathCallInformations )
-                <li><a href="$mapping/pathtracking/pathtrackingdetail/$pathCallInformation.trackingId">$pathCallInformation.trackingId:  $dateTool.format("yyyy-MM-dd'T'HH:mm:ssz", $pathCallInformation.startTime.time)</a></li>
+                <li><a href="$mapping/pathtracking/pathtrackingdetail/$pathCallInformation.trackingId">$pathCallInformation.trackingId:  $dateTool.format("yyyy-MM-dd'T'HH:mm:ssz", $pathCallInformation.startTime)</a></li>
             #end
             </ul>
         </div>