Author: jverhaeg(a)redhat.com
Date: 2008-10-31 17:38:00 -0400 (Fri, 31 Oct 2008)
New Revision: 611
Added:
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/CapturedActivityInfo.java
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/UnlocalizedActivityInfo.java
trunk/dna-common/src/main/java/org/jboss/dna/common/util/EmptyIterator.java
trunk/dna-common/src/test/java/org/jboss/dna/common/monitor/CapturedActivityInfoTest.java
Modified:
trunk/dna-common/src/main/java/org/jboss/dna/common/CommonI18n.java
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/ActivityMonitor.java
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/ActivityMonitorWrapper.java
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/ActivityStatus.java
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/SimpleActivityMonitor.java
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/SubActivityMonitor.java
trunk/dna-common/src/main/java/org/jboss/dna/common/util/CheckArg.java
trunk/dna-common/src/main/resources/org/jboss/dna/common/CommonI18n.properties
trunk/dna-common/src/test/java/org/jboss/dna/common/i18n/MockI18n.java
trunk/dna-common/src/test/java/org/jboss/dna/common/monitor/ActivityStatusTest.java
trunk/dna-common/src/test/java/org/jboss/dna/common/monitor/SimpleActivityMonitorTest.java
trunk/dna-common/src/test/resources/org/jboss/dna/common/i18n/MockI18n.properties
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/StreamSequencerAdapterTest.java
trunk/extensions/dna-sequencer-xml/src/main/java/org/jboss/dna/sequencer/xml/XmlSequencer.java
Log:
DNA-244: Changed ActivityMonitor to now support capturing of information, including
markers, errors, and warnings, that can be later retrieved via the ActivityStatus.
Modified: trunk/dna-common/src/main/java/org/jboss/dna/common/CommonI18n.java
===================================================================
--- trunk/dna-common/src/main/java/org/jboss/dna/common/CommonI18n.java 2008-10-31
20:09:32 UTC (rev 610)
+++ trunk/dna-common/src/main/java/org/jboss/dna/common/CommonI18n.java 2008-10-31
21:38:00 UTC (rev 611)
@@ -42,58 +42,51 @@
public static I18n i18nFieldNotStatic;
public static I18n i18nLocalizationFileNotFound;
public static I18n i18nLocalizationProblems;
- public static I18n i18nRequiredToSuppliedParameterMismatch;
-
- /**
- * Parameters:
- * <ol>
- * <li>{@link I18n#id() Property}</li>
- * <li>Localization file URL</li>
- * </ol>
- */
public static I18n i18nPropertyDuplicate;
public static I18n i18nPropertyMissing;
public static I18n i18nPropertyUnused;
+ public static I18n i18nRequiredToSuppliedParameterMismatch;
// Core-related fields
- public static I18n argumentMayNotBeLessThan;
+ public static I18n activityMonitorBeginTask;
+ public static I18n activityMonitorStatus;
+ public static I18n argumentDidNotContainKey;
+ public static I18n argumentDidNotContainObject;
+ public static I18n argumentMayNotBeEmpty;
public static I18n argumentMayNotBeGreaterThan;
+ public static I18n argumentMayNotBeLessThan;
+ public static I18n argumentMayNotBeNegative;
+ public static I18n argumentMayNotBeNull;
+ public static I18n argumentMayNotBeNullOrZeroLength;
+ public static I18n argumentMayNotBeNullOrZeroLengthOrEmpty;
+ public static I18n argumentMayNotBePositive;
+ public static I18n argumentMayNotContainNullValue;
+ public static I18n argumentMustBeEmpty;
+ public static I18n argumentMustBeEquals;
public static I18n argumentMustBeGreaterThan;
- public static I18n argumentMustBeLessThan;
public static I18n argumentMustBeGreaterThanOrEqualTo;
+ public static I18n argumentMustBeInstanceOf;
+ public static I18n argumentMustBeLessThan;
public static I18n argumentMustBeLessThanOrEqualTo;
- public static I18n argumentMayNotBeNegative;
- public static I18n argumentMayNotBePositive;
public static I18n argumentMustBeNegative;
- public static I18n argumentMustBePositive;
- public static I18n argumentMustBeNumber;
- public static I18n argumentMayNotBeNullOrZeroLength;
- public static I18n argumentMayNotBeNullOrZeroLengthOrEmpty;
- public static I18n argumentMayNotBeNull;
public static I18n argumentMustBeNull;
- public static I18n argumentMustBeInstanceOf;
+ public static I18n argumentMustBeNumber;
+ public static I18n argumentMustBeOfMaximumSize;
+ public static I18n argumentMustBeOfMinimumSize;
+ public static I18n argumentMustBePositive;
public static I18n argumentMustBeSameAs;
- public static I18n argumentMustNotBeSameAs;
- public static I18n argumentMustBeEquals;
public static I18n argumentMustNotBeEquals;
- public static I18n argumentMayNotBeEmpty;
- public static I18n argumentDidNotContainObject;
- public static I18n argumentDidNotContainKey;
- public static I18n argumentMayNotContainNullValue;
- public static I18n argumentMustBeOfMinimumSize;
- public static I18n argumentMustBeOfMaximumSize;
+ public static I18n argumentMustNotBeSameAs;
public static I18n componentClassnameNotValid;
public static I18n componentNotConfigured;
public static I18n dateParsingFailure;
public static I18n initialActivityMonitorTaskName;
public static I18n nullActivityMonitorTaskName;
public static I18n pathAncestorDegreeIsInvalid;
+ public static I18n pathCannotBeNormalized;
public static I18n pathIsAlreadyAbsolute;
public static I18n pathIsNotAbsolute;
public static I18n pathIsNotRelative;
- public static I18n pathCannotBeNormalized;
- public static I18n activityMonitorBeginTask;
- public static I18n activityMonitorStatus;
public static I18n requiredToSuppliedParameterMismatch;
static {
Modified:
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/ActivityMonitor.java
===================================================================
---
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/ActivityMonitor.java 2008-10-31
20:09:32 UTC (rev 610)
+++
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/ActivityMonitor.java 2008-10-31
21:38:00 UTC (rev 611)
@@ -23,8 +23,9 @@
package org.jboss.dna.common.monitor;
import java.util.Locale;
-import org.jboss.dna.common.collection.Problems;
import org.jboss.dna.common.i18n.I18n;
+import org.jboss.dna.common.util.Logger;
+import org.slf4j.Marker;
/**
* A basic activity monitor that facilitates the updating and monitoring of progress
towards the completion of an activity.
@@ -41,6 +42,15 @@
* cancelled before its normal completion, the <strong>Updater</strong> must
deny any previous cancellation request by calling
* {@link #setCancelled(boolean) setCancelled(false)}.
* </p>
+ * <h2>Events</h2>
+ * <p>
+ * The <strong>Updater</strong> may {@link #capture(Marker, I18n, Object...)
capture} information related to an activity,
+ * including errors encountered, similar to using a {@link Logger}. However, instead of
being written to a log, this information
+ * are merely collected so that it can be later {@link
ActivityStatus#getCapturedInformation() retrieved}. This is especially
+ * useful when the activity involves using an API that doesn't provide the ability to
collect or return one or more errors or
+ * warnings that may have occurred during the activity. Implementations of the API can
get around this deficiency using this
+ * activity monitor to store these issues so that they can be dealt with after the API
call has completed.
+ * </p>
*
* @author Randall Hauch
* @author John Verhaeg
@@ -53,13 +63,135 @@
*
* @param totalWork the total number of work units for the task
* @param name the name of the task
- * @param params the parameters for localization
+ * @param messageParameters the parameters for localization
*/
void beginTask( double totalWork,
I18n name,
- Object... params );
+ Object... messageParameters );
/**
+ * Captures an event that occurred during this activity.
+ *
+ * @param message a message representing the event.
+ * @param messageParameters parameter values that are to replace the placeholders in
the message
+ */
+ public void capture( I18n message,
+ Object... messageParameters );
+
+ /**
+ * Captures an event that occurred during this activity.
+ *
+ * @param marker an identifying marker
+ * @param message a message representing the event
+ * @param messageParameters parameter values that are to replace the placeholders in
the message
+ */
+ public void capture( Marker marker,
+ I18n message,
+ Object... messageParameters );
+
+ /**
+ * Captures an error that occurred during this activity.
+ *
+ * @param throwable the error.
+ */
+ public void captureError( Throwable throwable );
+
+ /**
+ * Captures an error that occurred during this activity.
+ *
+ * @param message a message describing the error.
+ * @param messageParameters parameter values that are to replace the placeholders in
the message
+ */
+ public void captureError( I18n message,
+ Object... messageParameters );
+
+ /**
+ * Captures an error that occurred during this activity.
+ *
+ * @param marker an identifying marker
+ * @param message a message describing the error.
+ * @param messageParameters parameter values that are to replace the placeholders in
the message
+ */
+ public void captureError( Marker marker,
+ I18n message,
+ Object... messageParameters );
+
+ /**
+ * Captures an error that occurred during this activity.
+ *
+ * @param throwable the error.
+ * @param message a message describing the error.
+ * @param messageParameters parameter values that are to replace the placeholders in
the message
+ */
+ public void captureError( Throwable throwable,
+ I18n message,
+ Object... messageParameters );
+
+ /**
+ * Captures an error that occurred during this activity.
+ *
+ * @param marker an identifying marker
+ * @param throwable the error.
+ * @param message a message describing the error.
+ * @param messageParameters parameter values that are to replace the placeholders in
the message
+ */
+ public void captureError( Marker marker,
+ Throwable throwable,
+ I18n message,
+ Object... messageParameters );
+
+ /**
+ * Captures a warning that occurred during this activity.
+ *
+ * @param throwable the warning.
+ */
+ public void captureWarning( Throwable throwable );
+
+ /**
+ * Captures a warning that occurred during this activity.
+ *
+ * @param message a message describing the warning.
+ * @param messageParameters parameter values that are to replace the placeholders in
the message
+ */
+ public void captureWarning( I18n message,
+ Object... messageParameters );
+
+ /**
+ * Captures a warning that occurred during this activity.
+ *
+ * @param marker an identifying marker
+ * @param message a message describing the warning.
+ * @param messageParameters parameter values that are to replace the placeholders in
the message
+ */
+ public void captureWarning( Marker marker,
+ I18n message,
+ Object... messageParameters );
+
+ /**
+ * Captures a warning that occurred during this activity.
+ *
+ * @param throwable the warning.
+ * @param message a message describing the warning.
+ * @param messageParameters parameter values that are to replace the placeholders in
the message
+ */
+ public void captureWarning( Throwable throwable,
+ I18n message,
+ Object... messageParameters );
+
+ /**
+ * Captures a warning that occurred during this activity.
+ *
+ * @param marker an identifying marker
+ * @param throwable the warning.
+ * @param message a message describing the warning.
+ * @param messageParameters parameter values that are to replace the placeholders in
the message
+ */
+ public void captureWarning( Marker marker,
+ Throwable throwable,
+ I18n message,
+ Object... messageParameters );
+
+ /**
* Called by the <strong>Updater</strong> to create a subtask with the
given about of work. The resulting activity monitor
* must be started ({@link #beginTask(double, I18n, Object...)}) and finished ({@link
#done()}).
*
@@ -75,8 +207,8 @@
void done();
/**
- * Get the name of the activity using the default locale. This should never change
for a activity monitor, and all
- * {@link #createSubtask(double) subtasks} should have the same name.
+ * Get the name of the activity using the {@link Locale#getDefault() default locale}.
This should never change for a activity
+ * monitor, and all {@link #createSubtask(double) subtasks} should have the same
name.
*
* @return the activity's name; never <code>null</code>
* @see #getActivityName(Locale)
@@ -87,28 +219,29 @@
* Returns the name of the activity using the supplied locale. This should never
change for a activity monitor, and all
* {@link #createSubtask(double) subtasks} should have the same name.
*
- * @param locale the locale in which the name is to be represented; if null, the
{@link Locale#getDefault() default locale}
- * will be used
+ * @param locale the locale in which the name is to be represented; if
<code>null</code>, the {@link Locale#getDefault()
+ * default locale} will be used
* @return the activity's name; never <code>null</code>
- * @see #getActivityName()
*/
String getActivityName( Locale locale );
/**
- * Return the problems encountered during the {@link #getStatus(Locale) progress}
made towards completing the associated
- * {@link #getActivityName() activity}.
+ * Return the current status of this activity, localized to the {@link
Locale#getDefault() default locale}. This method
+ * returns an immutable but consistent snapshot of the status for this activity. Note
that if this instance is a
+ * {@link #createSubtask(double) subtask} , this method returns the status of the
subtask.
*
- * @return the list of problems
+ * @return the status of this activity
+ * @see #getStatus(Locale)
*/
- Problems getProblems();
+ ActivityStatus getStatus();
/**
- * Return the current status of this activity, localized to the specified locale.
This method returns an immutable but
+ * Return the current status of this activity, localized to the supplied locale. This
method returns an immutable but
* consistent snapshot of the status for this activity. Note that if this instance is
a {@link #createSubtask(double) subtask}
* , this method returns the status of the subtask.
*
- * @param locale the locale in which the status is to be represented; if null, the
{@link Locale#getDefault() default locale}
- * will be used
+ * @param locale the locale in which the status is to be represented; if
<code>null</code>, the {@link Locale#getDefault()
+ * default locale} will be used
* @return the status of this activity
*/
ActivityStatus getStatus( Locale locale );
Modified:
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/ActivityMonitorWrapper.java
===================================================================
---
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/ActivityMonitorWrapper.java 2008-10-31
20:09:32 UTC (rev 610)
+++
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/ActivityMonitorWrapper.java 2008-10-31
21:38:00 UTC (rev 611)
@@ -23,8 +23,8 @@
package org.jboss.dna.common.monitor;
import java.util.Locale;
-import org.jboss.dna.common.collection.Problems;
import org.jboss.dna.common.i18n.I18n;
+import org.slf4j.Marker;
/**
* The thread safety of this class is determined by the delegate.
@@ -54,6 +54,140 @@
/**
* {@inheritDoc}
*
+ * @see
org.jboss.dna.common.monitor.ActivityMonitor#capture(org.jboss.dna.common.i18n.I18n,
java.lang.Object[])
+ */
+ public void capture( I18n message,
+ Object... parameters ) {
+ delegate.capture(message, parameters);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.common.monitor.ActivityMonitor#capture(org.slf4j.Marker,
org.jboss.dna.common.i18n.I18n,
+ * java.lang.Object[])
+ */
+ public void capture( Marker marker,
+ I18n message,
+ Object... parameters ) {
+ delegate.capture(marker, message, parameters);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see
org.jboss.dna.common.monitor.ActivityMonitor#captureError(java.lang.Throwable)
+ */
+ public void captureError( Throwable throwable ) {
+ delegate.captureError(throwable);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see
org.jboss.dna.common.monitor.ActivityMonitor#captureError(org.jboss.dna.common.i18n.I18n,
java.lang.Object[])
+ */
+ public void captureError( I18n message,
+ Object... parameters ) {
+ delegate.captureError(message, parameters);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.common.monitor.ActivityMonitor#captureError(org.slf4j.Marker,
org.jboss.dna.common.i18n.I18n,
+ * java.lang.Object[])
+ */
+ public void captureError( Marker marker,
+ I18n message,
+ Object... parameters ) {
+ delegate.captureError(marker, message, parameters);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see
org.jboss.dna.common.monitor.ActivityMonitor#captureError(java.lang.Throwable,
org.jboss.dna.common.i18n.I18n,
+ * java.lang.Object[])
+ */
+ public void captureError( Throwable throwable,
+ I18n message,
+ Object... parameters ) {
+ delegate.captureError(throwable, message, parameters);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.common.monitor.ActivityMonitor#captureError(org.slf4j.Marker,
java.lang.Throwable,
+ * org.jboss.dna.common.i18n.I18n, java.lang.Object[])
+ */
+ public void captureError( Marker marker,
+ Throwable throwable,
+ I18n message,
+ Object... parameters ) {
+ delegate.captureError(marker, throwable, message, parameters);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see
org.jboss.dna.common.monitor.ActivityMonitor#captureWarning(java.lang.Throwable)
+ */
+ public void captureWarning( Throwable throwable ) {
+ delegate.captureWarning(throwable);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see
org.jboss.dna.common.monitor.ActivityMonitor#captureWarning(org.jboss.dna.common.i18n.I18n,
java.lang.Object[])
+ */
+ public void captureWarning( I18n message,
+ Object... parameters ) {
+ delegate.captureWarning(message, parameters);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.common.monitor.ActivityMonitor#captureWarning(org.slf4j.Marker,
org.jboss.dna.common.i18n.I18n,
+ * java.lang.Object[])
+ */
+ public void captureWarning( Marker marker,
+ I18n message,
+ Object... parameters ) {
+ delegate.captureWarning(marker, message, parameters);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see
org.jboss.dna.common.monitor.ActivityMonitor#captureWarning(java.lang.Throwable,
org.jboss.dna.common.i18n.I18n,
+ * java.lang.Object[])
+ */
+ public void captureWarning( Throwable throwable,
+ I18n message,
+ Object... parameters ) {
+ delegate.captureWarning(throwable, message, parameters);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.common.monitor.ActivityMonitor#captureWarning(org.slf4j.Marker,
java.lang.Throwable,
+ * org.jboss.dna.common.i18n.I18n, java.lang.Object[])
+ */
+ public void captureWarning( Marker marker,
+ Throwable throwable,
+ I18n message,
+ Object... parameters ) {
+ delegate.captureWarning(marker, throwable, message, parameters);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
* @see org.jboss.dna.common.monitor.ActivityMonitor#createSubtask(double)
*/
public ActivityMonitor createSubtask( double subtaskWork ) {
@@ -90,10 +224,10 @@
/**
* {@inheritDoc}
*
- * @see org.jboss.dna.common.monitor.ActivityMonitor#getProblems()
+ * @see org.jboss.dna.common.monitor.ActivityMonitor#getStatus()
*/
- public Problems getProblems() {
- return delegate.getProblems();
+ public ActivityStatus getStatus() {
+ return delegate.getStatus();
}
/**
Modified: trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/ActivityStatus.java
===================================================================
---
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/ActivityStatus.java 2008-10-31
20:09:32 UTC (rev 610)
+++
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/ActivityStatus.java 2008-10-31
21:38:00 UTC (rev 611)
@@ -24,7 +24,11 @@
import java.io.Serializable;
import java.text.DecimalFormat;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
import net.jcip.annotations.Immutable;
+import org.jboss.dna.common.i18n.I18n;
import org.jboss.dna.common.util.StringUtil;
/**
@@ -67,45 +71,76 @@
private final double percentWorked;
private final boolean done;
private final boolean cancelled;
- private final String message;
+ private final String taskName;
+ private final CapturedActivityInfo[] capturedInformation;
/**
* Create the activity status.
*
- * @param activityName the name of the activity, which may not be
<code>null</code>
- * @param message the message for the status, which may not be
<code>null</code>
+ * @param activityName the name of the activity; must not be
<code>null</code>
+ * @param activityNameParameters the parameters for
<code>activityName</code>
+ * @param taskName the i18n template for the name of the task being performed within
the activity; must not be
+ * <code>null</code>
+ * @param taskNameParameters the parameters for <code>taskName</code>
* @param percentWorked the percentage worked, ranging from 0.0 for not started to
100.0 for complete; a negative value are
* treated as 0.0, while a value greater than 100.0 is treated as 100.0
* @param cancelled <code>true</code> if the activity has been requested
to be cancelled, or <code>false</code> otherwise
+ * @param capturedInformation the captured activity information; must not be
<code>null</code>
+ * @param locale the locale in which the status is to be represented; if
<code>null</code>, the {@link Locale#getDefault()
+ * default locale} will be used
*/
- public ActivityStatus( String activityName,
- String message,
- double percentWorked,
- boolean cancelled ) {
+ ActivityStatus( I18n activityName,
+ Object[] activityNameParameters,
+ I18n taskName,
+ Object[] taskNameParameters,
+ double percentWorked,
+ boolean cancelled,
+ List<UnlocalizedActivityInfo> capturedInformation,
+ Locale locale ) {
assert activityName != null;
- assert message != null;
- this.activityName = activityName;
+ assert capturedInformation != null;
+ assert taskName != null || taskNameParameters == null ||
taskNameParameters.length == 0;
+ this.activityName = activityName.text(locale, activityNameParameters);
this.done = percentWorked >= 100.0d;
this.percentWorked = this.done ? 100.0d : (percentWorked <= 0.0d ? 0.0d :
percentWorked);
- this.message = message;
+ this.taskName = taskName == null ? "" : taskName.text(locale,
taskNameParameters);
this.cancelled = cancelled;
+ this.capturedInformation = new CapturedActivityInfo[capturedInformation.size()];
+ Iterator<UnlocalizedActivityInfo> iter = capturedInformation.iterator();
+ for (int ndx = 0; iter.hasNext(); ndx++) {
+ UnlocalizedActivityInfo info = iter.next();
+ this.capturedInformation[ndx] = new CapturedActivityInfo(info.type,
info.taskName, info.taskNameParameters,
+ info.marker,
info.throwable, info.message,
+
info.messageParameters, locale);
+ }
}
/**
* Create the activity status and compute the percentage worked.
*
- * @param activityName the name of the activity, which may not be null
- * @param message the message for the status, which may not be null
+ * @param activityName the name of the activity; must not be
<code>null</code>
+ * @param activityNameParameters the parameters for
<code>activityName</code>
+ * @param taskName the i18n template for the name of the task being performed within
the activity; must not be
+ * <code>null</code>
+ * @param taskNameParameters the parameters for <code>taskName</code>
* @param workedSoFar the amount of work so far percentage worked
* @param totalWork the total amount of work for this activity
* @param cancelled true if the activity has been requested to be cancelled, or false
otherwise
+ * @param capturedInformation the captured activity information; must not be
<code>null</code>
+ * @param locale the locale in which the status is to be represented; if
<code>null</code>, the {@link Locale#getDefault()
+ * default locale} will be used
*/
- public ActivityStatus( String activityName,
- String message,
- double workedSoFar,
- double totalWork,
- boolean cancelled ) {
- this(activityName, message, computePercentage(workedSoFar, totalWork),
cancelled);
+ ActivityStatus( I18n activityName,
+ Object[] activityNameParameters,
+ I18n taskName,
+ Object[] taskNameParameters,
+ double workedSoFar,
+ double totalWork,
+ boolean cancelled,
+ List<UnlocalizedActivityInfo> capturedInformation,
+ Locale locale ) {
+ this(activityName, activityNameParameters, taskName, taskNameParameters,
computePercentage(workedSoFar, totalWork),
+ cancelled, capturedInformation, locale);
}
/**
@@ -117,6 +152,10 @@
return this.activityName;
}
+ public CapturedActivityInfo[] getCapturedInformation() {
+ return capturedInformation;
+ }
+
/**
* Get the progress as a percentage of the total work that's been completed.
*
@@ -127,12 +166,12 @@
}
/**
- * Get the activity monitor's text message.
+ * Get the activity monitor's task name.
*
- * @return the text message
+ * @return the task name
*/
- public String getMessage() {
- return this.message;
+ public String getTaskName() {
+ return taskName;
}
/**
@@ -163,7 +202,7 @@
String percentage = new
DecimalFormat(PERCENTAGE_PATTERN).format(getPercentWorked());
percentage = StringUtil.justifyRight(percentage, PERCENTAGE_PATTERN.length(),
' ');
String cancelled = this.isCancelled() ? " (cancelled)" : "";
- return this.activityName + " (" + this.message + ") " +
percentage + " %" + cancelled;
+ return activityName + " (" + taskName + ") " + percentage +
" %" + cancelled;
}
/**
Added:
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/CapturedActivityInfo.java
===================================================================
--- trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/CapturedActivityInfo.java
(rev 0)
+++
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/CapturedActivityInfo.java 2008-10-31
21:38:00 UTC (rev 611)
@@ -0,0 +1,177 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.dna.common.monitor;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
+import net.jcip.annotations.Immutable;
+import org.jboss.dna.common.i18n.I18n;
+import org.jboss.dna.common.util.CheckArg;
+import org.jboss.dna.common.util.Logger;
+import org.slf4j.Marker;
+
+/**
+ * @author jverhaeg
+ */
+@Immutable
+public final class CapturedActivityInfo {
+
+ private final Logger.Level type;
+ private final String taskName;
+ private final Marker marker;
+ private final Throwable throwable;
+ private final String message;
+
+ CapturedActivityInfo( Logger.Level type,
+ I18n taskName,
+ Object[] taskNameParameters,
+ final Marker marker,
+ Throwable throwable,
+ I18n message,
+ Object[] messageParameters,
+ Locale locale ) {
+ assert type != null;
+ assert taskName != null || taskNameParameters == null ||
taskNameParameters.length == 0;
+ assert message != null || messageParameters == null || messageParameters.length
== 0;
+ this.type = type;
+ this.taskName = taskName == null ? "" : taskName.text(locale,
taskNameParameters);
+ this.marker = marker == null ? null : new ImmutableMarker(marker);
+ this.throwable = throwable;
+ this.message = message == null ? "" : message.text(locale,
messageParameters);
+ }
+
+ /**
+ * Returns the identifying marker associated with this information.
+ *
+ * @return the marker
+ */
+ public Marker getMarker() {
+ return marker;
+ }
+
+ /**
+ * Returns the message associated with this information localized to the {@link
ActivityMonitor#getStatus(Locale) supplied
+ * locale}.
+ *
+ * @return the message
+ */
+ public String getMessage() {
+ if (message == null) {
+ if (throwable == null) return null;
+ return throwable.getMessage();
+ }
+ return message;
+ }
+
+ /**
+ * Returns the name of the task, localized to the {@link
ActivityMonitor#getStatus(Locale) supplied locale}, that was being
+ * performed when this information was captured.
+ *
+ * @return the task name
+ */
+ public String getTaskName() {
+ return taskName;
+ }
+
+ /**
+ * Returns the throwable associated with this information.
+ *
+ * @return the throwable
+ */
+ public Throwable getThrowable() {
+ return throwable;
+ }
+
+ /**
+ * @return <code>true</code> if this information represents an error.
+ */
+ public boolean isError() {
+ return (type == Logger.Level.ERROR);
+ }
+
+ /**
+ * @return <code>true</code> if this information represents a warning.
+ */
+ public boolean isWarning() {
+ return (type == Logger.Level.WARNING);
+ }
+
+ @Immutable
+ private final class ImmutableMarker implements Marker {
+
+ private static final long serialVersionUID = 1L;
+
+ private final String name;
+ private final List<ImmutableMarker> children = new
ArrayList<ImmutableMarker>();
+
+ ImmutableMarker( Marker marker ) {
+ name = marker.getName();
+ for (Iterator<?> iter = marker.iterator(); iter.hasNext();) {
+ children.add(new ImmutableMarker((Marker)iter.next()));
+ }
+ }
+
+ public void add( Marker child ) {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean contains( Marker that ) {
+ CheckArg.isNotNull(that, "that");
+ if (this == that) return true;
+ for (ImmutableMarker marker : children) {
+ if (marker.contains(that)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public boolean contains( String name ) {
+ CheckArg.isNotNull(name, "name");
+ if (this.name.equals(name)) return true;
+ for (ImmutableMarker marker : children) {
+ if (marker.contains(name)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public boolean hasChildren() {
+ return !children.isEmpty();
+ }
+
+ public Iterator<?> iterator() {
+ return children.iterator();
+ }
+
+ public boolean remove( Marker child ) {
+ throw new UnsupportedOperationException();
+ }
+ }
+}
Property changes on:
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/CapturedActivityInfo.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/SimpleActivityMonitor.java
===================================================================
---
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/SimpleActivityMonitor.java 2008-10-31
20:09:32 UTC (rev 610)
+++
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/SimpleActivityMonitor.java 2008-10-31
21:38:00 UTC (rev 611)
@@ -22,16 +22,19 @@
package org.jboss.dna.common.monitor;
+import java.util.List;
import java.util.Locale;
+import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import net.jcip.annotations.GuardedBy;
import net.jcip.annotations.ThreadSafe;
-import org.jboss.dna.common.collection.Problems;
-import org.jboss.dna.common.collection.ThreadSafeProblems;
import org.jboss.dna.common.i18n.I18n;
import org.jboss.dna.common.util.CheckArg;
+import org.jboss.dna.common.util.Logger;
+import org.jboss.dna.common.util.Logger.Level;
+import org.slf4j.Marker;
/**
* A basic activity monitor.
@@ -40,30 +43,30 @@
* @author John Verhaeg
*/
@ThreadSafe
-public class SimpleActivityMonitor implements ActivityMonitor {
+public final class SimpleActivityMonitor implements ActivityMonitor {
@GuardedBy( "lock" )
private I18n taskName;
@GuardedBy( "lock" )
- private Object[] taskNameParams;
+ private Object[] taskNameParameters;
@GuardedBy( "lock" )
private double totalWork;
@GuardedBy( "lock" )
private double worked;
private final I18n activityName;
- private final Object[] activityNameParams;
+ private final Object[] activityNameParameters;
private final ReadWriteLock lock = new ReentrantReadWriteLock();
private final AtomicBoolean cancelled = new AtomicBoolean(false);
- private final Problems problems = new ThreadSafeProblems();
+ private final List<UnlocalizedActivityInfo> capturedInformation = new
CopyOnWriteArrayList<UnlocalizedActivityInfo>();
public SimpleActivityMonitor( I18n activityName,
Object... params ) {
CheckArg.isNotNull(activityName, "activityName");
this.activityName = activityName;
- this.activityNameParams = params;
+ this.activityNameParameters = params;
this.taskName = null;
- this.taskNameParams = null;
+ this.taskNameParameters = null;
}
/**
@@ -72,13 +75,16 @@
* @see org.jboss.dna.common.monitor.ActivityMonitor#beginTask(double,
org.jboss.dna.common.i18n.I18n, java.lang.Object[])
*/
public void beginTask( double totalWork,
- I18n name,
- Object... params ) {
+ I18n taskName,
+ Object... taskNameParameters ) {
CheckArg.isGreaterThan(totalWork, 0.0, "totalWork");
+ if (taskName == null && taskNameParameters != null) {
+ CheckArg.isEmpty(taskNameParameters, "taskNameParameters");
+ }
try {
this.lock.writeLock().lock();
- this.taskName = name;
- this.taskNameParams = params;
+ this.taskName = taskName;
+ this.taskNameParameters = taskNameParameters;
this.totalWork = totalWork;
this.worked = 0.0d;
} finally {
@@ -89,10 +95,157 @@
/**
* {@inheritDoc}
*
+ * @see
org.jboss.dna.common.monitor.ActivityMonitor#capture(org.jboss.dna.common.i18n.I18n,
java.lang.Object[])
+ */
+ public void capture( I18n message,
+ Object... messageParameters ) {
+ capture(null, message, messageParameters);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.common.monitor.ActivityMonitor#capture(org.slf4j.Marker,
org.jboss.dna.common.i18n.I18n,
+ * java.lang.Object[])
+ */
+ public void capture( Marker marker,
+ I18n message,
+ Object... messageParameters ) {
+ capture(Level.INFO, marker, null, message, messageParameters);
+ }
+
+ private void capture( Logger.Level type,
+ Marker marker,
+ Throwable throwable,
+ I18n message,
+ Object... messageParameters ) {
+ assert type != null;
+ if (message == null && messageParameters != null) {
+ CheckArg.isEmpty(messageParameters, "messageParameters");
+ }
+ capturedInformation.add(new UnlocalizedActivityInfo(type, taskName,
taskNameParameters, marker, null, message,
+ messageParameters));
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see
org.jboss.dna.common.monitor.ActivityMonitor#captureError(java.lang.Throwable)
+ */
+ public void captureError( Throwable throwable ) {
+ captureError(throwable, null);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see
org.jboss.dna.common.monitor.ActivityMonitor#captureError(org.jboss.dna.common.i18n.I18n,
java.lang.Object[])
+ */
+ public void captureError( I18n message,
+ Object... messageParameters ) {
+ captureError(null, null, message, messageParameters);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.common.monitor.ActivityMonitor#captureError(org.slf4j.Marker,
org.jboss.dna.common.i18n.I18n,
+ * java.lang.Object[])
+ */
+ public void captureError( Marker marker,
+ I18n message,
+ Object... messageParameters ) {
+ captureError(marker, null, message, messageParameters);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see
org.jboss.dna.common.monitor.ActivityMonitor#captureError(java.lang.Throwable,
org.jboss.dna.common.i18n.I18n,
+ * java.lang.Object[])
+ */
+ public void captureError( Throwable throwable,
+ I18n message,
+ Object... messageParameters ) {
+ captureError(null, throwable, message, messageParameters);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.common.monitor.ActivityMonitor#captureError(org.slf4j.Marker,
java.lang.Throwable,
+ * org.jboss.dna.common.i18n.I18n, java.lang.Object[])
+ */
+ public void captureError( Marker marker,
+ Throwable throwable,
+ I18n message,
+ Object... messageParameters ) {
+ capture(Level.ERROR, marker, throwable, message, messageParameters);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see
org.jboss.dna.common.monitor.ActivityMonitor#captureWarning(java.lang.Throwable)
+ */
+ public void captureWarning( Throwable throwable ) {
+ captureWarning(throwable, null);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see
org.jboss.dna.common.monitor.ActivityMonitor#captureWarning(org.jboss.dna.common.i18n.I18n,
java.lang.Object[])
+ */
+ public void captureWarning( I18n message,
+ Object... messageParameters ) {
+ captureWarning(null, null, message, messageParameters);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.common.monitor.ActivityMonitor#captureWarning(org.slf4j.Marker,
org.jboss.dna.common.i18n.I18n,
+ * java.lang.Object[])
+ */
+ public void captureWarning( Marker marker,
+ I18n message,
+ Object... messageParameters ) {
+ captureWarning(marker, null, message, messageParameters);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see
org.jboss.dna.common.monitor.ActivityMonitor#captureWarning(java.lang.Throwable,
org.jboss.dna.common.i18n.I18n,
+ * java.lang.Object[])
+ */
+ public void captureWarning( Throwable throwable,
+ I18n message,
+ Object... messageParameters ) {
+ captureWarning(null, throwable, message, messageParameters);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.common.monitor.ActivityMonitor#captureWarning(org.slf4j.Marker,
java.lang.Throwable,
+ * org.jboss.dna.common.i18n.I18n, java.lang.Object[])
+ */
+ public void captureWarning( Marker marker,
+ Throwable throwable,
+ I18n message,
+ Object... messageParameters ) {
+ capture(Level.WARNING, marker, throwable, message, messageParameters);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
* @see org.jboss.dna.common.monitor.ActivityMonitor#createSubtask(double)
*/
public ActivityMonitor createSubtask( double subtaskWork ) {
- return new SubActivityMonitor(this, subtaskWork);
+ return new SubActivityMonitor(this, activityName, activityNameParameters,
subtaskWork, capturedInformation);
}
/**
@@ -130,20 +283,16 @@
* @see
org.jboss.dna.common.monitor.ActivityMonitor#getActivityName(java.util.Locale)
*/
public String getActivityName( Locale locale ) {
- return activityName.text(locale == null ? Locale.getDefault() : locale,
activityNameParams);
+ return activityName.text(locale, activityNameParameters);
}
/**
* {@inheritDoc}
- * <p>
- * Problems must only be added by the {@link ActivityMonitor
<strong>Updater</strong>}, and accessed by
- * {@link ActivityMonitor Observers} only after the activity has been {@link #done()
completed}.
- * </p>
*
- * @see org.jboss.dna.common.monitor.ActivityMonitor#getProblems()
+ * @see org.jboss.dna.common.monitor.ActivityMonitor#getStatus()
*/
- public Problems getProblems() {
- return problems;
+ public ActivityStatus getStatus() {
+ return getStatus(null);
}
/**
@@ -153,12 +302,11 @@
*/
public ActivityStatus getStatus( Locale locale ) {
try {
- this.lock.readLock().lock();
- String localizedTaskName = this.taskName == null ? "" :
this.taskName.text(locale, this.taskNameParams);
- return new ActivityStatus(this.getActivityName(locale), localizedTaskName,
this.worked, this.totalWork,
- this.isCancelled());
+ lock.readLock().lock();
+ return new ActivityStatus(activityName, activityNameParameters, taskName,
taskNameParameters, worked, totalWork,
+ isCancelled(), capturedInformation, locale);
} finally {
- this.lock.readLock().unlock();
+ lock.readLock().unlock();
}
}
Modified:
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/SubActivityMonitor.java
===================================================================
---
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/SubActivityMonitor.java 2008-10-31
20:09:32 UTC (rev 610)
+++
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/SubActivityMonitor.java 2008-10-31
21:38:00 UTC (rev 611)
@@ -22,27 +22,26 @@
package org.jboss.dna.common.monitor;
+import java.util.List;
import java.util.Locale;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import net.jcip.annotations.GuardedBy;
-import org.jboss.dna.common.collection.Problems;
+import net.jcip.annotations.ThreadSafe;
import org.jboss.dna.common.i18n.I18n;
+import org.slf4j.Marker;
/**
- * This class is thread-safe except when accessing or adding {@link #getProblems()
problems}. Problems must only be added by the
- * {@link ActivityMonitor <strong>Updater</strong>}, and accessed by {@link
ActivityMonitor Observers} only after the activity has
- * been {@link #done() completed}.
- *
* @author Randall Hauch
* @author John Verhaeg
*/
-public class SubActivityMonitor implements ActivityMonitor {
+@ThreadSafe
+class SubActivityMonitor implements ActivityMonitor {
@GuardedBy( "lock" )
private I18n taskName;
@GuardedBy( "lock" )
- private Object[] params;
+ private Object[] taskNameParameters;
@GuardedBy( "lock" )
private double totalWork;
@GuardedBy( "lock" )
@@ -52,14 +51,25 @@
private final double subtaskTotalInParent;
private final ActivityMonitor parent;
+ private final I18n activityName;
+ private final Object[] activityNameParameters;
private final ReadWriteLock lock = new ReentrantReadWriteLock();
+ private final List<UnlocalizedActivityInfo> capturedInformation;
- public SubActivityMonitor( final ActivityMonitor parent,
- final double subtaskTotalInParent ) {
+ SubActivityMonitor( final ActivityMonitor parent,
+ final I18n activityName,
+ final Object[] activityNameParameters,
+ final double subtaskTotalInParent,
+ List<UnlocalizedActivityInfo> capturedInformation ) {
assert subtaskTotalInParent > 0;
assert parent != null;
+ assert activityName != null;
+ this.activityName = activityName;
+ this.activityNameParameters = activityNameParameters;
+ assert capturedInformation != null;
this.parent = parent;
this.subtaskTotalInParent = subtaskTotalInParent;
+ this.capturedInformation = capturedInformation;
}
/**
@@ -74,7 +84,7 @@
try {
this.lock.writeLock().lock();
this.taskName = name;
- this.params = params;
+ this.taskNameParameters = params;
this.totalWork = totalWork;
this.parentWorkScaleFactor = ((float)subtaskTotalInParent) /
((float)totalWork);
} finally {
@@ -85,10 +95,144 @@
/**
* {@inheritDoc}
*
+ * @see
org.jboss.dna.common.monitor.ActivityMonitor#capture(org.jboss.dna.common.i18n.I18n,
java.lang.Object[])
+ */
+ public void capture( I18n message,
+ Object... parameters ) {
+ parent.capture(message, parameters);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.common.monitor.ActivityMonitor#capture(org.slf4j.Marker,
org.jboss.dna.common.i18n.I18n,
+ * java.lang.Object[])
+ */
+ public void capture( Marker marker,
+ I18n message,
+ Object... parameters ) {
+ parent.capture(marker, message, parameters);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see
org.jboss.dna.common.monitor.ActivityMonitor#captureError(java.lang.Throwable)
+ */
+ public void captureError( Throwable throwable ) {
+ parent.captureError(throwable);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see
org.jboss.dna.common.monitor.ActivityMonitor#captureError(org.jboss.dna.common.i18n.I18n,
java.lang.Object[])
+ */
+ public void captureError( I18n message,
+ Object... parameters ) {
+ parent.captureError(message, parameters);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.common.monitor.ActivityMonitor#captureError(org.slf4j.Marker,
org.jboss.dna.common.i18n.I18n,
+ * java.lang.Object[])
+ */
+ public void captureError( Marker marker,
+ I18n message,
+ Object... parameters ) {
+ parent.captureError(marker, message, parameters);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see
org.jboss.dna.common.monitor.ActivityMonitor#captureError(java.lang.Throwable,
org.jboss.dna.common.i18n.I18n,
+ * java.lang.Object[])
+ */
+ public void captureError( Throwable throwable,
+ I18n message,
+ Object... parameters ) {
+ parent.captureError(throwable, message, parameters);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.common.monitor.ActivityMonitor#captureError(org.slf4j.Marker,
java.lang.Throwable,
+ * org.jboss.dna.common.i18n.I18n, java.lang.Object[])
+ */
+ public void captureError( Marker marker,
+ Throwable throwable,
+ I18n message,
+ Object... parameters ) {
+ parent.captureError(marker, throwable, message, parameters);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see
org.jboss.dna.common.monitor.ActivityMonitor#captureWarning(java.lang.Throwable)
+ */
+ public void captureWarning( Throwable throwable ) {
+ parent.captureWarning(throwable);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see
org.jboss.dna.common.monitor.ActivityMonitor#captureWarning(org.jboss.dna.common.i18n.I18n,
java.lang.Object[])
+ */
+ public void captureWarning( I18n message,
+ Object... parameters ) {
+ parent.captureWarning(message, parameters);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.common.monitor.ActivityMonitor#captureWarning(org.slf4j.Marker,
org.jboss.dna.common.i18n.I18n,
+ * java.lang.Object[])
+ */
+ public void captureWarning( Marker marker,
+ I18n message,
+ Object... parameters ) {
+ parent.captureWarning(marker, message, parameters);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see
org.jboss.dna.common.monitor.ActivityMonitor#captureWarning(java.lang.Throwable,
org.jboss.dna.common.i18n.I18n,
+ * java.lang.Object[])
+ */
+ public void captureWarning( Throwable throwable,
+ I18n message,
+ Object... parameters ) {
+ parent.captureWarning(throwable, message, parameters);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.common.monitor.ActivityMonitor#captureWarning(org.slf4j.Marker,
java.lang.Throwable,
+ * org.jboss.dna.common.i18n.I18n, java.lang.Object[])
+ */
+ public void captureWarning( Marker marker,
+ Throwable throwable,
+ I18n message,
+ Object... parameters ) {
+ parent.captureWarning(marker, throwable, message, parameters);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
* @see org.jboss.dna.common.monitor.ActivityMonitor#createSubtask(double)
*/
public ActivityMonitor createSubtask( double subtaskWork ) {
- return new SubActivityMonitor(this, subtaskWork);
+ return new SubActivityMonitor(this, activityName, activityNameParameters,
subtaskWork, capturedInformation);
}
/**
@@ -138,10 +282,10 @@
/**
* {@inheritDoc}
*
- * @see org.jboss.dna.common.monitor.ActivityMonitor#getProblems()
+ * @see org.jboss.dna.common.monitor.ActivityMonitor#getStatus()
*/
- public Problems getProblems() {
- return parent.getProblems();
+ public ActivityStatus getStatus() {
+ return getStatus(null);
}
/**
@@ -151,11 +295,11 @@
*/
public ActivityStatus getStatus( Locale locale ) {
try {
- this.lock.readLock().lock();
- return new ActivityStatus(getActivityName(), this.taskName.text(locale,
this.params), this.submittedToParent,
- this.subtaskTotalInParent, this.isCancelled());
+ lock.readLock().lock();
+ return new ActivityStatus(activityName, activityNameParameters, taskName,
taskNameParameters, submittedToParent,
+ subtaskTotalInParent, isCancelled(),
capturedInformation, locale);
} finally {
- this.lock.readLock().unlock();
+ lock.readLock().unlock();
}
}
Added:
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/UnlocalizedActivityInfo.java
===================================================================
---
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/UnlocalizedActivityInfo.java
(rev 0)
+++
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/UnlocalizedActivityInfo.java 2008-10-31
21:38:00 UTC (rev 611)
@@ -0,0 +1,59 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.dna.common.monitor;
+
+import net.jcip.annotations.Immutable;
+import org.jboss.dna.common.i18n.I18n;
+import org.jboss.dna.common.util.Logger;
+import org.slf4j.Marker;
+
+/**
+ * @author jverhaeg
+ */
+@Immutable
+class UnlocalizedActivityInfo {
+
+ final Logger.Level type;
+ final I18n taskName;
+ final Object[] taskNameParameters;
+ final Marker marker;
+ final Throwable throwable;
+ final I18n message;
+ final Object[] messageParameters;
+
+ UnlocalizedActivityInfo( Logger.Level type,
+ I18n taskName,
+ Object[] taskNameParameters,
+ Marker marker,
+ Throwable throwable,
+ I18n message,
+ Object[] messageParameters ) {
+ assert type != null;
+ this.type = type;
+ this.taskName = taskName;
+ this.taskNameParameters = taskNameParameters;
+ this.marker = marker;
+ this.throwable = throwable;
+ this.message = message;
+ this.messageParameters = messageParameters;
+ }
+}
Property changes on:
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/UnlocalizedActivityInfo.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/dna-common/src/main/java/org/jboss/dna/common/util/CheckArg.java
===================================================================
--- trunk/dna-common/src/main/java/org/jboss/dna/common/util/CheckArg.java 2008-10-31
20:09:32 UTC (rev 610)
+++ trunk/dna-common/src/main/java/org/jboss/dna/common/util/CheckArg.java 2008-10-31
21:38:00 UTC (rev 611)
@@ -588,6 +588,21 @@
}
/**
+ * Check that the array is empty
+ *
+ * @param argument Array
+ * @param name The name of the argument
+ * @throws IllegalArgumentException If array is not empty
+ */
+ public static void isEmpty( Object[] argument,
+ String name ) {
+ isNotNull(argument, name);
+ if (argument.length > 0) {
+ throw new
IllegalArgumentException(CommonI18n.argumentMustBeEmpty.text(name));
+ }
+ }
+
+ /**
* Check that the array is not empty
*
* @param argument Array
Added: trunk/dna-common/src/main/java/org/jboss/dna/common/util/EmptyIterator.java
===================================================================
--- trunk/dna-common/src/main/java/org/jboss/dna/common/util/EmptyIterator.java
(rev 0)
+++ trunk/dna-common/src/main/java/org/jboss/dna/common/util/EmptyIterator.java 2008-10-31
21:38:00 UTC (rev 611)
@@ -0,0 +1,59 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.dna.common.util;
+
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
+/**
+ * @author jverhaeg
+ * @param <T> some type
+ */
+public final class EmptyIterator<T> implements Iterator<T> {
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.util.Iterator#hasNext()
+ */
+ public boolean hasNext() {
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.util.Iterator#next()
+ */
+ public T next() {
+ throw new NoSuchElementException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.util.Iterator#remove()
+ */
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+}
Property changes on:
trunk/dna-common/src/main/java/org/jboss/dna/common/util/EmptyIterator.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/dna-common/src/main/resources/org/jboss/dna/common/CommonI18n.properties
===================================================================
---
trunk/dna-common/src/main/resources/org/jboss/dna/common/CommonI18n.properties 2008-10-31
20:09:32 UTC (rev 610)
+++
trunk/dna-common/src/main/resources/org/jboss/dna/common/CommonI18n.properties 2008-10-31
21:38:00 UTC (rev 611)
@@ -37,42 +37,43 @@
i18nRequiredToSuppliedParameterMismatch = Internationalization field "{0}" in
{1}: {2}
# Core-related fields
+activityMonitorBeginTask = Beginning {0} ({1})
+activityMonitorStatus = {0}
+argumentDidNotContainKey = "The {0} argument did not contain the expected key {1}
+argumentDidNotContainObject = "The {0} argument did not contain the expected object
{1}
+argumentMayNotBeEmpty = The {0} argument may not be empty
argumentMayNotBeGreaterThan = The {0} argument value, {1}, may not be greater than {2}
argumentMayNotBeLessThan = The {0} argument value, {1}, may not be less than {2}
+argumentMayNotBeNegative = The {0} argument value, {1}, may not be negative
+argumentMayNotBeNull = The {0} argument may not be null
+argumentMayNotBeNullOrZeroLength = The {0} argument may not be null or zero-length
+argumentMayNotBeNullOrZeroLengthOrEmpty = The {0} argument may not be empty or contain
only whitespace
+argumentMayNotBePositive = The {0} argument value, {1}, may not be positive
+argumentMayNotContainNullValue = The {0} argument may not contain a null value (first
null found at position {1})
+argumentMustBeEmpty = The {0} argument must be empty.
+argumentMustBeEquals = The {0} argument is not equal to {1}
argumentMustBeGreaterThan = The {0} argument value, {1}, must be greater than {2}
+argumentMustBeGreaterThanOrEqualTo = The {0} argument value, {1}, must be greater than or
equal to {2}
+argumentMustBeInstanceOf = The {0} argument was an instance of {1} but was expected to be
an instance of {2}
argumentMustBeLessThan = The {0} argument value, {1}, must be less than {2}
-argumentMustBeGreaterThanOrEqualTo = The {0} argument value, {1}, must be greater than or
equal to {2}
argumentMustBeLessThanOrEqualTo = The {0} argument value, {1}, must be less than or equal
to {2}
-argumentMayNotBeNegative = The {0} argument value, {1}, may not be negative
-argumentMayNotBePositive = The {0} argument value, {1}, may not be positive
argumentMustBeNegative = The {0} argument value, {1}, must be negative
+argumentMustBeNull = The {0} argument must be null
+argumentMustBeNumber = The {0} argument value must be a number
+argumentMustBeOfMaximumSize = The {0} argument is a {1} with {2} elements but must have
no more than {3}
+argumentMustBeOfMinimumSize = The {0} argument is a {1} with {2} elements but must have
at least {3}
argumentMustBePositive = The {0} argument value, {1}, must be positive
-argumentMustBeNumber = The {0} argument value must be a number
-argumentMayNotBeNullOrZeroLength = The {0} argument may not be null or zero-length
-argumentMayNotBeNullOrZeroLengthOrEmpty = The {0} argument may not be empty or contain
only whitespace
-argumentMayNotBeNull = The {0} argument may not be null
-argumentMustBeNull = The {0} argument must be null
-argumentMustBeInstanceOf = The {0} argument was an instance of {1} but was expected to be
an instance of {2}
argumentMustBeSameAs = The {0} argument is not the same as "{1}"
+argumentMustNotBeEquals = The {0} argument is equal to {1}
argumentMustNotBeSameAs = The {0} argument is the same as "{1}"
-argumentMustBeEquals = The {0} argument is not equal to {1}
-argumentMustNotBeEquals = The {0} argument is equal to {1}
-argumentMayNotBeEmpty = The {0} argument may not be empty
-argumentDidNotContainObject = "The {0} argument did not contain the expected object
{1}
-argumentDidNotContainKey = "The {0} argument did not contain the expected key {1}
-argumentMayNotContainNullValue = The {0} argument may not contain a null value (first
null found at position {1})
-argumentMustBeOfMinimumSize = The {0} argument is a {1} with {2} elements but must have
at least {3}
-argumentMustBeOfMaximumSize = The {0} argument is a {1} with {2} elements but must have
no more than {3}
componentClassnameNotValid = The class name {0} specified for {1} is not a valid Java
class name
componentNotConfigured = The component {0} was not configured and will not be used
dateParsingFailure = Unable to parse the date "{0}" using the standard ISO 8601
format
initialActivityMonitorTaskName =
nullActivityMonitorTaskName = Not available
pathAncestorDegreeIsInvalid = Unable to obtain the {1} ancestor for {0}
+pathCannotBeNormalized = The path {0} is invalid and cannot be normalized
pathIsAlreadyAbsolute = The path {0} is already an absolute path
pathIsNotAbsolute = The path {0} is not an absolute path
pathIsNotRelative = The path {0} is not a relative path
-pathCannotBeNormalized = The path {0} is invalid and cannot be normalized
-activityMonitorBeginTask = Beginning {0} ({1})
-activityMonitorStatus = {0}
requiredToSuppliedParameterMismatch = {0} parameter{1} supplied, but {2} parameter{3}
required: "{4}" => "{5}"
Modified: trunk/dna-common/src/test/java/org/jboss/dna/common/i18n/MockI18n.java
===================================================================
--- trunk/dna-common/src/test/java/org/jboss/dna/common/i18n/MockI18n.java 2008-10-31
20:09:32 UTC (rev 610)
+++ trunk/dna-common/src/test/java/org/jboss/dna/common/i18n/MockI18n.java 2008-10-31
21:38:00 UTC (rev 611)
@@ -34,5 +34,6 @@
}
}
+ public static I18n noPlaceholders;
public static I18n passthrough;
}
Modified:
trunk/dna-common/src/test/java/org/jboss/dna/common/monitor/ActivityStatusTest.java
===================================================================
---
trunk/dna-common/src/test/java/org/jboss/dna/common/monitor/ActivityStatusTest.java 2008-10-31
20:09:32 UTC (rev 610)
+++
trunk/dna-common/src/test/java/org/jboss/dna/common/monitor/ActivityStatusTest.java 2008-10-31
21:38:00 UTC (rev 611)
@@ -25,6 +25,11 @@
import static org.hamcrest.core.Is.is;
import static org.hamcrest.number.IsCloseTo.closeTo;
import static org.junit.Assert.assertThat;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+import org.jboss.dna.common.i18n.MockI18n;
+import org.jboss.dna.common.util.Logger;
import org.junit.Before;
import org.junit.Test;
@@ -34,18 +39,56 @@
*/
public class ActivityStatusTest {
+ private static final String VALID_ACTIVITY_NAME = "Reading from file X";
+ private static final String VALID_TASK_NAME = "Checking for file";
+
private ActivityStatus status;
- private String validActivityName;
- private String validTaskName;
+ private List<UnlocalizedActivityInfo> infos;
@Before
public void beforeEach() {
- this.validActivityName = "Reading from file X";
- this.validTaskName = "Checking for file";
- this.status = new ActivityStatus(this.validActivityName, this.validTaskName,
10.0d, false);
+ infos = new ArrayList<UnlocalizedActivityInfo>();
+ infos.add(new UnlocalizedActivityInfo(Logger.Level.INFO, null, null, null, null,
null, null));
+ this.status = new ActivityStatus(MockI18n.passthrough, new Object[]
{VALID_ACTIVITY_NAME}, MockI18n.passthrough,
+ new Object[] {VALID_TASK_NAME}, 10.0d, false,
infos, Locale.US);
}
+ @Test( expected = AssertionError.class )
+ public void shouldNotAllowNoActivityName() {
+ new ActivityStatus(null, new Object[] {VALID_ACTIVITY_NAME},
MockI18n.passthrough, new Object[] {VALID_TASK_NAME}, 10.0d,
+ false, infos, Locale.US);
+ }
+
@Test
+ public void shouldAllowNoActivityNameParameters() {
+ new ActivityStatus(MockI18n.noPlaceholders, null, MockI18n.passthrough, new
Object[] {VALID_TASK_NAME}, 10.0d, false,
+ infos, Locale.US);
+ }
+
+ @Test
+ public void shouldAllowNoTaskName() {
+ new ActivityStatus(MockI18n.passthrough, new Object[] {VALID_ACTIVITY_NAME},
null, null, 10.0d, false, infos, Locale.US);
+ }
+
+ @Test( expected = AssertionError.class )
+ public void shouldNotAllowTaskNameParametersWithNoTaskName() {
+ new ActivityStatus(MockI18n.passthrough, new Object[] {VALID_ACTIVITY_NAME},
null, new Object[] {VALID_TASK_NAME}, 10.0d,
+ false, infos, Locale.US);
+ }
+
+ @Test( expected = AssertionError.class )
+ public void shouldNotAllowNoCapturedActivityInformation() {
+ new ActivityStatus(MockI18n.passthrough, new Object[] {VALID_ACTIVITY_NAME},
MockI18n.passthrough,
+ new Object[] {VALID_TASK_NAME}, 10.0d, false, null,
Locale.US);
+ }
+
+ @Test
+ public void shouldAllowNoLocale() {
+ new ActivityStatus(MockI18n.passthrough, new Object[] {VALID_ACTIVITY_NAME},
MockI18n.passthrough,
+ new Object[] {VALID_TASK_NAME}, 10.0d, false, infos, null);
+ }
+
+ @Test
public void shouldComputePercentageAs100PercentIfWithinPrecision() {
assertThat(ActivityStatus.computePercentage(100.0d -
(ActivityStatus.PERCENT_PRECISION / 2.0d), 100.0d),
is(closeTo(100.0d, ActivityStatus.PERCENT_PRECISION)));
@@ -60,7 +103,21 @@
@Test
public void shouldHaveToStringThatIncludesPercentage() {
- // System.out.println(this.status);
assertThat(this.status.toString().indexOf("10.0 %") > 0, is(true));
}
+
+ @Test
+ public void shouldProvideCapturedActivityInforation() {
+ assertThat(status.getCapturedInformation().length > 0, is(true));
+ }
+
+ @Test
+ public void shouldProvideActivityName() {
+ assertThat(status.getActivityName(), is(VALID_ACTIVITY_NAME));
+ }
+
+ @Test
+ public void shouldProvideTaskName() {
+ assertThat(status.getTaskName(), is(VALID_TASK_NAME));
+ }
}
Added:
trunk/dna-common/src/test/java/org/jboss/dna/common/monitor/CapturedActivityInfoTest.java
===================================================================
---
trunk/dna-common/src/test/java/org/jboss/dna/common/monitor/CapturedActivityInfoTest.java
(rev 0)
+++
trunk/dna-common/src/test/java/org/jboss/dna/common/monitor/CapturedActivityInfoTest.java 2008-10-31
21:38:00 UTC (rev 611)
@@ -0,0 +1,148 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.dna.common.monitor;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNull.notNullValue;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.stub;
+import java.util.Locale;
+import org.jboss.dna.common.i18n.MockI18n;
+import org.jboss.dna.common.util.EmptyIterator;
+import org.jboss.dna.common.util.Logger.Level;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.MockitoAnnotations;
+import org.mockito.MockitoAnnotations.Mock;
+import org.slf4j.Marker;
+
+/**
+ * @author jverhaeg
+ */
+public final class CapturedActivityInfoTest {
+
+ private CapturedActivityInfo info;
+ @Mock
+ Marker marker;
+
+ @Before
+ public void before() {
+ MockitoAnnotations.initMocks(this);
+ stub(marker.iterator()).toReturn(new EmptyIterator<Marker>());
+ info = new CapturedActivityInfo(Level.INFO, MockI18n.passthrough, new Object[]
{"task"}, marker, new Throwable(),
+ MockI18n.passthrough, new Object[]
{"message"}, Locale.US);
+ }
+
+ @Test( expected = AssertionError.class )
+ public void shouldNotAllowNoType() {
+ new CapturedActivityInfo(null, MockI18n.passthrough, new Object[]
{"task"}, marker, new Throwable(),
+ MockI18n.passthrough, new Object[]
{"message"}, Locale.US);
+ }
+
+ @Test
+ public void shouldAllowNoTaskName() {
+ new CapturedActivityInfo(Level.INFO, null, null, marker, new Throwable(),
MockI18n.passthrough, new Object[] {"message"},
+ Locale.US);
+ }
+
+ @Test
+ public void shouldAllowNoTaskNameParameters() {
+ new CapturedActivityInfo(Level.INFO, null, null, marker, new Throwable(),
MockI18n.noPlaceholders, null, Locale.US);
+ }
+
+ @Test( expected = AssertionError.class )
+ public void shouldNotAllowTaskNameParametersWithNoTaskName() {
+ new CapturedActivityInfo(Level.INFO, null, new Object[] {"task"},
marker, new Throwable(), MockI18n.passthrough,
+ new Object[] {"message"}, Locale.US);
+ }
+
+ @Test
+ public void shouldAllowNoMarker() {
+ new CapturedActivityInfo(Level.INFO, MockI18n.passthrough, new Object[]
{"task"}, null, new Throwable(),
+ MockI18n.passthrough, new Object[]
{"message"}, Locale.US);
+ }
+
+ @Test
+ public void shouldAllowNoThrowable() {
+ new CapturedActivityInfo(Level.INFO, MockI18n.passthrough, new Object[]
{"task"}, marker, null, MockI18n.passthrough,
+ new Object[] {"message"}, Locale.US);
+ }
+
+ @Test
+ public void shouldAllowNoMessage() {
+ new CapturedActivityInfo(Level.INFO, MockI18n.passthrough, new Object[]
{"task"}, marker, new Throwable(), null, null,
+ Locale.US);
+ }
+
+ @Test
+ public void shouldAllowNoMessageParameters() {
+ new CapturedActivityInfo(Level.INFO, MockI18n.passthrough, new Object[]
{"task"}, marker, new Throwable(),
+ MockI18n.noPlaceholders, null, Locale.US);
+ }
+
+ @Test( expected = AssertionError.class )
+ public void shouldNotAllowMessageParametersWithNoMessage() {
+ new CapturedActivityInfo(Level.INFO, MockI18n.passthrough, new Object[]
{"task"}, marker, new Throwable(), null,
+ new Object[] {"message"}, Locale.US);
+ }
+
+ @Test
+ public void shouldAllowNoLocale() {
+ new CapturedActivityInfo(Level.INFO, MockI18n.passthrough, new Object[]
{"task"}, marker, new Throwable(),
+ MockI18n.passthrough, new Object[]
{"message"}, null);
+ }
+
+ @Test
+ public void shouldProvideMarker() {
+ assertThat(info.getMarker(), notNullValue());
+ }
+
+ @Test
+ public void shouldProvideMessage() {
+ assertThat(info.getMessage(), is("message"));
+ }
+
+ @Test
+ public void shouldProvideTaskName() {
+ assertThat(info.getTaskName(), is("task"));
+ }
+
+ @Test
+ public void shouldProvideThrowable() {
+ assertThat(info.getThrowable(), notNullValue());
+ }
+
+ @Test
+ public void shouldIndicateType() {
+ assertThat(info.isError(), is(false));
+ assertThat(info.isWarning(), is(false));
+ CapturedActivityInfo info = new CapturedActivityInfo(Level.ERROR, null, null,
null, null, null, null, null);
+ assertThat(info.isError(), is(true));
+ assertThat(info.isWarning(), is(false));
+ info = new CapturedActivityInfo(Level.WARNING, null, null, null, null, null,
null, null);
+ assertThat(info.isError(), is(false));
+ assertThat(info.isWarning(), is(true));
+ info = new CapturedActivityInfo(Level.DEBUG, null, null, null, null, null, null,
null);
+ assertThat(info.isError(), is(false));
+ assertThat(info.isWarning(), is(false));
+ }
+}
Property changes on:
trunk/dna-common/src/test/java/org/jboss/dna/common/monitor/CapturedActivityInfoTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/dna-common/src/test/java/org/jboss/dna/common/monitor/SimpleActivityMonitorTest.java
===================================================================
---
trunk/dna-common/src/test/java/org/jboss/dna/common/monitor/SimpleActivityMonitorTest.java 2008-10-31
20:09:32 UTC (rev 610)
+++
trunk/dna-common/src/test/java/org/jboss/dna/common/monitor/SimpleActivityMonitorTest.java 2008-10-31
21:38:00 UTC (rev 611)
@@ -28,13 +28,18 @@
import static org.hamcrest.core.IsSame.sameInstance;
import static org.hamcrest.number.IsCloseTo.closeTo;
import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.stub;
import java.util.Locale;
import java.util.Set;
import org.jboss.dna.common.CommonI18n;
import org.jboss.dna.common.i18n.I18n;
import org.jboss.dna.common.i18n.MockI18n;
+import org.jboss.dna.common.util.EmptyIterator;
import org.junit.Before;
import org.junit.Test;
+import org.mockito.MockitoAnnotations;
+import org.mockito.MockitoAnnotations.Mock;
+import org.slf4j.Marker;
/**
* @author Randall Hauch
@@ -45,9 +50,13 @@
private static final String VALID_TASK_NAME = "Checking for file";
private ActivityMonitor monitor;
+ @Mock
+ Marker marker;
@Before
public void beforeEach() {
+ MockitoAnnotations.initMocks(this);
+ stub(marker.iterator()).toReturn(new EmptyIterator<Marker>());
this.monitor = new SimpleActivityMonitor(MockI18n.passthrough, "Reading from
file X");
}
@@ -60,12 +69,12 @@
public void shouldReturnActivityStatusWithEmptyMessageBeforeTaskIsBegun() {
ActivityStatus status = monitor.getStatus(Locale.FRANCE);
assertThat(status, is(notNullValue()));
- assertThat(status.getMessage(), is(""));
+ assertThat(status.getTaskName(), is(""));
assertThat(status.getPercentWorked(), is(closeTo(0.0d, 0.001d)));
status = monitor.getStatus(null);
assertThat(status, is(notNullValue()));
- assertThat(status.getMessage(), is(""));
+ assertThat(status.getTaskName(), is(""));
assertThat(status.getPercentWorked(), is(closeTo(0.0d, 0.001d)));
}
@@ -75,22 +84,22 @@
monitor.worked(10.0d);
ActivityStatus status = monitor.getStatus(Locale.FRANCE);
assertThat(status, is(notNullValue()));
- assertThat(status.getMessage(), is("examinez le message"));
+ assertThat(status.getTaskName(), is("examinez le message"));
assertThat(status.getPercentWorked(), is(closeTo(10.0d, 0.001d)));
status = monitor.getStatus(Locale.ENGLISH);
assertThat(status, is(notNullValue()));
- assertThat(status.getMessage(), is("test task"));
+ assertThat(status.getTaskName(), is("test task"));
assertThat(status.getPercentWorked(), is(closeTo(10.0d, 0.001d)));
status = monitor.getStatus(Locale.getDefault());
assertThat(status, is(notNullValue()));
- assertThat(status.getMessage(), is("test task"));
+ assertThat(status.getTaskName(), is("test task"));
assertThat(status.getPercentWorked(), is(closeTo(10.0d, 0.001d)));
status = monitor.getStatus(null);
assertThat(status, is(notNullValue()));
- assertThat(status.getMessage(), is("test task"));
+ assertThat(status.getTaskName(), is("test task"));
assertThat(status.getPercentWorked(), is(closeTo(10.0d, 0.001d)));
}
@@ -100,22 +109,22 @@
monitor.worked(10.0d);
ActivityStatus status = monitor.getStatus(Locale.FRANCE);
assertThat(status, is(notNullValue()));
- assertThat(status.getMessage(), is("examinez le message 2"));
+ assertThat(status.getTaskName(), is("examinez le message 2"));
assertThat(status.getPercentWorked(), is(closeTo(10.0d, 0.001d)));
status = monitor.getStatus(Locale.ENGLISH);
assertThat(status, is(notNullValue()));
- assertThat(status.getMessage(), is("second test task 2"));
+ assertThat(status.getTaskName(), is("second test task 2"));
assertThat(status.getPercentWorked(), is(closeTo(10.0d, 0.001d)));
status = monitor.getStatus(Locale.getDefault());
assertThat(status, is(notNullValue()));
- assertThat(status.getMessage(), is("second test task 2"));
+ assertThat(status.getTaskName(), is("second test task 2"));
assertThat(status.getPercentWorked(), is(closeTo(10.0d, 0.001d)));
status = monitor.getStatus(null);
assertThat(status, is(notNullValue()));
- assertThat(status.getMessage(), is("second test task 2"));
+ assertThat(status.getTaskName(), is("second test task 2"));
assertThat(status.getPercentWorked(), is(closeTo(10.0d, 0.001d)));
}
@@ -124,7 +133,7 @@
ActivityStatus status = monitor.getStatus(null);
assertThat(status, is(notNullValue()));
assertThat(status.getActivityName(), is(monitor.getActivityName()));
- assertThat(status.getMessage(), is(""));
+ assertThat(status.getTaskName(), is(""));
assertThat(status.getPercentWorked(), is(closeTo(0.0d, 0.001d)));
}
@@ -134,7 +143,7 @@
ActivityStatus status = monitor.getStatus(null);
assertThat(status, is(notNullValue()));
assertThat(status.getActivityName(), is(monitor.getActivityName()));
- assertThat(status.getMessage(), is(VALID_TASK_NAME));
+ assertThat(status.getTaskName(), is(VALID_TASK_NAME));
assertThat(status.getPercentWorked(), is(closeTo(0.0d, 0.001d)));
}
@@ -144,7 +153,7 @@
ActivityStatus status = monitor.getStatus(null);
assertThat(status, is(notNullValue()));
assertThat(status.getActivityName(), is(monitor.getActivityName()));
- assertThat(status.getMessage(), is(VALID_TASK_NAME));
+ assertThat(status.getTaskName(), is(VALID_TASK_NAME));
assertThat(status.getPercentWorked(), is(closeTo(0.0d, 0.001d)));
for (int i = 1; i <= 9; ++i) {
this.monitor.worked(100);
@@ -152,7 +161,7 @@
status = monitor.getStatus(null);
assertThat(status, is(notNullValue()));
assertThat(status.getActivityName(), is(monitor.getActivityName()));
- assertThat(status.getMessage(), is(VALID_TASK_NAME));
+ assertThat(status.getTaskName(), is(VALID_TASK_NAME));
assertThat(status.getPercentWorked(), is(closeTo(10 * i, 0.001d)));
assertThat(status.isDone(), is(false));
}
@@ -161,7 +170,7 @@
status = monitor.getStatus(null);
assertThat(status, is(notNullValue()));
assertThat(status.getActivityName(), is(monitor.getActivityName()));
- assertThat(status.getMessage(), is(VALID_TASK_NAME));
+ assertThat(status.getTaskName(), is(VALID_TASK_NAME));
assertThat(status.getPercentWorked(), is(closeTo(100, 0.001d)));
assertThat(status.isDone(), is(true));
}
@@ -172,7 +181,7 @@
ActivityStatus status = monitor.getStatus(null);
assertThat(status, is(notNullValue()));
assertThat(status.getActivityName(), is(monitor.getActivityName()));
- assertThat(status.getMessage(), is(VALID_TASK_NAME));
+ assertThat(status.getTaskName(), is(VALID_TASK_NAME));
assertThat(status.getPercentWorked(), is(closeTo(0.0d, 0.001d)));
// Create subtasks ...
@@ -192,7 +201,7 @@
status = subtask.getStatus(null);
assertThat(status, is(notNullValue()));
assertThat(status.getActivityName(), is(monitor.getActivityName()));
- assertThat(status.getMessage(), is(subtaskName));
+ assertThat(status.getTaskName(), is(subtaskName));
assertThat(status.getPercentWorked(), is(closeTo(10 * j, 0.001d)));
assertThat(status.isDone(), is(j == 10));
@@ -204,7 +213,7 @@
status = monitor.getStatus(null);
assertThat(status, is(notNullValue()));
assertThat(status.getActivityName(), is(monitor.getActivityName()));
- assertThat(status.getMessage(), is(VALID_TASK_NAME));
+ assertThat(status.getTaskName(), is(VALID_TASK_NAME));
assertThat(status.getPercentWorked(), is(closeTo(10 * i, 0.001d)));
assertThat(status.isDone(), is(false));
}
@@ -214,7 +223,7 @@
status = monitor.getStatus(null);
assertThat(status, is(notNullValue()));
assertThat(status.getActivityName(), is(monitor.getActivityName()));
- assertThat(status.getMessage(), is(VALID_TASK_NAME));
+ assertThat(status.getTaskName(), is(VALID_TASK_NAME));
assertThat(status.getPercentWorked(), is(closeTo(100, 0.001d)));
assertThat(status.isDone(), is(true));
}
@@ -225,7 +234,7 @@
ActivityStatus status = monitor.getStatus(null);
assertThat(status, is(notNullValue()));
assertThat(status.getActivityName(), is(monitor.getActivityName()));
- assertThat(status.getMessage(), is(VALID_TASK_NAME));
+ assertThat(status.getTaskName(), is(VALID_TASK_NAME));
assertThat(status.getPercentWorked(), is(closeTo(0.0d, 0.001d)));
assertThat(status.isDone(), is(false));
@@ -237,7 +246,7 @@
status = monitor.getStatus(null);
assertThat(status, is(notNullValue()));
assertThat(status.getActivityName(), is(monitor.getActivityName()));
- assertThat(status.getMessage(), is(VALID_TASK_NAME));
+ assertThat(status.getTaskName(), is(VALID_TASK_NAME));
assertThat(status.getPercentWorked(), is(closeTo(100, 0.001d)));
assertThat(status.isDone(), is(true));
}
@@ -257,7 +266,7 @@
ActivityStatus status = monitor.getStatus(null);
assertThat(status, is(notNullValue()));
assertThat(status.getActivityName(), is(monitor.getActivityName()));
- assertThat(status.getMessage(), is(VALID_TASK_NAME));
+ assertThat(status.getTaskName(), is(VALID_TASK_NAME));
assertThat(status.getPercentWorked(), is(closeTo(0.0d, 0.001d)));
for (int i = 1; i <= 9; ++i) {
monitor.worked(100);
@@ -266,7 +275,7 @@
status = monitor.getStatus(null);
assertThat(status, is(notNullValue()));
assertThat(status.getActivityName(), is(monitor.getActivityName()));
- assertThat(status.getMessage(), is(VALID_TASK_NAME));
+ assertThat(status.getTaskName(), is(VALID_TASK_NAME));
assertThat(status.getPercentWorked(), is(closeTo(10 * i, 0.001d)));
assertThat(status.isDone(), is(false));
@@ -279,7 +288,7 @@
status = monitor.getStatus(null);
assertThat(status, is(notNullValue()));
assertThat(status.getActivityName(), is(monitor.getActivityName()));
- assertThat(status.getMessage(), is(VALID_TASK_NAME));
+ assertThat(status.getTaskName(), is(VALID_TASK_NAME));
assertThat(status.getPercentWorked(), is(closeTo(100, 0.001d)));
assertThat(status.isDone(), is(true));
@@ -291,7 +300,7 @@
ActivityStatus status = monitor.getStatus(null);
assertThat(status, is(notNullValue()));
assertThat(status.getActivityName(), is(monitor.getActivityName()));
- assertThat(status.getMessage(), is(VALID_TASK_NAME));
+ assertThat(status.getTaskName(), is(VALID_TASK_NAME));
assertThat(status.getPercentWorked(), is(closeTo(0.0d, 0.001d)));
for (int i = 1; i <= 9; ++i) {
monitor.worked(100);
@@ -300,7 +309,7 @@
status = monitor.getStatus(null);
assertThat(status, is(notNullValue()));
assertThat(status.getActivityName(), is(monitor.getActivityName()));
- assertThat(status.getMessage(), is(VALID_TASK_NAME));
+ assertThat(status.getTaskName(), is(VALID_TASK_NAME));
assertThat(status.getPercentWorked(), is(closeTo(10 * i, 0.001d)));
assertThat(status.isDone(), is(false));
@@ -313,20 +322,96 @@
status = monitor.getStatus(null);
assertThat(status, is(notNullValue()));
assertThat(status.getActivityName(), is(monitor.getActivityName()));
- assertThat(status.getMessage(), is(VALID_TASK_NAME));
+ assertThat(status.getTaskName(), is(VALID_TASK_NAME));
assertThat(status.getPercentWorked(), is(closeTo(100, 0.001d)));
assertThat(status.isDone(), is(true));
assertThat(monitor.isCancelled(), is(true));
}
@Test
- public void shouldRecordProblems() {
- monitor.beginTask(1000, MockI18n.passthrough, VALID_TASK_NAME);
- monitor.getProblems().addWarning(MockI18n.passthrough);
- monitor.done();
- assertThat(monitor.getProblems().hasWarnings(), is(true));
+ public void shouldAllowCaptureInformation() {
+ monitor.capture(MockI18n.passthrough, "Message");
+ assertThat(monitor.getStatus(Locale.getDefault()).getCapturedInformation().length
> 0, is(true));
}
+ @Test
+ public void shouldAllowCaptureInformationWithNoMessage() {
+ monitor.capture(null);
+ assertThat(monitor.getStatus(Locale.getDefault()).getCapturedInformation().length
> 0, is(true));
+ }
+
+ @Test( expected = IllegalArgumentException.class )
+ public void shouldNotAllowCaptureInformationWithNoMessageAndMessageParameters() {
+ monitor.capture(null, "message");
+ assertThat(monitor.getStatus(Locale.getDefault()).getCapturedInformation().length
> 0, is(true));
+ }
+
+ @Test
+ public void shouldAllowCaptureInformationWithMarker() {
+ monitor.capture(marker, null);
+ assertThat(monitor.getStatus(Locale.getDefault()).getCapturedInformation().length
> 0, is(true));
+ }
+
+ @Test
+ public void shouldAllowCaptureError() {
+ monitor.captureError(MockI18n.passthrough, "Error");
+ assertThat(monitor.getStatus(Locale.getDefault()).getCapturedInformation().length
> 0, is(true));
+ }
+
+ @Test
+ public void shouldAllowCaptureErrorWithNoMessage() {
+ monitor.captureError(null);
+ assertThat(monitor.getStatus(Locale.getDefault()).getCapturedInformation().length
> 0, is(true));
+ }
+
+ @Test( expected = IllegalArgumentException.class )
+ public void shouldNotAllowCaptureErrorWithNoMessageAndMessageParameters() {
+ monitor.captureError(null, "Error");
+ assertThat(monitor.getStatus(Locale.getDefault()).getCapturedInformation().length
> 0, is(true));
+ }
+
+ @Test
+ public void shouldAllowCaptureErrorWithMarker() {
+ monitor.captureError(marker, null);
+ assertThat(monitor.getStatus(Locale.getDefault()).getCapturedInformation().length
> 0, is(true));
+ }
+
+ @Test
+ public void shouldAllowCaptureErrorWithThrowable() {
+ monitor.captureError(new Throwable());
+ assertThat(monitor.getStatus(Locale.getDefault()).getCapturedInformation().length
> 0, is(true));
+ }
+
+ @Test
+ public void shouldAllowCaptureWarning() {
+ monitor.captureWarning(MockI18n.passthrough, "Warning");
+ assertThat(monitor.getStatus(Locale.getDefault()).getCapturedInformation().length
> 0, is(true));
+ }
+
+ @Test
+ public void shouldAllowCaptureWarningWithNoMessage() {
+ monitor.captureWarning(null);
+ assertThat(monitor.getStatus(Locale.getDefault()).getCapturedInformation().length
> 0, is(true));
+ }
+
+ @Test( expected = IllegalArgumentException.class )
+ public void shouldNotAllowCaptureWarningWithNoMessageAndMessageParameters() {
+ monitor.captureWarning(null, "Warning");
+ assertThat(monitor.getStatus(Locale.getDefault()).getCapturedInformation().length
> 0, is(true));
+ }
+
+ @Test
+ public void shouldAllowCaptureWarningWithMarker() {
+ monitor.captureWarning(marker, null);
+ assertThat(monitor.getStatus(Locale.getDefault()).getCapturedInformation().length
> 0, is(true));
+ }
+
+ @Test
+ public void shouldAllowCaptureWarningWithThrowable() {
+ monitor.captureWarning(new Throwable());
+ assertThat(monitor.getStatus(Locale.getDefault()).getCapturedInformation().length
> 0, is(true));
+ }
+
public static class I18nMessages {
public static I18n testTaskName;
Modified:
trunk/dna-common/src/test/resources/org/jboss/dna/common/i18n/MockI18n.properties
===================================================================
---
trunk/dna-common/src/test/resources/org/jboss/dna/common/i18n/MockI18n.properties 2008-10-31
20:09:32 UTC (rev 610)
+++
trunk/dna-common/src/test/resources/org/jboss/dna/common/i18n/MockI18n.properties 2008-10-31
21:38:00 UTC (rev 611)
@@ -1 +1,2 @@
+noPlaceholders = empty
passthrough = {0}
Modified:
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/StreamSequencerAdapterTest.java
===================================================================
---
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/StreamSequencerAdapterTest.java 2008-10-31
20:09:32 UTC (rev 610)
+++
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/StreamSequencerAdapterTest.java 2008-10-31
21:38:00 UTC (rev 611)
@@ -35,9 +35,9 @@
import javax.jcr.Node;
import javax.jcr.Session;
import javax.jcr.observation.Event;
-import org.jboss.dna.common.collection.Problem;
import org.jboss.dna.common.jcr.AbstractJcrRepositoryTest;
import org.jboss.dna.common.monitor.ActivityMonitor;
+import org.jboss.dna.common.monitor.CapturedActivityInfo;
import org.jboss.dna.common.monitor.RecordingActivityMonitor;
import org.jboss.dna.graph.properties.NamespaceRegistry;
import org.jboss.dna.graph.properties.Path;
@@ -129,7 +129,7 @@
}
}
- protected void testSequencer( final StreamSequencer sequencer ) throws Exception {
+ protected void testSequencer( final StreamSequencer sequencer ) throws Throwable {
StreamSequencer streamSequencer = new StreamSequencer() {
public void sequence( InputStream stream,
@@ -139,7 +139,7 @@
try {
sequencer.sequence(stream, output, context, activityMonitor);
} catch (AssertionError err) {
- activityMonitor.getProblems().addError(err, null);
+ activityMonitor.captureError(err);
}
}
};
@@ -155,8 +155,8 @@
outputPaths.add(new RepositoryNodePath(repositoryWorkspaceName,
outputNode.getPath()));
sequencerOutput.setProperty("alpha/beta", "isSomething",
true);
adapter.execute(inputNode, "sequencedProperty", nodeChange,
outputPaths, context, activityMonitor);
- for (Problem problem : activityMonitor.getProblems()) {
- throw (AssertionError)problem.getThrowable();
+ for (CapturedActivityInfo info :
activityMonitor.getStatus().getCapturedInformation()) {
+ if (info.isError()) throw info.getThrowable();
}
}
@@ -375,7 +375,7 @@
}
@Test
- public void shouldPassNonNullInputStreamToSequencer() throws Exception {
+ public void shouldPassNonNullInputStreamToSequencer() throws Throwable {
testSequencer(new StreamSequencer() {
public void sequence( InputStream stream,
@@ -388,7 +388,7 @@
}
@Test
- public void shouldPassNonNullSequencerOutputToSequencer() throws Exception {
+ public void shouldPassNonNullSequencerOutputToSequencer() throws Throwable {
testSequencer(new StreamSequencer() {
public void sequence( InputStream stream,
@@ -401,7 +401,7 @@
}
@Test
- public void shouldPassNonNullSequencerContextToSequencer() throws Exception {
+ public void shouldPassNonNullSequencerContextToSequencer() throws Throwable {
testSequencer(new StreamSequencer() {
public void sequence( InputStream stream,
@@ -414,7 +414,7 @@
}
@Test
- public void shouldPassNonNullActivityMonitorToSequencer() throws Exception {
+ public void shouldPassNonNullActivityMonitorToSequencer() throws Throwable {
testSequencer(new StreamSequencer() {
public void sequence( InputStream stream,
Modified:
trunk/extensions/dna-sequencer-xml/src/main/java/org/jboss/dna/sequencer/xml/XmlSequencer.java
===================================================================
---
trunk/extensions/dna-sequencer-xml/src/main/java/org/jboss/dna/sequencer/xml/XmlSequencer.java 2008-10-31
20:09:32 UTC (rev 610)
+++
trunk/extensions/dna-sequencer-xml/src/main/java/org/jboss/dna/sequencer/xml/XmlSequencer.java 2008-10-31
21:38:00 UTC (rev 611)
@@ -90,7 +90,7 @@
reader.parse(new InputSource(stream));
} catch (Exception error) {
context.getLogger(getClass()).error(error,
XmlSequencerI18n.fatalErrorSequencingXmlDocument, error);
- monitor.getProblems().addError(error,
XmlSequencerI18n.fatalErrorSequencingXmlDocument, error);
+ monitor.captureError(error, XmlSequencerI18n.fatalErrorSequencingXmlDocument,
error);
} finally {
monitor.done();
}
@@ -361,7 +361,7 @@
@Override
public void error( SAXParseException error ) {
context.getLogger(XmlSequencer.class).error(error,
XmlSequencerI18n.errorSequencingXmlDocument, error);
- monitor.getProblems().addError(error,
XmlSequencerI18n.errorSequencingXmlDocument, error);
+ monitor.captureError(error, XmlSequencerI18n.errorSequencingXmlDocument,
error);
}
/**
@@ -397,7 +397,7 @@
@Override
public void fatalError( SAXParseException error ) {
context.getLogger(XmlSequencer.class).error(error,
XmlSequencerI18n.fatalErrorSequencingXmlDocument, error);
- monitor.getProblems().addError(error,
XmlSequencerI18n.fatalErrorSequencingXmlDocument, error);
+ monitor.captureError(error, XmlSequencerI18n.fatalErrorSequencingXmlDocument,
error);
}
private Name getDefaultPrimaryType() {
@@ -688,7 +688,7 @@
@Override
public void warning( SAXParseException warning ) {
context.getLogger(XmlSequencer.class).warn(warning,
XmlSequencerI18n.warningSequencingXmlDocument);
- monitor.getProblems().addWarning(warning,
XmlSequencerI18n.warningSequencingXmlDocument, warning);
+ monitor.captureWarning(warning,
XmlSequencerI18n.warningSequencingXmlDocument, warning);
}
}