tal on-error fix
authorzapata <zapata>
Sun, 18 Jan 2004 01:55:17 +0000 (01:55 +0000)
committerzapata <zapata>
Sun, 18 Jan 2004 01:55:17 +0000 (01:55 +0000)
source/mir/generator/tal/template/TALBasicTemplateNodeLibrary.java
source/mircoders/global/JobQueue.java
source/mircoders/global/MRUCache.java
source/mircoders/global/MirGlobal.java

index 6ff4c58..ab64df1 100755 (executable)
@@ -233,33 +233,59 @@ public class TALBasicTemplateNodeLibrary implements TALTemplateNodeLibrary {
     }\r
 \r
     public void process(TALExpressionParser aParser, Object aContext, StringBuffer aDestination, TALLogger aLogger) throws TemplateProcessingException {\r
     }\r
 \r
     public void process(TALExpressionParser aParser, Object aContext, StringBuffer aDestination, TALLogger aLogger) throws TemplateProcessingException {\r
+      if (errorExpression != null) {\r
+        StringBuffer destination = new StringBuffer();\r
+        try {\r
+          outerProcess(aParser, aContext, aDestination, aLogger);\r
+        }\r
+        catch (Throwable t) {\r
+          try {\r
+            destination.delete(0, destination.length());\r
+            aParser.processPseudoAssignment(aContext, "exception", t);\r
+            destination.append(aParser.evaluateStringExpression(aContext, errorExpression));\r
+          }\r
+          catch (Throwable s) {\r
+            throw new TemplateProcessingException(s);\r
+          }\r
+        }\r
+        finally {\r
+          aDestination.append(destination);\r
+        }\r
+      }\r
+      else {\r
+        outerProcess(aParser, aContext, aDestination, aLogger);\r
+      }\r
+    }\r
+\r
+    public void outerProcess(TALExpressionParser aParser, Object aContext, StringBuffer aDestination, TALLogger aLogger) throws TemplateProcessingException {\r
       Iterator i;\r
 \r
       Iterator i;\r
 \r
-        i = definitions.iterator();\r
-        while (i.hasNext()) {\r
-          Definition d = (Definition) i.next();\r
-          aParser.processAssignment(aContext, d.getVariable(), d.getExpression());\r
-        }\r
+      i = definitions.iterator();\r
+      while (i.hasNext()) {\r
+        Definition d = (Definition) i.next();\r
+        aParser.processAssignment(aContext, d.getVariable(), d.getExpression());\r
+      }\r
 \r
 \r
-        if (condition == null || aParser.evaluateBooleanExpression(aContext, condition)) {\r
-          if (repeatExpression != null) {\r
-            i = aParser.evaluateListExpression(aContext, repeatExpression);\r
+      if (condition == null || aParser.evaluateBooleanExpression(aContext, condition)) {\r
+        if (repeatExpression != null) {\r
+          i = aParser.evaluateListExpression(aContext, repeatExpression);\r
 \r
 \r
-            while (i.hasNext()) {\r
-              aParser.processDirectAssignment(aContext, repeatVariable, i.next());\r
-              innerProcess(aParser, aContext, aDestination, aLogger);\r
-            }\r
-          }\r
-          else {\r
+          while (i.hasNext()) {\r
+            aParser.processDirectAssignment(aContext, repeatVariable, i.next());\r
             innerProcess(aParser, aContext, aDestination, aLogger);\r
           }\r
         }\r
             innerProcess(aParser, aContext, aDestination, aLogger);\r
           }\r
         }\r
+        else {\r
+          innerProcess(aParser, aContext, aDestination, aLogger);\r
+        }\r
+      }\r
     };\r
 \r
     private void innerProcess(TALExpressionParser aParser, Object aContext, StringBuffer aDestination, TALLogger aLogger)\r
     };\r
 \r
     private void innerProcess(TALExpressionParser aParser, Object aContext, StringBuffer aDestination, TALLogger aLogger)\r
