You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by sl...@apache.org on 2009/07/22 22:28:04 UTC

svn commit: r796871 - in /tuscany/java/sca/modules: assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ monitor/src/main/java/org/apache/tuscany/sca/monitor/ monitor/src/main/java/org/apache/tuscany/sca/monitor/impl/

Author: slaws
Date: Wed Jul 22 20:28:03 2009
New Revision: 796871

URL: http://svn.apache.org/viewvc?rev=796871&view=rev
Log:
TUSCANY-3150 TUSCANY-3176 updates to show how we can accumulate context and how we can make the code simpler in terms of introducing the monitor to a module. I would like to think there is a more automatic way of determining the bundle name. 

Modified:
    tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferenceWireBuilderImpl.java
    tuscany/java/sca/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/Monitor.java
    tuscany/java/sca/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/Problem.java
    tuscany/java/sca/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/impl/MonitorImpl.java
    tuscany/java/sca/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/impl/ProblemImpl.java

Modified: tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferenceWireBuilderImpl.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferenceWireBuilderImpl.java?rev=796871&r1=796870&r2=796871&view=diff
==============================================================================
--- tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferenceWireBuilderImpl.java (original)
+++ tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferenceWireBuilderImpl.java Wed Jul 22 20:28:03 2009
@@ -66,6 +66,8 @@
      */
     protected void wireComponentReferences(Composite composite, Monitor monitor) {
 
+        monitor.pushContext(composite.getName().toString());
+        
         // Wire nested composites recursively
         for (Component component : composite.getComponents()) {
             Implementation implementation = component.getImplementation();
@@ -108,7 +110,14 @@
                                 componentReference.getName());
                     }
                 } else {
-                    warning(monitor, "TooManyReferenceTargets", composite, componentReference.getName());
+// ---------------------------                    
+// TUSCANY-3132  first example of updated error handling                  
+                    Monitor.error(monitor,
+                                  this,
+                                  "assembly-validation-messages",
+                                  "TooManyReferenceTargets", 
+                                  componentReference.getName());
+// ---------------------------                    
                 }
             }
         }
@@ -118,6 +127,8 @@
         //  for (ComponentReference componentReference : componentReferences.values()) {
         //      componentReference.getTargets().clear();
         //  }
+        
+        monitor.popContext();
     }
 
     /**

Modified: tuscany/java/sca/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/Monitor.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/Monitor.java?rev=796871&r1=796870&r2=796871&view=diff
==============================================================================
--- tuscany/java/sca/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/Monitor.java (original)
+++ tuscany/java/sca/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/Monitor.java Wed Jul 22 20:28:03 2009
@@ -28,27 +28,27 @@
  *
  * @version $Rev$ $Date$
  */
