svn commit: r12604 - trunk/src_new/org/argouml/cognitive/Designer.java

[email protected]
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: tfmorris
Date: 2007-05-11 17:00:49-0700
New Revision: 12604

Modified:
   trunk/src_new/org/argouml/cognitive/Designer.java

Log:
Make sure Critic thread logs when it dies

Modified: trunk/src_new/org/argouml/cognitive/Designer.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src_new/org/argouml/cognitive/Designer.java?view=diff&rev=12604&p1=trunk/src_new/org/argouml/cognitive/Designer.java&p2=trunk/src_new/org/argouml/cognitive/Designer.java&r1=12603&r2=12604
==============================================================================
--- trunk/src_new/org/argouml/cognitive/Designer.java	(original)
+++ trunk/src_new/org/argouml/cognitive/Designer.java	2007-05-11 17:00:49-0700
@@ -40,6 +40,7 @@
 import org.argouml.cognitive.critics.Critic;
 import org.argouml.configuration.Configuration;
 import org.argouml.configuration.ConfigurationKey;
+import org.argouml.model.InvalidElementException;
 import org.argouml.ui.ActionGoToCritique;
 import org.tigris.gef.util.ChildGenerator;
 import org.tigris.gef.util.EnumerationEmpty;
@@ -268,99 +269,113 @@
      * Thread that runs this.
      */
     public void run() {
+        try {
+            while (true) {
 
-        while (true) {
+                // local variables - what do they do?
+                long critiqueStartTime;
+                long cutoffTime;
+                int minWarmElements = 5;
+                int size;
 
-            // local variables - what do they do?
-            long critiqueStartTime;
-            long cutoffTime;
-            int minWarmElements = 5;
-            int size;
-
-            // the critiquing thread should wait if disabled.
-            synchronized (this) {
-                while (!Configuration.getBoolean(
-                        Designer.AUTO_CRITIQUE, true)) {
-                    try {
-                        this.wait();
-                    } catch (InterruptedException ignore) {
-                        LOG.error("InterruptedException!!!", ignore);
+                // the critiquing thread should wait if disabled.
+                synchronized (this) {
+                    while (!Configuration.getBoolean(
+                            Designer.AUTO_CRITIQUE, true)) {
+                        try {
+                            this.wait();
+                        } catch (InterruptedException ignore) {
+                            LOG.error("InterruptedException!!!", ignore);
+                        }
                     }
                 }
-            }
-
-            // why?
-            if (critiquingRoot != null
-//		&& getAutoCritique()
-		&& critiqueLock <= 0) {
 
                 // why?
-                synchronized (this) {
-                    critiqueStartTime = System.currentTimeMillis();
-                    cutoffTime = critiqueStartTime + 3000;
-
-                    size = addQueue.size();
-                    for (int i = 0; i < size; i++) {
-                        hotQueue.addElement(addQueue.elementAt(i));
-                        hotReasonQueue.addElement(addReasonQueue.elementAt(i));
-                    }
-                    addQueue.removeAllElements();
-                    addReasonQueue.removeAllElements();
+                if (critiquingRoot != null
+//                      && getAutoCritique()
+                        && critiqueLock <= 0) {
+
+                    // why?
+                    synchronized (this) {
+                        critiqueStartTime = System.currentTimeMillis();
+                        cutoffTime = critiqueStartTime + 3000;
+
+                        size = addQueue.size();
+                        for (int i = 0; i < size; i++) {
+                            hotQueue.addElement(addQueue.elementAt(i));
+                            hotReasonQueue.addElement(addReasonQueue
+                                    .elementAt(i));
+                        }
+                        addQueue.removeAllElements();
+                        addReasonQueue.removeAllElements();
 
-                    longestHot = Math.max(longestHot, hotQueue.size());
-                    agency.determineActiveCritics(this);
+                        longestHot = Math.max(longestHot, hotQueue.size());
+                        agency.determineActiveCritics(this);
 
-                    while (hotQueue.size() > 0) {
-                        Object dm = hotQueue.elementAt(0);
-                        Long reasonCode = (Long) hotReasonQueue.elementAt(0);
-                        hotQueue.removeElementAt(0);
-                        hotReasonQueue.removeElementAt(0);
-                        Agency.applyAllCritics(dm, theDesigner(),
-					       reasonCode.longValue());
-                    }
+                        while (hotQueue.size() > 0) {
+                            Object dm = hotQueue.elementAt(0);
+                            Long reasonCode =
+                                    (Long) hotReasonQueue.elementAt(0);
+                            hotQueue.removeElementAt(0);
+                            hotReasonQueue.removeElementAt(0);
+                            Agency.applyAllCritics(dm, theDesigner(),
+                                    reasonCode.longValue());
+                        }
 
-                    size = removeQueue.size();
-                    for (int i = 0; i < size; i++) {
-                        warmQueue.removeElement(removeQueue.elementAt(i));
-                    }
-                    removeQueue.removeAllElements();
+                        size = removeQueue.size();
+                        for (int i = 0; i < size; i++) {
+                            warmQueue.removeElement(removeQueue.elementAt(i));
+                        }
+                        removeQueue.removeAllElements();
 
-                    if (warmQueue.size() == 0) {
-                        warmQueue.addElement(critiquingRoot);
-                    }
-                    while (warmQueue.size() > 0
-			   && (System.currentTimeMillis() < cutoffTime
-			       || minWarmElements > 0)) {
-                        if (minWarmElements > 0) {
-                            minWarmElements--;
+                        if (warmQueue.size() == 0) {
+                            warmQueue.addElement(critiquingRoot);
                         }
-                        Object dm = warmQueue.elementAt(0);
-                        warmQueue.removeElementAt(0);
-                        Agency.applyAllCritics(dm, theDesigner());
-                        java.util.Enumeration subDMs = childGenerator.gen(dm);
-                        while (subDMs.hasMoreElements()) {
-                            Object nextDM = subDMs.nextElement();
-                            if (!(warmQueue.contains(nextDM))) {
-                                warmQueue.addElement(nextDM);
+                        while (warmQueue.size() > 0
+                                && (System.currentTimeMillis() < cutoffTime
+                                        || minWarmElements > 0)) {
+                            if (minWarmElements > 0) {
+                                minWarmElements--;
+                            }
+                            Object dm = warmQueue.elementAt(0);
+                            warmQueue.removeElementAt(0);
+                            try {
+                                Agency.applyAllCritics(dm, theDesigner());
+                                java.util.Enumeration subDMs =
+                                        childGenerator.gen(dm);
+                                while (subDMs.hasMoreElements()) {
+                                    Object nextDM = subDMs.nextElement();
+                                    if (!(warmQueue.contains(nextDM))) {
+                                        warmQueue.addElement(nextDM);
+                                    }
+                                }
+                            } catch (InvalidElementException e) {
+                                // Don't let a transient error kill the thread
+                                LOG.warn("Element " + dm
+                                        + "caused an InvalidElementException.  "
+                                        + "Ignoring for this pass.");
                             }
                         }
                     }
+                } else {
+                    critiqueStartTime = System.currentTimeMillis();
+                }
+                critiqueDuration =
+                        System.currentTimeMillis() - critiqueStartTime;
+                long cycleDuration =
+                    (critiqueDuration * 100) / critiqueCPUPercent;
+                long sleepDuration =
+                    Math.min(cycleDuration - critiqueDuration, 3000);
+                sleepDuration = Math.max(sleepDuration, 1000);
+                LOG.debug("sleepDuration= " + sleepDuration);
+                try {
+                    Thread.sleep(sleepDuration);
+                } catch (InterruptedException ignore) {
+                    LOG.error("InterruptedException!!!", ignore);
                 }
-            } else {
-                critiqueStartTime = System.currentTimeMillis();
-            }
-            critiqueDuration = System.currentTimeMillis() - critiqueStartTime;
-            long cycleDuration =
-		(critiqueDuration * 100) / critiqueCPUPercent;
-            long sleepDuration =
-		Math.min(cycleDuration - critiqueDuration, 3000);
-            sleepDuration = Math.max(sleepDuration, 1000);
-            LOG.debug("sleepDuration= " + sleepDuration);
-            try {
-                Thread.sleep(sleepDuration);
-            } catch (InterruptedException ignore) {
-                LOG.error("InterruptedException!!!", ignore);
             }
+        } catch (Exception e) {
+            LOG.error("Critic thread killed by exception", e);
         }
     }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.