-       throws TemplateProcessingException\r
-    {\r
+        throws TemplateProcessingException {\r
+\r
       boolean omitTag = false;\r
       boolean omitTag = false;\r
+\r
       if (omitTagExpression != null)\r
         omitTag = aParser.evaluateBooleanExpression(aContext, omitTagExpression);\r
 \r
       if (omitTagExpression != null)\r
         omitTag = aParser.evaluateBooleanExpression(aContext, omitTagExpression);\r
 \r
@@ -289,39 +315,12 @@ public class TALBasicTemplateNodeLibrary implements TALTemplateNodeLibrary {
         aDestination.append(">");\r
       }\r
 \r
         aDestination.append(">");\r
       }\r
 \r
-      StringBuffer destination = aDestination;\r
-      if (errorExpression != null) {\r
-        destination = new StringBuffer();\r
-      }\r
-      try {\r
-        if (contentExpression != null) {\r
-          destination.append(aParser.evaluateStringExpression(aContext, contentExpression));\r
-        }\r
-        else {\r
-          if (body != null)\r
-            body.process(aParser, aContext, destination, aLogger);\r
-        }\r
+      if (contentExpression != null) {\r
+        aDestination.append(aParser.evaluateStringExpression(aContext, contentExpression));\r
       }\r
       }\r
-      catch (Throwable t) {\r
-        if (!(t instanceof TemplateProcessingException))\r
-          aLogger.error("TALTemplate.TALBasicTemplateNode.processs", "exception occurred: " + t.toString());\r
-        if (errorExpression != null) {\r
-          try {\r
-            destination.delete(0, destination.length());\r
-\r
-            aParser.processPseudoAssignment(aContext, "exception", t);\r
-            destination.append(aParser.evaluateStringExpression(aContext, errorExpression));\r
-          }\r
-          catch (Throwable s) {\r
-          }\r
-        }\r
-        else {\r
-          throw new TemplateProcessingException(t);\r
-        }\r
-      }\r
-      finally {\r
-        if (errorExpression != null) {\r
-          aDestination.append(destination);\r
+      else {\r
+        if (body != null) {\r
+          body.process(aParser, aContext, aDestination, aLogger);\r
         }\r
       }\r
       if (!omitTag) {\r
         }\r
       }\r
       if (!omitTag) {\r
index f6093dc..eb68a34 100755 (executable)
@@ -38,14 +38,14 @@ import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
-import java.util.Vector;
+import java.util.ArrayList;
 
 import mir.log.LoggerWrapper;
 
 // important: objects passed as data must not be altered once put into a job
 
 public class JobQueue {
 
 import mir.log.LoggerWrapper;
 
 // important: objects passed as data must not be altered once put into a job
 
 public class JobQueue {
-  private Vector jobHandlers;
+  private List jobHandlers;
   private Map identifierToJobHandler;
   private int nrJobs;
   private int jobCleanupTreshold;
   private Map identifierToJobHandler;
   private int nrJobs;
   private int jobCleanupTreshold;
@@ -69,7 +69,7 @@ public class JobQueue {
 
   public JobQueue(LoggerWrapper aLogger) {
     logger = aLogger;
 
   public JobQueue(LoggerWrapper aLogger) {
     logger = aLogger;
-    jobHandlers = new Vector();
+    jobHandlers = new ArrayList();
     identifierToJobHandler = new HashMap();
     nrJobs = 0;
     lastCleanup = 0;
     identifierToJobHandler = new HashMap();
     nrJobs = 0;
     lastCleanup = 0;
@@ -96,12 +96,14 @@ public class JobQueue {
       identifierToJobHandler.put(jobHandler.getIdentifier(), jobHandler);
       jobHandler.setPending();
 
       identifierToJobHandler.put(jobHandler.getIdentifier(), jobHandler);
       jobHandler.setPending();
 
+      jobHandlers.notify();
+
       return jobHandler.getIdentifier();
     }
   }
 
   public List getJobsInfo() {
       return jobHandler.getIdentifier();
     }
   }
 
   public List getJobsInfo() {
-    List result = new Vector();
+    List result = new ArrayList();
 
     synchronized (jobHandlers) {
       Iterator i = jobHandlers.iterator();
 
     synchronized (jobHandlers) {
       Iterator i = jobHandlers.iterator();
@@ -115,7 +117,8 @@ public class JobQueue {
   }
 
   private void cleanupJobList() {
   }
 
   private void cleanupJobList() {
-    List toRemove = new Vector();
+    List toRemove = new ArrayList();
+
     synchronized (jobHandlers) {
       Iterator i = jobHandlers.iterator();
 
     synchronized (jobHandlers) {
       Iterator i = jobHandlers.iterator();
 
@@ -139,21 +142,31 @@ public class JobQueue {
     lastCleanup = System.currentTimeMillis();
   }
 
     lastCleanup = System.currentTimeMillis();
   }
 
-  private JobHandler acquirePendingJob() {
-    synchronized (jobHandlers) {
-      int priorityFound= 0;
-      JobHandler jobFound;
+  /**
+   * Returns when a new producer job has become available
+   */
+  private JobHandler acquirePendingJob() throws InterruptedException {
+    int priorityFound= 0;
+    JobHandler jobFound;
 
 
-      jobFound = null;
-      Iterator i = jobHandlers.iterator();
-      while (i.hasNext()) {
-        JobHandler job = (JobHandler) i.next();
+    synchronized (jobHandlers) {
+      do {
+        jobFound = null;
+        Iterator i = jobHandlers.iterator();
+        while (i.hasNext()) {
+          JobHandler job = (JobHandler) i.next();
+
+          if (job.isPending() && (jobFound==null || priorityFound<job.getPriority())) {
+            jobFound = job;
+            priorityFound = job.getPriority();
+          }
+        }
 
 
-        if (job.isPending() && (jobFound==null || priorityFound<job.getPriority())) {
-          jobFound = job;
-          priorityFound = job.getPriority();
+        if (jobFound==null) {
+          jobHandlers.wait();
         }
         }
-      }
+
+      } while (jobFound==null);
 
       return jobFound;
     }
 
       return jobFound;
     }
@@ -397,19 +410,16 @@ public class JobQueue {
 
       try {
         while (true) {
 
       try {
         while (true) {
-          JobHandler job = acquirePendingJob();
-          if (job != null) {
+          try {
+            JobHandler job = acquirePendingJob();
+
             logger.debug("  starting job ("+job.getIdentifier()+"): " +job.getDescription());
             job.runJob();
             logger.debug("  finished job ("+job.getIdentifier()+"): " +job.getDescription());
             logger.debug("  starting job ("+job.getIdentifier()+"): " +job.getDescription());
             job.runJob();
             logger.debug("  finished job ("+job.getIdentifier()+"): " +job.getDescription());
+
             job=null;
           }
             job=null;
           }
-          else {
-            try {
-              Thread.sleep(1500);
-            }
-            catch (InterruptedException e) {
-            }
+          catch (InterruptedException e) {
           }
         }
       }
           }
         }
       }
index c3d2ee5..bdd6921 100755 (executable)
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
  * In addition, as a special exception, The Mir-coders gives permission to link
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
  * In addition, as a special exception, The Mir-coders gives permission to link
- * the code of this program with  any library licensed under the Apache Software License, 
- * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library 
- * (or with modified versions of the above that use the same license as the above), 
- * and distribute linked combinations including the two.  You must obey the 
- * GNU General Public License in all respects for all of the code used other than 
- * the above mentioned libraries.  If you modify this file, you may extend this 
- * exception to your version of the file, but you are not obligated to do so.  
+ * the code of this program with  any library licensed under the Apache Software License,
+ * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library
+ * (or with modified versions of the above that use the same license as the above),
+ * and distribute linked combinations including the two.  You must obey the
+ * GNU General Public License in all respects for all of the code used other than
+ * the above mentioned libraries.  If you modify this file, you may extend this
+ * exception to your version of the file, but you are not obligated to do so.
  * If you do not wish to do so, delete this exception statement from your version.
  */
 package mircoders.global;
  * If you do not wish to do so, delete this exception statement from your version.
  */
 package mircoders.global;
@@ -45,25 +45,22 @@ public class MRUCache {
 
   private MirPropertiesConfiguration configuration;
   private LoggerWrapper logger;
 
   private MirPropertiesConfiguration configuration;
   private LoggerWrapper logger;
-  
-
 
   public MRUCache() {
     logger = new LoggerWrapper("Global.MRUCache");
     try {
       configuration = MirPropertiesConfiguration.instance();
 
   public MRUCache() {
     logger = new LoggerWrapper("Global.MRUCache");
     try {
       configuration = MirPropertiesConfiguration.instance();
-       }
+    }
     catch (PropertiesConfigExc e) {
       throw new RuntimeException("Can't get configuration: " + e.getMessage());
     }
     cacheMaxItems=Integer.parseInt(configuration.getString("Global.Cache.Items"));
     cache = new HashMap();
     mruList= new LinkedList();
     catch (PropertiesConfigExc e) {
       throw new RuntimeException("Can't get configuration: " + e.getMessage());
     }
     cacheMaxItems=Integer.parseInt(configuration.getString("Global.Cache.Items"));
     cache = new HashMap();
     mruList= new LinkedList();
-    
   }
 
   /**
   }
 
   /**
-   * Checks if the cache has an object with the specified key  
+   * Checks if the cache has an object with the specified key
    */
 
   public boolean hasObject(CacheKey aCacheKey) {
    */
 
   public boolean hasObject(CacheKey aCacheKey) {
@@ -72,7 +69,7 @@ public class MRUCache {
       return cache.containsKey(aCacheKey);
     }
   }
       return cache.containsKey(aCacheKey);
     }
   }
-  
+
   /**
    * Stores an object in the cache by placing it at the top of the
    * list If the object is in the cache, it promotes it to the top of
   /**
    * Stores an object in the cache by placing it at the top of the
    * list If the object is in the cache, it promotes it to the top of
@@ -84,30 +81,30 @@ public class MRUCache {
 
   public void storeObject(CacheKey aCacheKey,Object data) {
     synchronized (cache) {
 
   public void storeObject(CacheKey aCacheKey,Object data) {
     synchronized (cache) {
-      if (! hasObject(aCacheKey)){
-       // add to the cache
-       cache.put(aCacheKey,data);
-       if (mruList.size() >= cacheMaxItems){
-         removeObject((CacheKey) mruList.getLast());
-       }
+      if (!hasObject(aCacheKey)) {
+        // add to the cache
+        cache.put(aCacheKey, data);
+        if (mruList.size() >= cacheMaxItems) {
+          removeObject((CacheKey) mruList.getLast());
+        }
       }
       mruList.remove(aCacheKey);
       mruList.addFirst(aCacheKey);
     }
       }
       mruList.remove(aCacheKey);
       mruList.addFirst(aCacheKey);
     }
-  }  
-  
-  public void removeObject(CacheKey aCacheKey){
+  }
+
+  public void removeObject(CacheKey aCacheKey) {
     synchronized (cache) {
       mruList.remove(aCacheKey);
       cache.remove(aCacheKey);
     }
   }
     synchronized (cache) {
       mruList.remove(aCacheKey);
       cache.remove(aCacheKey);
     }
   }
-  
+
   /**
    * Moves requested item to front of cache
    */
 
   /**
    * Moves requested item to front of cache
    */
 
-  public Object getObject(CacheKey aCacheKey){
+  public Object getObject(CacheKey aCacheKey) {
     synchronized (cache) {
       mruList.remove(aCacheKey);
       mruList.addFirst(aCacheKey);
     synchronized (cache) {
       mruList.remove(aCacheKey);
       mruList.addFirst(aCacheKey);
index b4599fd..5856cdd 100755 (executable)
@@ -50,7 +50,6 @@ import mircoders.localizer.MirCachingLocalizerDecorator;
 import mircoders.localizer.MirLocalizer;\r
 \r
 public class MirGlobal {\r
 import mircoders.localizer.MirLocalizer;\r
 \r
 public class MirGlobal {\r
-  static private MirPropertiesConfiguration configuration;\r
   static private MirLocalizer localizer;\r
   static private ProducerEngine producerEngine;\r
   static private Abuse abuse;\r
   static private MirLocalizer localizer;\r
   static private ProducerEngine producerEngine;\r
   static private Abuse abuse;\r
@@ -91,12 +90,14 @@ public class MirGlobal {
     return localizer;\r
   }\r
 \r
     return localizer;\r
   }\r
 \r
+  /**\r
+   * Returns a string that provides some global status information\r
+   */\r
   public static String getStatus() {\r
     StringBuffer result = new StringBuffer();\r
 \r
   public static String getStatus() {\r
     StringBuffer result = new StringBuffer();\r
 \r
-    System.gc();\r
-    result.append(Runtime.getRuntime().freeMemory()).append("/");\r
-    result.append(Runtime.getRuntime().freeMemory()).append(" free memory | ");\r
+    result.append((Runtime.getRuntime().totalMemory()-Runtime.getRuntime().freeMemory())/(1024*1024));\r
+    result.append("M in use, ");\r
     result.append(Thread.currentThread().activeCount()).append(" active threads");\r
 \r
     return result.toString();\r
     result.append(Thread.currentThread().activeCount()).append(" active threads");\r
 \r
     return result.toString();\r