-public interface Monitor {
+public abstract class Monitor {
     /**
      * Reports a build problem.
      * 
      * @param problem
      */
-    void problem(Problem problem);
+    public abstract void problem(Problem problem);
 
     /** 
      * Returns a list of reported problems. 
      * 
      * @return the list of problems. The list may be empty
      */
-    List<Problem> getProblems();
+    public abstract List<Problem> getProblems();
 
     /**
      * Returns the last logged problem.
      * 
      * @return
      */
-    public Problem getLastProblem();
+    public abstract Problem getLastProblem();
 
     /**
      * Create a new problem.
@@ -61,12 +61,12 @@
      * @param cause             the exception which caused the problem
      * @return
      */
-    Problem createProblem(String sourceClassName,
-                          String bundleName,
-                          Severity severity,
-                          Object problemObject,
-                          String messageId,
-                          Exception cause);
+    public abstract Problem createProblem(String sourceClassName,
+                                          String bundleName,
+                                          Severity severity,
+                                          Object problemObject,
+                                          String messageId,
+                                          Exception cause);
 
     /**
      * Create a new problem.
@@ -79,23 +79,74 @@
      * @param messageParams     the parameters of the problem message
      * @return
      */
-    Problem createProblem(String sourceClassName,
-                          String bundleName,
-                          Severity severity,
-                          Object problemObject,
-                          String messageId,
-                          Object... messageParams);
+    public abstract Problem createProblem(String sourceClassName,
+                                   String bundleName,
+                                   Severity severity,
+                                   Object problemObject,
+                                   String messageId,
+                                   Object... messageParams);
 
     /**
      * Set the name of an artifact for which errors are Monitored
      * @param artifactName the artifact name
      */
-    void setArtifactName(String artifactName);
+    public abstract void setArtifactName(String artifactName);
 
     /**
      * Get the name of the artifact for which errors are Monitored
      * @return the name of the Artifact or null if no artifact name has been set
      */
-    String getArtifactName();
-
+    public abstract String getArtifactName();
+    
+    // =====================================================
+    // TUSCANY-3132 - new approach to monitoring errors
+    //           
+    
+    /**
+     * Add a context string to the context stack
+     * @param context the context string to add
+     */
+    public abstract void pushContext(String context);
+    
+    /**
+     * Remove the most recent context string from the 
+     * context stack
+     */
+    public abstract void popContext();
+    
+    public static void warning (Monitor monitor, 
+                                Object reportingObject,
+                                String messageBundle,
+                                String messageId, 
+                                String... messageParameters){
+        if (monitor != null) {
+            Problem problem =
+                monitor.createProblem(reportingObject.getClass().getName(),
+                                      messageBundle,
+                                      Severity.WARNING,
+                                      null,
+                                      messageId,
+                                      (Object[])messageParameters);
+            monitor.problem(problem);
+        }
+    }
+   
+    public static void error (Monitor monitor, 
+                              Object reportingObject,
+                              String messageBundle,
+                              String messageId, 
+                              String... messageParameters){
+        if (monitor != null) {
+            Problem problem =
+                monitor.createProblem(reportingObject.getClass().getName(),
+                                      messageBundle,
+                                      Severity.ERROR,
+                                      null,
+                                      messageId,
+                                      (Object[])messageParameters);
+            monitor.problem(problem);
+        }
+    }
+    
+    // =====================================================
 }

Modified: tuscany/java/sca/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/Problem.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/Problem.java?rev=796871&r1=796870&r2=796871&view=diff
==============================================================================
--- tuscany/java/sca/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/Problem.java (original)
+++ tuscany/java/sca/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/Problem.java Wed Jul 22 20:28:03 2009
@@ -35,6 +35,8 @@
     String getBundleName();
 
     Severity getSeverity();
+    
+    String getContext();
 
     Object getProblemObject();
 

Modified: tuscany/java/sca/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/impl/MonitorImpl.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/impl/MonitorImpl.java?rev=796871&r1=796870&r2=796871&view=diff
==============================================================================
--- tuscany/java/sca/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/impl/MonitorImpl.java (original)
+++ tuscany/java/sca/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/impl/MonitorImpl.java Wed Jul 22 20:28:03 2009
@@ -21,6 +21,7 @@
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Stack;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -33,8 +34,11 @@
  *
  * @version $Rev$ $Date$
  */
-public class MonitorImpl implements Monitor {
+public class MonitorImpl extends Monitor {
     private static final Logger logger = Logger.getLogger(MonitorImpl.class.getName());
+    
+    // stack of context information that is printed alongside each problem
+    private Stack<String> contextStack = new Stack<String>();
 
     // Cache all the problem reported to monitor for further analysis
     private List<Problem> problemCache = new ArrayList<Problem>();
@@ -54,21 +58,21 @@
 
         if (problem.getSeverity() == Severity.INFO) {
             problemCache.add(problem);
-            problemLogger.logp(Level.INFO, problem.getSourceClassName(), null, problem.getMessageId(), problem
+            problemLogger.logp(Level.INFO, problem.getSourceClassName(), problem.getContext(), problem.getMessageId(), problem
                 .getMessageParams());
         } else if (problem.getSeverity() == Severity.WARNING) {
             problemCache.add(problem);
-            problemLogger.logp(Level.WARNING, problem.getSourceClassName(), null, problem.getMessageId(), problem
+            problemLogger.logp(Level.WARNING, problem.getSourceClassName(), problem.getContext(), problem.getMessageId(), problem
                 .getMessageParams());
         } else if (problem.getSeverity() == Severity.ERROR) {
             if (problem.getCause() != null) {
                 problemCache.add(problem);
-                problemLogger.logp(Level.SEVERE, problem.getSourceClassName(), null, problem.getMessageId(), problem
+                problemLogger.logp(Level.SEVERE, problem.getSourceClassName(), problem.getContext(), problem.getMessageId(), problem
                     .getCause().toString());
 
             } else {
                 problemCache.add(problem);
-                problemLogger.logp(Level.SEVERE, problem.getSourceClassName(), null, problem.getMessageId(), problem
+                problemLogger.logp(Level.SEVERE, problem.getSourceClassName(), problem.getContext(), problem.getMessageId(), problem
                     .getMessageParams());
             }
         }
@@ -91,7 +95,7 @@
                                  Object problemObject,
                                  String messageId,
                                  Exception cause) {
-        return new ProblemImpl(sourceClassName, bundleName, severity, problemObject, messageId, cause);
+        return new ProblemImpl(sourceClassName, bundleName, severity, contextStack.toString(), problemObject, messageId, cause);
     }
 
     public Problem createProblem(String sourceClassName,
@@ -100,7 +104,7 @@
                                  Object problemObject,
                                  String messageId,
                                  Object... messageParams) {
-        return new ProblemImpl(sourceClassName, bundleName, severity, problemObject, messageId, messageParams);
+        return new ProblemImpl(sourceClassName, bundleName, severity, contextStack.toString(), problemObject, messageId, messageParams);
     }
 
     public String getArtifactName() {
@@ -110,4 +114,14 @@
     public void setArtifactName(String artifactName) {
         this.artifactName = artifactName;
     }
+    
+    @Override
+    public void pushContext(String context) {
+        contextStack.push(context);
+    }
+    
+    @Override
+    public void popContext() {
+        contextStack.pop();
+    }
 }

Modified: tuscany/java/sca/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/impl/ProblemImpl.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/impl/ProblemImpl.java?rev=796871&r1=796870&r2=796871&view=diff
==============================================================================
--- tuscany/java/sca/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/impl/ProblemImpl.java (original)
+++ tuscany/java/sca/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/impl/ProblemImpl.java Wed Jul 22 20:28:03 2009
@@ -37,6 +37,7 @@
     private String sourceClassName;
     private String bundleName;
     private Severity severity;
+    private String context;
     private Object problemObject;
     private String messageId;
     private Object[] messageParams;
@@ -48,6 +49,7 @@
      * @param sourceClassName   the class name reporting the problem
      * @param bundleName        the name of the message bundle to use
      * @param severity          the severity of the problem
+     * @param context           the string indicating where the error occurred
      * @param problemObject     the model object for which the problem is being reported
      * @param messageId         the id of the problem message
      * @param messageParams     the parameters of the problem message
@@ -55,12 +57,14 @@
     public ProblemImpl(String sourceClassName,
                        String bundleName,
                        Severity severity,
+                       String context,
                        Object problemObject,
                        String messageId,
                        Object... messageParams) {
         this.sourceClassName = sourceClassName;
         this.bundleName = bundleName;
         this.severity = severity;
+        this.context = context;
         this.problemObject = problemObject;
         this.messageId = messageId;
         this.messageParams = messageParams;
@@ -72,6 +76,7 @@
      * @param sourceClassName   the class name reporting the problem
      * @param bundleName        the name of the message bundle to use
      * @param severity          the severity of the problem
+     * @param context           the string indicating where the error occurred
      * @param problemObject     the model object for which the problem is being reported
      * @param messageId         the id of the problem message
      * @param cause             the exception which caused the problem
@@ -79,12 +84,14 @@
     public ProblemImpl(String sourceClassName,
                        String bundleName,
                        Severity severity,
+                       String context,
                        Object problemObject,
                        String messageId,
                        Exception cause) {
         this.sourceClassName = sourceClassName;
         this.bundleName = bundleName;
         this.severity = severity;
+        this.context = context;
         this.problemObject = problemObject;
         this.messageId = messageId;
         this.cause = cause;
@@ -101,6 +108,10 @@
     public Severity getSeverity() {
         return severity;
     }
+    
+    public String getContext() {
+        return context;
+    }
 
     public Object getProblemObject() {
         return problemObject;
@@ -137,6 +148,6 @@
 
         Formatter formatter = new SimpleFormatter();
 
-        return formatter.formatMessage(record);
+        return context + " - " + formatter.formatMessage(record);
     }
 }