diff options
Diffstat (limited to 'java/sca/modules/monitor/src')
7 files changed, 143 insertions, 114 deletions
diff --git a/java/sca/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/DefaultMonitorFactory.java b/java/sca/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/DefaultMonitorFactory.java index b38968caeb..6bd796f3c1 100644 --- a/java/sca/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/DefaultMonitorFactory.java +++ b/java/sca/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/DefaultMonitorFactory.java @@ -21,21 +21,20 @@ package org.apache.tuscany.sca.monitor; import org.apache.tuscany.sca.monitor.impl.MonitorImpl; - /** * A factory for creating validation monitors * * @version $Rev$ $Date$ */ public class DefaultMonitorFactory implements MonitorFactory { - + private Monitor monitor = null; public Monitor createMonitor() { if (monitor == null) { monitor = new MonitorImpl(); } - return monitor ; + return monitor; } } diff --git a/java/sca/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/Monitor.java b/java/sca/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/Monitor.java index 14366b423d..5b09f0116c 100644 --- a/java/sca/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/Monitor.java +++ b/java/sca/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/Monitor.java @@ -35,21 +35,21 @@ public interface Monitor { * @param problem */ void problem(Problem problem); - + /** * Returns a list of reported problems. * * @return the list of problems. The list may be empty */ List<Problem> getProblems(); - + /** * Returns the last logged problem. * * @return */ public Problem getLastProblem(); - + /** * Create a new problem. * @@ -61,7 +61,12 @@ public interface Monitor { * @param cause the exception which caused the problem * @return */ - Problem createProblem(String sourceClassName, String bundleName, Severity severity, Object problemObject, String messageId, Exception cause); + Problem createProblem(String sourceClassName, + String bundleName, + Severity severity, + Object problemObject, + String messageId, + Exception cause); /** * Create a new problem. @@ -74,18 +79,23 @@ public interface Monitor { * @param messageParams the parameters of the problem message * @return */ - Problem createProblem(String sourceClassName, String bundleName, Severity severity, Object problemObject, String messageId, Object... messageParams ); - + 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 ); - + 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(); - + } diff --git a/java/sca/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/MonitorFactory.java b/java/sca/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/MonitorFactory.java index 3384626958..3f2acaaf07 100644 --- a/java/sca/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/MonitorFactory.java +++ b/java/sca/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/MonitorFactory.java @@ -18,7 +18,6 @@ */ package org.apache.tuscany.sca.monitor; - /** * A factory for validation monitors * @@ -32,5 +31,5 @@ public interface MonitorFactory { * @return a new monitor */ Monitor createMonitor(); - + } diff --git a/java/sca/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/Problem.java b/java/sca/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/Problem.java index 83a2d63eae..d495569e73 100644 --- a/java/sca/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/Problem.java +++ b/java/sca/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/Problem.java @@ -19,31 +19,28 @@ package org.apache.tuscany.sca.monitor; - /** * Records an validation problem. * * @version $Rev$ $Date$ */ public interface Problem { - + public enum Severity { - INFO, - WARNING, - ERROR + INFO, WARNING, ERROR } - + String getSourceClassName(); - + String getBundleName(); - - Severity getSeverity(); - + + Severity getSeverity(); + Object getProblemObject(); - + String getMessageId(); - + Exception getCause(); - + Object[] getMessageParams(); } diff --git a/java/sca/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/impl/MonitorImpl.java b/java/sca/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/impl/MonitorImpl.java index ca0c7d865c..27070fcc40 100644 --- a/java/sca/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/impl/MonitorImpl.java +++ b/java/sca/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/impl/MonitorImpl.java @@ -35,69 +35,79 @@ import org.apache.tuscany.sca.monitor.Problem.Severity; */ public class MonitorImpl implements Monitor { private static final Logger logger = Logger.getLogger(MonitorImpl.class.getName()); - + // Cache all the problem reported to monitor for further analysis private List<Problem> problemCache = new ArrayList<Problem>(); - + // Name of an artifact for which problems are being Monitored private String artifactName = null; public void problem(Problem problem) { - + Logger problemLogger = Logger.getLogger(problem.getSourceClassName(), problem.getBundleName()); - - if (problemLogger == null){ - logger.severe("Can't get logger " + problem.getSourceClassName()+ " with bundle " + problem.getBundleName()); + + if (problemLogger == null) { + logger.severe("Can't get logger " + problem.getSourceClassName() + + " with bundle " + + problem.getBundleName()); } - + if (problem.getSeverity() == Severity.INFO) { - problemCache.add(problem); - problemLogger.logp(Level.INFO, problem.getSourceClassName(), null, - problem.getMessageId(), problem.getMessageParams()); - } - else if (problem.getSeverity() == Severity.WARNING) { problemCache.add(problem); - problemLogger.logp(Level.WARNING, problem.getSourceClassName(), null, - problem.getMessageId(), problem.getMessageParams()); - } - else if (problem.getSeverity() == Severity.ERROR) { + problemLogger.logp(Level.INFO, problem.getSourceClassName(), null, problem.getMessageId(), problem + .getMessageParams()); + } else if (problem.getSeverity() == Severity.WARNING) { + problemCache.add(problem); + problemLogger.logp(Level.WARNING, problem.getSourceClassName(), null, 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.getCause().toString()); + problemLogger.logp(Level.SEVERE, problem.getSourceClassName(), null, problem.getMessageId(), problem + .getCause().toString()); } else { problemCache.add(problem); - problemLogger.logp(Level.SEVERE, problem.getSourceClassName(), null, - problem.getMessageId(), problem.getMessageParams()); + problemLogger.logp(Level.SEVERE, problem.getSourceClassName(), null, problem.getMessageId(), problem + .getMessageParams()); } } } - - public List<Problem> getProblems(){ + + public List<Problem> getProblems() { return problemCache; } - - public Problem getLastProblem(){ + + public Problem getLastProblem() { if (problemCache.isEmpty()) { return null; } return problemCache.get(problemCache.size() - 1); } - - public Problem createProblem(String sourceClassName, String bundleName, Severity severity, Object problemObject, String messageId, Exception cause) { + + public Problem createProblem(String sourceClassName, + String bundleName, + Severity severity, + Object problemObject, + String messageId, + Exception cause) { return new ProblemImpl(sourceClassName, bundleName, severity, problemObject, messageId, cause); } - - public Problem createProblem(String sourceClassName, String bundleName, Severity severity, Object problemObject, String messageId, Object... messageParams) { + + public Problem createProblem(String sourceClassName, + String bundleName, + Severity severity, + Object problemObject, + String messageId, + Object... messageParams) { return new ProblemImpl(sourceClassName, bundleName, severity, problemObject, messageId, messageParams); } - public String getArtifactName() { - return artifactName; - } + public String getArtifactName() { + return artifactName; + } - public void setArtifactName(String artifactName) { - this.artifactName = artifactName; - } + public void setArtifactName(String artifactName) { + this.artifactName = artifactName; + } } diff --git a/java/sca/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/impl/ProblemImpl.java b/java/sca/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/impl/ProblemImpl.java index 5a0aaeddd0..f00071bc51 100644 --- a/java/sca/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/impl/ProblemImpl.java +++ b/java/sca/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/impl/ProblemImpl.java @@ -52,7 +52,12 @@ public class ProblemImpl implements Problem { * @param messageId the id of the problem message * @param messageParams the parameters of the problem message */ - public ProblemImpl(String sourceClassName, String bundleName, Severity severity, Object problemObject, String messageId, Object... messageParams ) { + public ProblemImpl(String sourceClassName, + String bundleName, + Severity severity, + Object problemObject, + String messageId, + Object... messageParams) { this.sourceClassName = sourceClassName; this.bundleName = bundleName; this.severity = severity; @@ -60,7 +65,7 @@ public class ProblemImpl implements Problem { this.messageId = messageId; this.messageParams = messageParams; } - + /** * Construct a new problem * @@ -71,31 +76,36 @@ public class ProblemImpl implements Problem { * @param messageId the id of the problem message * @param cause the exception which caused the problem */ - public ProblemImpl(String sourceClassName, String bundleName, Severity severity, Object problemObject, String messageId, Exception cause) { + public ProblemImpl(String sourceClassName, + String bundleName, + Severity severity, + Object problemObject, + String messageId, + Exception cause) { this.sourceClassName = sourceClassName; - this.bundleName = bundleName; - this.severity = severity; + this.bundleName = bundleName; + this.severity = severity; this.problemObject = problemObject; this.messageId = messageId; this.cause = cause; - } + } public String getSourceClassName() { return sourceClassName; } - + public String getBundleName() { return bundleName; } - + public Severity getSeverity() { return severity; } - + public Object getProblemObject() { return problemObject; } - + public String getMessageId() { return messageId; } @@ -103,20 +113,20 @@ public class ProblemImpl implements Problem { public Object[] getMessageParams() { return messageParams; } - + public Exception getCause() { return cause; - } + } @Override public String toString() { Logger logger = Logger.getLogger(sourceClassName, bundleName); - + LogRecord record = new LogRecord(Level.INFO, messageId); - - if (cause == null){ + + if (cause == null) { record.setParameters(messageParams); - + } else { Object[] params = new String[1]; params[0] = cause.toString(); @@ -124,9 +134,9 @@ public class ProblemImpl implements Problem { } record.setResourceBundle(logger.getResourceBundle()); record.setSourceClassName(sourceClassName); - + Formatter formatter = new SimpleFormatter(); - + return formatter.formatMessage(record); } } diff --git a/java/sca/modules/monitor/src/test/java/org/apache/tuscany/sca/monitor/MonitorTestCase.java b/java/sca/modules/monitor/src/test/java/org/apache/tuscany/sca/monitor/MonitorTestCase.java index 4380e32f99..6e5fcd9015 100644 --- a/java/sca/modules/monitor/src/test/java/org/apache/tuscany/sca/monitor/MonitorTestCase.java +++ b/java/sca/modules/monitor/src/test/java/org/apache/tuscany/sca/monitor/MonitorTestCase.java @@ -30,63 +30,67 @@ import org.junit.Test; * @version $Rev$ $Date$ */ public class MonitorTestCase { - + private static MonitorFactory monitorFactory; - + @BeforeClass public static void init() throws Exception { - monitorFactory = new DefaultMonitorFactory(); + monitorFactory = new DefaultMonitorFactory(); } - + @AfterClass public static void destroy() throws Exception { monitorFactory = null; } - + @Test - public void testCreateProblem() throws Exception { + public void testCreateProblem() throws Exception { String dummyModelObject = "DUMMY MODEL OBJECT"; - + Monitor monitor = monitorFactory.createMonitor(); - + Problem problem = null; - - problem = monitor.createProblem(this.getClass().getName(), - "tuscany-monitor-test-messages", - Severity.WARNING, - dummyModelObject, - "MESSAGE1" ); + + problem = + monitor.createProblem(this.getClass().getName(), + "tuscany-monitor-test-messages", + Severity.WARNING, + dummyModelObject, + "MESSAGE1"); monitor.problem(problem); - + String param = "Some Parameter"; - - problem = monitor.createProblem(this.getClass().getName(), - "tuscany-monitor-test-messages", - Severity.WARNING, - dummyModelObject, + + problem = + monitor.createProblem(this.getClass().getName(), + "tuscany-monitor-test-messages", + Severity.WARNING, + dummyModelObject, "MESSAGE2", param); monitor.problem(problem); - - problem = monitor.createProblem(this.getClass().getName(), - "tuscany-monitor-test-messages", - Severity.WARNING, - dummyModelObject, + + problem = + monitor.createProblem(this.getClass().getName(), + "tuscany-monitor-test-messages", + Severity.WARNING, + dummyModelObject, "MESSAGE3", - 8, - 9, + 8, + 9, 4); monitor.problem(problem); - + Exception ex = new IllegalStateException("TEST_MESSAGE"); - - problem = monitor.createProblem(this.getClass().getName(), - "tuscany-monitor-test-messages", - Severity.ERROR, - dummyModelObject, + + problem = + monitor.createProblem(this.getClass().getName(), + "tuscany-monitor-test-messages", + Severity.ERROR, + dummyModelObject, "MESSAGE4", ex); - monitor.problem(problem); - + monitor.problem(problem); + } } |