- Revision
- 388
- Author
- mauro
- Date
- 2007-11-16 02:55:53 -0600 (Fri, 16 Nov 2007)
Log Message
Added ConsoleMonitor. Renamed writing monitor methods to monitorLevels() and monitorMessages() for better clarity.
Modified Paths
- trunk/core/src/main/java/org/codehaus/waffle/monitor/AbstractWritingMonitor.java
- trunk/distribution/src/site/content/monitors.html
- trunk/examples/simple-example/src/main/java/org/codehaus/waffle/example/simple/SimpleMonitor.java
Added Paths
Diff
Modified: trunk/core/src/main/java/org/codehaus/waffle/monitor/AbstractWritingMonitor.java (387 => 388)
--- trunk/core/src/main/java/org/codehaus/waffle/monitor/AbstractWritingMonitor.java 2007-11-16 08:37:03 UTC (rev 387) +++ trunk/core/src/main/java/org/codehaus/waffle/monitor/AbstractWritingMonitor.java 2007-11-16 08:55:53 UTC (rev 388) @@ -46,14 +46,22 @@ RegistrarMonitor, ServletMonitor, ValidationMonitor, ViewMonitor { private Map<String, Level> levels; - private Map<String, String> templates; + private Map<String, String> messages; protected AbstractWritingMonitor(){ - this.levels = eventLevels(); - this.templates = eventTemplates(); + this.levels = monitorLevels(); + this.messages = monitorMessages(); } - protected Map<String, Level> eventLevels() { + /** + * Creates the default map of monitor levels, keyed on the event name. + * Subclasses may override any of these by retrieving the levels via + * <code>super.monitorLevels()</code>, overwriting any entry and returning + * the map. + * + * @return A Map<String, Level> + */ + protected Map<String, Level> monitorLevels() { Map<String, Level> levels = new HashMap<String, Level>(); levels.put("defaultActionMethodFound", INFO); levels.put("defaultActionMethodCached", DEBUG); @@ -93,44 +101,54 @@ return levels; } - protected Map<String, String> eventTemplates() { - Map<String, String> templates = new HashMap<String, String>(); - templates.put("defaultActionMethodFound", "Default ActionMethod found: {0}"); - templates.put("defaultActionMethodCached", "Default ActionMethod cached for controller {0}: {1}"); - templates.put("pragmaticActionMethodFound", "Pragmatic ActionMethod found: {0}"); - templates.put("actionMethodFound", "ActionMethod found: {0}"); - templates.put("actionMethodExecuted", "ActionMethod executed with response: {0}"); - templates.put("actionMethodExecutionFailed", "ActionMethod failed: {0}"); - templates.put("methodNameResolved", "Method name ''{0}'' found for key ''{1}'' among keys {2}"); - templates.put("methodIntercepted", "Method ''{0}'' intercepted with arguments {1} and returned value ''{2}''"); - templates.put("argumentNameResolved", "Argument name ''{0}'' resolved to ''{1}'' in scope ''{2}''"); - templates.put("argumentNameNotMatched", "Argument name ''{0}'' not matched by pattern ''{1}''"); - templates.put("responseIsCommitted", "Response is committed for response: {0}"); - templates.put("viewDispatched", "View dispatched: {0}"); - templates.put("bindFailedForModel", "Bind failed for model ''{0}'': {1}"); - templates.put("bindFailedForController", "Bind failed for controller ''{0}'': {1}"); - templates.put("registrarCreated", "Registrar created {0} with monitor {1}"); - templates.put("registrarNotFound", "Registrar not found {0}"); - templates.put("contextInitialized", "Context initialized"); - templates.put("applicationContextContainerStarted", "Application context container started"); - templates.put("applicationContextContainerDestroyed", "Application context container destroyed"); - templates.put("sessionContextContainerCreated", "Session context container created with parent application container {0}"); - templates.put("requestContextContainerCreated", "Request context container created with parent session container {0}"); - templates.put("controllerNameResolved", "Controller name resolved to {0} from path {1}"); - templates.put("controllerNotFound", "Controller not found for name {0}"); - templates.put("methodDefinitionNotFound", "Method definition not found for controller name {0}"); - templates.put("requestContextContainerNotFound", "Request level context container not found"); - templates.put("componentRegistered", "Registered component of type {1} with key {0} and parameters {2}"); - templates.put("instanceRegistered", "Registered instance {1} with key {0}"); - templates.put("nonCachingComponentRegistered", "Registered non-caching component of type {1} with key {0} and parameters {2}"); - templates.put("servletServiceFailed", "Servlet service failed: {0}"); - templates.put("controllerValidatorNotFound", "Controller validator not found"); - templates.put("methodDefinitionNotFound", "Method definition not found in controller definition {0}"); - templates.put("validationFailed", "Validation failed: {0}"); - templates.put("viewForwarded", "View forwarded to path {0}"); - templates.put("viewRedirected", "View redirected: {0}"); - templates.put("viewResponded", "View responded: {0}"); - return templates; + /** + * Creates the default map of monitor message templates, keyed on the event name. + * Subclasses may override any of these by retrieving the messages via + * <code>super.monitorMessages()</code>, overwriting any entry and returning + * the map. Message templates need to be maintained in a format compatible with + * [EMAIL PROTECTED] MessageFormat} and will expect the same number of arguments as the event + * (with the argument index reflecting the argument order of the event). + * + * @return A Map<String, String> + */ + protected Map<String, String> monitorMessages() { + Map<String, String> messages = new HashMap<String, String>(); + messages.put("defaultActionMethodFound", "Default ActionMethod found: {0}"); + messages.put("defaultActionMethodCached", "Default ActionMethod cached for controller {0}: {1}"); + messages.put("pragmaticActionMethodFound", "Pragmatic ActionMethod found: {0}"); + messages.put("actionMethodFound", "ActionMethod found: {0}"); + messages.put("actionMethodExecuted", "ActionMethod executed with response: {0}"); + messages.put("actionMethodExecutionFailed", "ActionMethod failed: {0}"); + messages.put("methodNameResolved", "Method name ''{0}'' found for key ''{1}'' among keys {2}"); + messages.put("methodIntercepted", "Method ''{0}'' intercepted with arguments {1} and returned value ''{2}''"); + messages.put("argumentNameResolved", "Argument name ''{0}'' resolved to ''{1}'' in scope ''{2}''"); + messages.put("argumentNameNotMatched", "Argument name ''{0}'' not matched by pattern ''{1}''"); + messages.put("responseIsCommitted", "Response is committed for response: {0}"); + messages.put("viewDispatched", "View dispatched: {0}"); + messages.put("bindFailedForModel", "Bind failed for model ''{0}'': {1}"); + messages.put("bindFailedForController", "Bind failed for controller ''{0}'': {1}"); + messages.put("registrarCreated", "Registrar created {0} with monitor {1}"); + messages.put("registrarNotFound", "Registrar not found {0}"); + messages.put("contextInitialized", "Context initialized"); + messages.put("applicationContextContainerStarted", "Application context container started"); + messages.put("applicationContextContainerDestroyed", "Application context container destroyed"); + messages.put("sessionContextContainerCreated", "Session context container created with parent application container {0}"); + messages.put("requestContextContainerCreated", "Request context container created with parent session container {0}"); + messages.put("controllerNameResolved", "Controller name resolved to {0} from path {1}"); + messages.put("controllerNotFound", "Controller not found for name {0}"); + messages.put("methodDefinitionNotFound", "Method definition not found for controller name {0}"); + messages.put("requestContextContainerNotFound", "Request level context container not found"); + messages.put("componentRegistered", "Registered component of type {1} with key {0} and parameters {2}"); + messages.put("instanceRegistered", "Registered instance {1} with key {0}"); + messages.put("nonCachingComponentRegistered", "Registered non-caching component of type {1} with key {0} and parameters {2}"); + messages.put("servletServiceFailed", "Servlet service failed: {0}"); + messages.put("controllerValidatorNotFound", "Controller validator not found"); + messages.put("methodDefinitionNotFound", "Method definition not found in controller definition {0}"); + messages.put("validationFailed", "Validation failed: {0}"); + messages.put("viewForwarded", "View forwarded to path {0}"); + messages.put("viewRedirected", "View redirected: {0}"); + messages.put("viewResponded", "View responded: {0}"); + return messages; } private Level level(String event) { @@ -141,10 +159,10 @@ } private String template(String event) { - if ( !templates.containsKey(event) ){ + if ( !messages.containsKey(event) ){ throw new NoSuchElementException(event); } - return templates.get(event); + return messages.get(event); } protected void write(String event, Object... arguments) {
Added: trunk/core/src/main/java/org/codehaus/waffle/monitor/ConsoleMonitor.java (0 => 388)
--- trunk/core/src/main/java/org/codehaus/waffle/monitor/ConsoleMonitor.java (rev 0) +++ trunk/core/src/main/java/org/codehaus/waffle/monitor/ConsoleMonitor.java 2007-11-16 08:55:53 UTC (rev 388) @@ -0,0 +1,34 @@ +/***************************************************************************** + * Copyright (C) 2005,2006 Michael Ward * + * All rights reserved. * + * ------------------------------------------------------------------------- * + * The software in this package is published under the terms of the BSD * + * style license a copy of which has been included with this distribution in * + * the LICENSE.txt file. * + * * + * Original code by: Mauro Talevi * + *****************************************************************************/ +package org.codehaus.waffle.monitor; + +import static java.text.MessageFormat.format; + +/** + * Writing monitor that write events to console. + * + * @author Mauro Talevi + */ +public class ConsoleMonitor extends AbstractWritingMonitor { + + private static final String WAFFLE = "[WAFFLE]: {0} - {1}"; + + @Override + protected void write(Level level, String message) { + System.out.println(format(WAFFLE, level, message)); + } + + @Override + protected void trace(Throwable exception) { + exception.printStackTrace(); + } + +}
Modified: trunk/distribution/src/site/content/monitors.html (387 => 388)
--- trunk/distribution/src/site/content/monitors.html 2007-11-16 08:37:03 UTC (rev 387) +++ trunk/distribution/src/site/content/monitors.html 2007-11-16 08:55:53 UTC (rev 388) @@ -56,9 +56,11 @@ <p> Waffle provides an abstract implementation of <b>all</b> the monitor interfaces in <b><a href="" - org.codehaus.waffle.monitor.AbstractWritingMonitor</a></b> and two concrete implementations: + org.codehaus.waffle.monitor.AbstractWritingMonitor</a></b> and three concrete implementations: <b><a href="" - org.codehaus.waffle.monitor.CommonsLoggingMonitor</a></b> (which delegates to Commons Logging) + org.codehaus.waffle.monitor.CommonsLoggingMonitor</a></b> (which delegates to Commons Logging), + <b><a href="" + org.codehaus.waffle.monitor.ConsoleMonitor</a></b> (which writes to console) and <b><a href="" org.codehaus.waffle.monitor.SilentMonitor</a></b> (which writes nothing). </p> @@ -68,20 +70,22 @@ org.codehaus.waffle.monitor.AbstractWritingMonitor</a></b> defines a default <b><a href="" org.codehaus.waffle.monitor.Monitor.Level</a> for each event and a default message - template, which can be overridden via the <b>eventLevels()</b> and <b>eventTemplates()</b> + template, which can be overridden via the <b>monitorLevels()</b> and <b>monitorMessages()</b> methods. By convention, the levels and templates are held in maps keyed on the event name: <textarea class="xml:nogutter:nocontrols" name="code"> - protected Map<String, Level> eventLevels(){ - Map<String, Level> levels = super.eventLevels(); + @Override + protected Map<String, Level> monitorLevels(){ + Map<String, Level> levels = super.monitorLevels(); // change from INFO to DEBUG levels.put("defaultActionMethodFound", DEBUG); return levels; } - protected Map<String, String> eventTemplates(){ - Map<String, Level> templates = super.eventTemplates(); - // changed text to be more verbose - templates.put("defaultActionMethodFound", "The default ActionMethod has been found: {0}"); + @Override + protected Map<String, String> monitorMessages(){ + Map<String, Level> templates = super.monitorMessages(); + // changed text to be cheeky + templates.put("defaultActionMethodFound", "Ah-ha, found you: {0}"); return templates; } </textarea>
Modified: trunk/examples/simple-example/src/main/java/org/codehaus/waffle/example/simple/SimpleMonitor.java (387 => 388)
--- trunk/examples/simple-example/src/main/java/org/codehaus/waffle/example/simple/SimpleMonitor.java 2007-11-16 08:37:03 UTC (rev 387) +++ trunk/examples/simple-example/src/main/java/org/codehaus/waffle/example/simple/SimpleMonitor.java 2007-11-16 08:55:53 UTC (rev 388) @@ -11,8 +11,8 @@ * We want to shouw that we can change all monitor levels to INFO */ @Override - protected Map<String, Level> eventLevels(){ - Map<String, Level> levels = super.eventLevels(); + protected Map<String, Level> monitorLevels(){ + Map<String, Level> levels = super.monitorLevels(); for ( String key : levels.keySet() ){ levels.put(key, Level.INFO); }
To unsubscribe from this list please visit:
