Author: jverhaeg(a)redhat.com
Date: 2008-10-29 16:09:42 -0400 (Wed, 29 Oct 2008)
New Revision: 599
Added:
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/LoggingActivityMonitor.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/test/java/org/jboss/dna/common/monitor/ActivityStatusTest.java
trunk/dna-common/src/test/java/org/jboss/dna/common/monitor/RecordingActivityMonitor.java
trunk/dna-common/src/test/java/org/jboss/dna/common/monitor/SimpleActivityMonitorTest.java
trunk/dna-common/src/test/resources/org/jboss/dna/common/monitor/SimpleActivityMonitorTest$I18nMessages_en.properties
trunk/dna-common/src/test/resources/org/jboss/dna/common/monitor/SimpleActivityMonitorTest$I18nMessages_fr.properties
Removed:
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/LoggingProgressMonitor.java
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/ProgressMonitor.java
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/ProgressMonitorWrapper.java
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/ProgressStatus.java
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/SimpleProgressMonitor.java
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/SubProgressMonitor.java
trunk/dna-common/src/test/java/org/jboss/dna/common/monitor/ProgressStatusTest.java
trunk/dna-common/src/test/java/org/jboss/dna/common/monitor/RecordingProgressMonitor.java
trunk/dna-common/src/test/java/org/jboss/dna/common/monitor/SimpleProgressMonitorTest.java
trunk/dna-common/src/test/resources/org/jboss/dna/common/monitor/SimpleProgressMonitorTest$I18nMessages_en.properties
trunk/dna-common/src/test/resources/org/jboss/dna/common/monitor/SimpleProgressMonitorTest$I18nMessages_fr.properties
Modified:
trunk/dna-common/src/main/java/org/jboss/dna/common/CommonI18n.java
trunk/dna-common/src/main/resources/org/jboss/dna/common/CommonI18n.properties
trunk/dna-common/src/test/java/org/jboss/dna/common/component/ComponentLibraryTest.java
trunk/dna-common/src/test/java/org/jboss/dna/common/component/MockComponentA.java
trunk/dna-common/src/test/java/org/jboss/dna/common/component/MockComponentB.java
trunk/dna-common/src/test/java/org/jboss/dna/common/component/SampleComponent.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/ExecutionContext.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/ExecutionContexts.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connectors/BasicExecutionContext.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/sequencers/StreamSequencer.java
trunk/dna-graph/src/test/java/org/jboss/dna/graph/sequencers/MockSequencerContext.java
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/Sequencer.java
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencerNodeContext.java
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencingService.java
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/StreamSequencerAdapter.java
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/MockSequencerA.java
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/MockSequencerB.java
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/StreamSequencerAdapterTest.java
trunk/extensions/dna-sequencer-images/src/main/java/org/jboss/dna/sequencer/images/ImageMetadataSequencer.java
trunk/extensions/dna-sequencer-images/src/test/java/org/jboss/dna/sequencer/images/ImageMetadataSequencerTest.java
trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/JavaMetadataSequencer.java
trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/metadata/JavaMetadata.java
trunk/extensions/dna-sequencer-java/src/test/java/org/jboss/dna/sequencer/java/JavaMetadataSequencerTest.java
trunk/extensions/dna-sequencer-mp3/src/main/java/org/jboss/dna/sequencer/mp3/Mp3MetadataSequencer.java
trunk/extensions/dna-sequencer-msoffice/src/main/java/org/jboss/dna/sequencer/msoffice/MSOfficeMetadataSequencer.java
trunk/extensions/dna-sequencer-zip/src/main/java/org/jboss/dna/sequencer/zip/ZipSequencer.java
Log:
Undid DNA-186 in lieu of better solution to come involving execution context progress
monitor, and renamed ProgressMonitor and ProgressStatus to ActivityMonitor and
ActivityStatus, respectively, since the monitor is about more than just progress (such as
collecting problems that occur during an activity)
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-29
18:23:01 UTC (rev 598)
+++ trunk/dna-common/src/main/java/org/jboss/dna/common/CommonI18n.java 2008-10-29
20:09:42 UTC (rev 599)
@@ -85,15 +85,15 @@
public static I18n componentClassnameNotValid;
public static I18n componentNotConfigured;
public static I18n dateParsingFailure;
- public static I18n initialProgressMonitorTaskName;
- public static I18n nullProgressMonitorTaskName;
+ public static I18n initialActivityMonitorTaskName;
+ public static I18n nullActivityMonitorTaskName;
public static I18n pathAncestorDegreeIsInvalid;
public static I18n pathIsAlreadyAbsolute;
public static I18n pathIsNotAbsolute;
public static I18n pathIsNotRelative;
public static I18n pathCannotBeNormalized;
- public static I18n progressMonitorBeginTask;
- public static I18n progressMonitorStatus;
+ public static I18n activityMonitorBeginTask;
+ public static I18n activityMonitorStatus;
public static I18n requiredToSuppliedParameterMismatch;
static {
Copied: trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/ActivityMonitor.java
(from rev 596,
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/ProgressMonitor.java)
===================================================================
--- trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/ActivityMonitor.java
(rev 0)
+++
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/ActivityMonitor.java 2008-10-29
20:09:42 UTC (rev 599)
@@ -0,0 +1,145 @@
+/*
+ * 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.Locale;
+import org.jboss.dna.common.collection.Problems;
+import org.jboss.dna.common.i18n.I18n;
+
+/**
+ * A basic activity monitor that facilitates the updating and monitoring of progress
towards the completion of an activity.
+ * Documentation hereafter will refer to the code in an application that updates progress
as the <strong>Updater</strong>, and
+ * code that monitors progress as an <strong>Observer</strong>.
+ * <p>
+ * The progress of each activity is started when the <strong>Updater</strong>
calls {@link #beginTask(double, I18n, Object...)},
+ * continues with a mixture of work ({@link #worked(double)}) and subtasks ( {@link
#createSubtask(double)}), and finishes when
+ * the activity is completed ({@link #done()}) or cancelled ( {@link
#setCancelled(boolean)}).
+ * </p>
+ * <p>
+ * If an activity is interrupted before its normal completion due to a cancellation
request by an <strong>Observer</strong>, it is
+ * still the responsibility of the <strong>Updater</strong> to mark the
activity as completed. Similarly, if an activity cannot be
+ * cancelled before its normal completion, the <strong>Updater</strong> must
deny any previous cancellation request by calling
+ * {@link #setCancelled(boolean) setCancelled(false)}.
+ * </p>
+ *
+ * @author Randall Hauch
+ * @author John Verhaeg
+ */
+public interface ActivityMonitor {
+
+ /**
+ * Called by the <strong>Updater</strong> to indicate work has started on
the task, specifying the total amount of work that
+ * this task constitutes.
+ *
+ * @param totalWork the total number of work units for the task
+ * @param name the name of the task
+ * @param params the parameters for localization
+ */
+ void beginTask( double totalWork,
+ I18n name,
+ Object... params );
+
+ /**
+ * 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()}).
+ *
+ * @param subtaskWork the number of work units for this subtask
+ * @return the activity monitor for the subtask
+ */
+ ActivityMonitor createSubtask( double subtaskWork );
+
+ /**
+ * Called by the <strong>Updater</strong> to mark this activity as
complete. This method must be called, even if the activity
+ * has been cancelled.
+ */
+ 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.
+ *
+ * @return the activity's name; never <code>null</code>
+ * @see #getActivityName(Locale)
+ */
+ String getActivityName();
+
+ /**
+ * 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
+ * @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 list of problems
+ */
+ Problems getProblems();
+
+ /**
+ * Return the current status of this activity, localized to the specified 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
+ * @return the status of this activity
+ */
+ ActivityStatus getStatus( Locale locale );
+
+ /**
+ * Return whether a request was made by an <strong>Observer</strong> to
{@link #setCancelled(boolean) cancel} this activity.
+ *
+ * @return <code>true</code> if this activity has been requested to be
cancelled.
+ */
+ boolean isCancelled();
+
+ /**
+ * Return whether this activity has completed.
+ *
+ * @return <code>true</code> if this activity has completed.
+ */
+ boolean isDone();
+
+ /**
+ * Called by an <strong>Observer</strong> to request the cancellation of
this activity, or by the <strong>Updater</strong> to
+ * deny a prior cancellation request (i.e., when the activity {@link #done()
completes} before the <strong>Updater</strong>
+ * recognizes a cancellation request by an <strong>Observer</strong>).
+ *
+ * @param value <code>true</code> if requesting the activity be
cancelled.
+ */
+ void setCancelled( boolean value );
+
+ /**
+ * Called by the <strong>Updater</strong> to report work completed for
this task.
+ *
+ * @param work the number of work units that have been worked
+ */
+ void worked( double work );
+}
Copied:
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/ActivityMonitorWrapper.java
(from rev 596,
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/ProgressMonitorWrapper.java)
===================================================================
---
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/ActivityMonitorWrapper.java
(rev 0)
+++
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/ActivityMonitorWrapper.java 2008-10-29
20:09:42 UTC (rev 599)
@@ -0,0 +1,147 @@
+/*
+ * 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.Locale;
+import org.jboss.dna.common.collection.Problems;
+import org.jboss.dna.common.i18n.I18n;
+
+/**
+ * The thread safety of this class is determined by the delegate.
+ *
+ * @author Randall Hauch
+ * @author John Verhaeg
+ */
+public class ActivityMonitorWrapper implements ActivityMonitor {
+
+ private final ActivityMonitor delegate;
+
+ public ActivityMonitorWrapper( ActivityMonitor delegate ) {
+ this.delegate = delegate;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @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 ) {
+ this.delegate.beginTask(totalWork, name, params);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.common.monitor.ActivityMonitor#createSubtask(double)
+ */
+ public ActivityMonitor createSubtask( double subtaskWork ) {
+ return this.delegate.createSubtask(subtaskWork);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.common.monitor.ActivityMonitor#done()
+ */
+ public void done() {
+ this.delegate.done();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.common.monitor.ActivityMonitor#getActivityName()
+ */
+ public String getActivityName() {
+ return delegate.getActivityName();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see
org.jboss.dna.common.monitor.ActivityMonitor#getActivityName(java.util.Locale)
+ */
+ public String getActivityName( Locale locale ) {
+ return delegate.getActivityName(locale);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.common.monitor.ActivityMonitor#getProblems()
+ */
+ public Problems getProblems() {
+ return delegate.getProblems();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.common.monitor.ActivityMonitor#getStatus(java.util.Locale)
+ */
+ public ActivityStatus getStatus( Locale locale ) {
+ return this.delegate.getStatus(locale);
+ }
+
+ public ActivityMonitor getWrappedMonitor() {
+ return this.delegate;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.common.monitor.ActivityMonitor#isCancelled()
+ */
+ public boolean isCancelled() {
+ return this.delegate.isCancelled();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.common.monitor.ActivityMonitor#isDone()
+ */
+ public boolean isDone() {
+ return delegate.isDone();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.common.monitor.ActivityMonitor#setCancelled(boolean)
+ */
+ public void setCancelled( boolean value ) {
+ this.delegate.setCancelled(value);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.common.monitor.ActivityMonitor#worked(double)
+ */
+ public void worked( double work ) {
+ this.delegate.worked(work);
+ }
+}
Copied: trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/ActivityStatus.java
(from rev 596,
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/ProgressStatus.java)
===================================================================
--- trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/ActivityStatus.java
(rev 0)
+++
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/ActivityStatus.java 2008-10-29
20:09:42 UTC (rev 599)
@@ -0,0 +1,208 @@
+/*
+ * 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.io.Serializable;
+import java.text.DecimalFormat;
+import net.jcip.annotations.Immutable;
+import org.jboss.dna.common.util.StringUtil;
+
+/**
+ * A snapshot of the progress on an activity.
+ *
+ * @author Randall Hauch
+ * @author John Verhaeg
+ */
+@Immutable
+public class ActivityStatus implements Serializable, Comparable<ActivityStatus> {
+
+ /**
+ */
+ private static final long serialVersionUID = -7771764546193063275L;
+ protected static final String PERCENTAGE_PATTERN = "##0.0"; // percentage
should always fit
+ protected static final double PERCENT_PRECISION = 0.001d;
+
+ /**
+ * Compute the percentage worked, accounting for imprecision in
+ *
+ * @param workedSoFar the amount of work so far percentage worked
+ * @param totalWork the total amount of work for this activity
+ * @return the percentage worked
+ */
+ protected static double computePercentage( double workedSoFar,
+ double totalWork ) {
+ if (isSamePercentage(workedSoFar, 0.0d)) return 0.0d;
+ assert totalWork > 0.0d;
+ double percentage = workedSoFar / totalWork * 100.0d;
+ if (isSamePercentage(percentage, 100.0d)) percentage = 100.0d;
+ return percentage;
+ }
+
+ protected static boolean isSamePercentage( double percentage1,
+ double percentage2 ) {
+ return Math.abs(percentage1 - percentage2) <= PERCENT_PRECISION;
+ }
+
+ private final String activityName;
+ private final double percentWorked;
+ private final boolean done;
+ private final boolean cancelled;
+ private final String message;
+
+ /**
+ * 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 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
+ */
+ public ActivityStatus( String activityName,
+ String message,
+ double percentWorked,
+ boolean cancelled ) {
+ assert activityName != null;
+ assert message != null;
+ this.activityName = activityName;
+ this.done = percentWorked >= 100.0d;
+ this.percentWorked = this.done ? 100.0d : (percentWorked <= 0.0d ? 0.0d :
percentWorked);
+ this.message = message;
+ this.cancelled = cancelled;
+ }
+
+ /**
+ * 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 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
+ */
+ public ActivityStatus( String activityName,
+ String message,
+ double workedSoFar,
+ double totalWork,
+ boolean cancelled ) {
+ this(activityName, message, computePercentage(workedSoFar, totalWork),
cancelled);
+ }
+
+ /**
+ * Get the name of the activity.
+ *
+ * @return the activity's name
+ */
+ public String getActivityName() {
+ return this.activityName;
+ }
+
+ /**
+ * Get the progress as a percentage of the total work that's been completed.
+ *
+ * @return the percentage worked, ranging from 0.0 to 100.0
+ */
+ public double getPercentWorked() {
+ return this.percentWorked;
+ }
+
+ /**
+ * Get the activity monitor's text message.
+ *
+ * @return the text message
+ */
+ public String getMessage() {
+ return this.message;
+ }
+
+ /**
+ * Return whether work on this activity has completed.
+ *
+ * @return true if work has completed, or false if work on the activity is still
progressing
+ * @see #isCancelled()
+ */
+ public boolean isDone() {
+ return done;
+ }
+
+ /**
+ * Return whether the activity was requested to be cancelled.
+ *
+ * @return cancelled
+ * @see #isDone()
+ */
+ public boolean isCancelled() {
+ return this.cancelled;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toString() {
+ 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;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int hashCode() {
+ return this.getActivityName().hashCode();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean equals( Object obj ) {
+ if (this == obj) return true;
+ if (obj instanceof ActivityStatus) {
+ final ActivityStatus that = (ActivityStatus)obj;
+ // First check that the name is the same ...
+ if (!this.getActivityName().equals(that.getActivityName())) return false;
+ // Then check doneness and percent complete ...
+ if (this.isDone() != that.isDone()) return false;
+ if (!isSamePercentage(this.getPercentWorked(), that.getPercentWorked()))
return false;
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int compareTo( ActivityStatus that ) {
+ if (this == that) return 0;
+
+ // First check the name ...
+ int diff = this.getActivityName().compareTo(that.getActivityName());
+ if (diff != 0) return diff;
+
+ // Then check the percentage ...
+ return Double.compare(this.getPercentWorked(), that.getPercentWorked());
+ }
+}
Copied:
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/LoggingActivityMonitor.java
(from rev 596,
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/LoggingProgressMonitor.java)
===================================================================
---
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/LoggingActivityMonitor.java
(rev 0)
+++
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/LoggingActivityMonitor.java 2008-10-29
20:09:42 UTC (rev 599)
@@ -0,0 +1,96 @@
+/*
+ * 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.Locale;
+import org.jboss.dna.common.CommonI18n;
+import org.jboss.dna.common.i18n.I18n;
+import org.jboss.dna.common.util.Logger;
+
+/**
+ * @author Randall Hauch
+ * @author John Verhaeg
+ */
+public class LoggingActivityMonitor extends ActivityMonitorWrapper {
+
+ private final Logger logger;
+ private final Logger.Level level;
+ private final Locale locale;
+
+ public LoggingActivityMonitor( ActivityMonitor delegate,
+ Logger logger,
+ Logger.Level level ) {
+ this(delegate, logger, level, null);
+ }
+
+ public LoggingActivityMonitor( ActivityMonitor delegate,
+ Logger logger,
+ Logger.Level level,
+ Locale locale ) {
+ super(delegate);
+ assert level != null;
+ assert logger != null;
+ this.level = level;
+ this.logger = logger;
+ this.locale = locale;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void beginTask( double totalWork,
+ I18n name,
+ Object... params ) {
+ super.beginTask(totalWork, name, params);
+ this.logger.log(level, CommonI18n.activityMonitorBeginTask, getActivityName(),
name.text(params));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void done() {
+ super.done();
+ this.logger.log(level, CommonI18n.activityMonitorStatus,
super.getStatus(this.locale));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void setCancelled( boolean value ) {
+ super.setCancelled(value);
+ this.logger.log(level, CommonI18n.activityMonitorStatus,
super.getStatus(this.locale));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void worked( double work ) {
+ super.worked(work);
+ this.logger.log(level, CommonI18n.activityMonitorStatus,
super.getStatus(this.locale));
+ }
+
+}
Deleted:
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/LoggingProgressMonitor.java
===================================================================
---
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/LoggingProgressMonitor.java 2008-10-29
18:23:01 UTC (rev 598)
+++
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/LoggingProgressMonitor.java 2008-10-29
20:09:42 UTC (rev 599)
@@ -1,88 +0,0 @@
-/*
- * 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.Locale;
-import org.jboss.dna.common.CommonI18n;
-import org.jboss.dna.common.i18n.I18n;
-import org.jboss.dna.common.util.Logger;
-
-/**
- * @author Randall Hauch
- */
-public class LoggingProgressMonitor extends ProgressMonitorWrapper {
-
- private final Logger logger;
- private final Logger.Level level;
- private final Locale locale;
-
- public LoggingProgressMonitor( ProgressMonitor delegate, Logger logger, Logger.Level
level ) {
- this(delegate, logger, level, null);
- }
-
- public LoggingProgressMonitor( ProgressMonitor delegate, Logger logger, Logger.Level
level, Locale locale ) {
- super(delegate);
- assert level != null;
- assert logger != null;
- this.level = level;
- this.logger = logger;
- this.locale = locale;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void beginTask( double totalWork, I18n name, Object... params ) {
- super.beginTask(totalWork, name, params);
- this.logger.log(level, CommonI18n.progressMonitorBeginTask, getActivityName(),
name.text(params));
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void done() {
- super.done();
- this.logger.log(level, CommonI18n.progressMonitorStatus,
super.getStatus(this.locale));
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void setCancelled( boolean value ) {
- super.setCancelled(value);
- this.logger.log(level, CommonI18n.progressMonitorStatus,
super.getStatus(this.locale));
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void worked( double work ) {
- super.worked(work);
- this.logger.log(level, CommonI18n.progressMonitorStatus,
super.getStatus(this.locale));
- }
-
-}
Deleted: trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/ProgressMonitor.java
===================================================================
---
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/ProgressMonitor.java 2008-10-29
18:23:01 UTC (rev 598)
+++
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/ProgressMonitor.java 2008-10-29
20:09:42 UTC (rev 599)
@@ -1,141 +0,0 @@
-/*
- * 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.Locale;
-import org.jboss.dna.common.collection.Problems;
-import org.jboss.dna.common.i18n.I18n;
-
-/**
- * A basic progress monitor that facilitates the updating and monitoring of progress
towards the completion of an activity.
- * Documentation hereafter will refer to the code in an application that updates progress
as the <strong>Updater</strong>, and
- * code that monitors progress as an <strong>Observer</strong>.
- * <p>
- * The progress of each {@link #getActivityName() activity} is started when the
<strong>Updater</strong> calls
- * {@link #beginTask(double, I18n, Object...)}, continues with a mixture of work ({@link
#worked(double)}) and subtasks (
- * {@link #createSubtask(double)}), and finishes when the activity is completed ({@link
#done()}) or cancelled (
- * {@link #setCancelled(boolean)}).
- * </p>
- * <p>
- * If an activity is interrupted before its normal completion due to a cancellation
request by an <strong>Observer</strong>, it is
- * still the responsibility of the <strong>Updater</strong> to mark the
activity as completed. Similarly, if an activity cannot be
- * cancelled before its normal completion, the <strong>Updater</strong> must
deny any previous cancellation request by calling
- * {@link #setCancelled(boolean) setCancelled(false)}.
- * </p>
- *
- * @author Randall Hauch
- * @author John Verhaeg
- */
-public interface ProgressMonitor {
-
- /**
- * Called by the <strong>Updater</strong> to indicate work has started on
the task, specifying the total amount of work that
- * this task constitutes.
- *
- * @param totalWork the total number of work units for the task
- * @param name the name of the task
- * @param params the parameters for localization
- */
- void beginTask( double totalWork,
- I18n name,
- Object... params );
-
- /**
- * Called by the <strong>Updater</strong> to create a subtask with the
given about of work. The resulting progress monitor
- * must be started ({@link #beginTask(double, I18n, Object...)}) and finished ({@link
#done()}).
- *
- * @param subtaskWork the number of work units for this subtask
- * @return the progress monitor for the subtask
- */
- ProgressMonitor createSubtask( double subtaskWork );
-
- /**
- * Called by the <strong>Updater</strong> to mark this activity as
complete. This method must be called, even if the activity
- * has been cancelled.
- */
- void done();
-
- /**
- * Get the name of the activity. This should never change for a progress monitor, and
all {@link #createSubtask(double)
- * subtasks} should have the same name.
- *
- * @return the activity's name; never <code>null</code>
- */
- String getActivityName();
-
- /**
- * Get the name of the activity that spawned this activity. This should never change
for a progress monitor.
- *
- * @return the parent activity's name; never <code>null</code>
- */
- String getParentActivityName();
-
- /**
- * Return the problems encountered during the {@link #getStatus(Locale) progress}
made towards completing the associated
- * {@link #getActivityName() activity}.
- *
- * @return the list of problems
- */
- Problems getProblems();
-
- /**
- * Return the current status of this activity, localized to the specified 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
- * @return the status of this activity
- */
- ProgressStatus getStatus( Locale locale );
-
- /**
- * Return whether a request was made by an <strong>Observer</strong> to
{@link #setCancelled(boolean) cancel} this activity.
- *
- * @return <code>true</code> if this activity has been requested to be
cancelled.
- */
- boolean isCancelled();
-
- /**
- * Return whether this activity has completed.
- *
- * @return <code>true</code> if this activity has completed.
- */
- boolean isDone();
-
- /**
- * Called by an <strong>Observer</strong> to request the cancellation of
this activity, or by the <strong>Updater</strong> to
- * deny a prior cancellation request (i.e., when the activity {@link #done()
completes} before the <strong>Updater</strong>
- * recognizes a cancellation request by an <strong>Observer</strong>).
- *
- * @param value <code>true</code> if requesting the activity be
cancelled.
- */
- void setCancelled( boolean value );
-
- /**
- * Called by the <strong>Updater</strong> to report work completed for
this task.
- *
- * @param work the number of work units that have been worked
- */
- void worked( double work );
-}
Deleted:
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/ProgressMonitorWrapper.java
===================================================================
---
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/ProgressMonitorWrapper.java 2008-10-29
18:23:01 UTC (rev 598)
+++
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/ProgressMonitorWrapper.java 2008-10-29
20:09:42 UTC (rev 599)
@@ -1,107 +0,0 @@
-/*
- * 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.Locale;
-import org.jboss.dna.common.collection.Problems;
-import org.jboss.dna.common.i18n.I18n;
-
-/**
- * The thread safety of this class is determined by the delegate.
- *
- * @author Randall Hauch
- * @author John Verhaeg
- */
-public class ProgressMonitorWrapper implements ProgressMonitor {
-
- private final ProgressMonitor delegate;
-
- public ProgressMonitorWrapper( ProgressMonitor delegate ) {
- this.delegate = delegate;
- }
-
- public void beginTask( double totalWork,
- I18n name,
- Object... params ) {
- this.delegate.beginTask(totalWork, name, params);
- }
-
- public ProgressMonitor createSubtask( double subtaskWork ) {
- return this.delegate.createSubtask(subtaskWork);
- }
-
- public void done() {
- this.delegate.done();
- }
-
- public String getActivityName() {
- return this.delegate.getActivityName();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.common.monitor.ProgressMonitor#getParentActivityName()
- */
- public String getParentActivityName() {
- return this.delegate.getParentActivityName();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.common.monitor.ProgressMonitor#getProblems()
- */
- public Problems getProblems() {
- return delegate.getProblems();
- }
-
- public ProgressStatus getStatus( Locale locale ) {
- return this.delegate.getStatus(locale);
- }
-
- public ProgressMonitor getWrappedMonitor() {
- return this.delegate;
- }
-
- public boolean isCancelled() {
- return this.delegate.isCancelled();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.common.monitor.ProgressMonitor#isDone()
- */
- public boolean isDone() {
- return delegate.isDone();
- }
-
- public void setCancelled( boolean value ) {
- this.delegate.setCancelled(value);
- }
-
- public void worked( double work ) {
- this.delegate.worked(work);
- }
-}
Deleted: trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/ProgressStatus.java
===================================================================
---
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/ProgressStatus.java 2008-10-29
18:23:01 UTC (rev 598)
+++
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/ProgressStatus.java 2008-10-29
20:09:42 UTC (rev 599)
@@ -1,207 +0,0 @@
-/*
- * 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.io.Serializable;
-import java.text.DecimalFormat;
-import net.jcip.annotations.Immutable;
-import org.jboss.dna.common.util.StringUtil;
-
-/**
- * A snapshot of the progress on an activity.
- *
- * @author Randall Hauch
- */
-@Immutable
-public class ProgressStatus implements Serializable, Comparable<ProgressStatus> {
-
- /**
- */
- private static final long serialVersionUID = -7771764546193063275L;
- protected static final String PERCENTAGE_PATTERN = "##0.0"; // percentage
should always fit
- protected static final double PERCENT_PRECISION = 0.001d;
-
- /**
- * Compute the percentage worked, accounting for imprecision in
- *
- * @param workedSoFar the amount of work so far percentage worked
- * @param totalWork the total amount of work for this activity
- * @return the percentage worked
- */
- protected static double computePercentage( double workedSoFar,
- double totalWork ) {
- if (isSamePercentage(workedSoFar, 0.0d)) return 0.0d;
- assert totalWork > 0.0d;
- double percentage = workedSoFar / totalWork * 100.0d;
- if (isSamePercentage(percentage, 100.0d)) percentage = 100.0d;
- return percentage;
- }
-
- protected static boolean isSamePercentage( double percentage1,
- double percentage2 ) {
- return Math.abs(percentage1 - percentage2) <= PERCENT_PRECISION;
- }
-
- private final String activityName;
- private final double percentWorked;
- private final boolean done;
- private final boolean cancelled;
- private final String message;
-
- /**
- * Create the progress status.
- *
- * @param activityName the name of the activity, which may not be null
- * @param message the message for the progress, which may not be null
- * @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 true if the activity has been requested to be cancelled, or false
otherwise
- */
- public ProgressStatus( String activityName,
- String message,
- double percentWorked,
- boolean cancelled ) {
- assert activityName != null;
- assert message != null;
- this.activityName = activityName;
- this.done = percentWorked >= 100.0d;
- this.percentWorked = this.done ? 100.0d : (percentWorked <= 0.0d ? 0.0d :
percentWorked);
- this.message = message;
- this.cancelled = cancelled;
- }
-
- /**
- * Create the progress status and compute the percentage worked.
- *
- * @param activityName the name of the activity, which may not be null
- * @param message the message for the progress, which may not be null
- * @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
- */
- public ProgressStatus( String activityName,
- String message,
- double workedSoFar,
- double totalWork,
- boolean cancelled ) {
- this(activityName, message, computePercentage(workedSoFar, totalWork),
cancelled);
- }
-
- /**
- * Get the name of the activity.
- *
- * @return the activity's name
- */
- public String getActivityName() {
- return this.activityName;
- }
-
- /**
- * Get the progress as a percentage of the total work that's been completed.
- *
- * @return the percentage worked, ranging from 0.0 to 100.0
- */
- public double getPercentWorked() {
- return this.percentWorked;
- }
-
- /**
- * Get the progress monitor's text message.
- *
- * @return the text message
- */
- public String getMessage() {
- return this.message;
- }
-
- /**
- * Return whether work on this activity has completed.
- *
- * @return true if work has completed, or false if work on the activity is still
progressing
- * @see #isCancelled()
- */
- public boolean isDone() {
- return done;
- }
-
- /**
- * Return whether the activity was requested to be cancelled.
- *
- * @return cancelled
- * @see #isDone()
- */
- public boolean isCancelled() {
- return this.cancelled;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public String toString() {
- 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;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public int hashCode() {
- return this.getActivityName().hashCode();
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean equals( Object obj ) {
- if (this == obj) return true;
- if (obj instanceof ProgressStatus) {
- final ProgressStatus that = (ProgressStatus)obj;
- // First check that the name is the same ...
- if (!this.getActivityName().equals(that.getActivityName())) return false;
- // Then check doneness and percent complete ...
- if (this.isDone() != that.isDone()) return false;
- if (!isSamePercentage(this.getPercentWorked(), that.getPercentWorked()))
return false;
- return true;
- }
- return false;
- }
-
- /**
- * {@inheritDoc}
- */
- public int compareTo( ProgressStatus that ) {
- if (this == that) return 0;
-
- // First check the name ...
- int diff = this.getActivityName().compareTo(that.getActivityName());
- if (diff != 0) return diff;
-
- // Then check the percentage ...
- return Double.compare(this.getPercentWorked(), that.getPercentWorked());
- }
-}
Copied:
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/SimpleActivityMonitor.java
(from rev 596,
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/SimpleProgressMonitor.java)
===================================================================
---
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/SimpleActivityMonitor.java
(rev 0)
+++
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/SimpleActivityMonitor.java 2008-10-29
20:09:42 UTC (rev 599)
@@ -0,0 +1,228 @@
+/*
+ * 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.Locale;
+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;
+
+/**
+ * A basic activity monitor.
+ *
+ * @author Randall Hauch
+ * @author John Verhaeg
+ */
+@ThreadSafe
+public class SimpleActivityMonitor implements ActivityMonitor {
+
+ @GuardedBy( "lock" )
+ private I18n taskName;
+ @GuardedBy( "lock" )
+ private Object[] taskNameParams;
+ @GuardedBy( "lock" )
+ private double totalWork;
+ @GuardedBy( "lock" )
+ private double worked;
+
+ private final I18n activityName;
+ private final Object[] activityNameParams;
+ private final ReadWriteLock lock = new ReentrantReadWriteLock();
+ private final AtomicBoolean cancelled = new AtomicBoolean(false);
+ private final Problems problems = new ThreadSafeProblems();
+
+ public SimpleActivityMonitor( I18n activityName,
+ Object... params ) {
+ CheckArg.isNotNull(activityName, "activityName");
+ this.activityName = activityName;
+ this.activityNameParams = params;
+ this.taskName = null;
+ this.taskNameParams = null;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @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 ) {
+ CheckArg.isGreaterThan(totalWork, 0.0, "totalWork");
+ try {
+ this.lock.writeLock().lock();
+ this.taskName = name;
+ this.taskNameParams = params;
+ this.totalWork = totalWork;
+ this.worked = 0.0d;
+ } finally {
+ this.lock.writeLock().unlock();
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.common.monitor.ActivityMonitor#createSubtask(double)
+ */
+ public ActivityMonitor createSubtask( double subtaskWork ) {
+ return new SubActivityMonitor(this, subtaskWork);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.common.monitor.ActivityMonitor#done()
+ */
+ public void done() {
+ boolean alreadyDone = false;
+ try {
+ this.lock.writeLock().lock();
+ if (this.worked < this.totalWork) {
+ this.worked = this.totalWork;
+ } else {
+ alreadyDone = true;
+ }
+ } finally {
+ this.lock.writeLock().unlock();
+ }
+ if (!alreadyDone) notifyProgress();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.common.monitor.ActivityMonitor#getActivityName()
+ */
+ public String getActivityName() {
+ return getActivityName(null);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @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);
+ }
+
+ /**
+ * {@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()
+ */
+ public Problems getProblems() {
+ return problems;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.common.monitor.ActivityMonitor#getStatus(java.util.Locale)
+ */
+ 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());
+ } finally {
+ this.lock.readLock().unlock();
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.common.monitor.ActivityMonitor#isCancelled()
+ */
+ public boolean isCancelled() {
+ return this.cancelled.get();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.common.monitor.ActivityMonitor#isDone()
+ */
+ public boolean isDone() {
+ lock.readLock().lock();
+ try {
+ return worked >= totalWork;
+ } finally {
+ lock.readLock().unlock();
+ }
+ }
+
+ /**
+ * Method that is called in {@link #worked(double)} (which is called by {@link
#createSubtask(double) subtasks}) when there
+ * has been some positive work, or when the monitor is first marked as {@link
#done()}.
+ * <p>
+ * This method implementation does nothing, but subclasses can easily override this
method if they want to be updated with the
+ * latest progress.
+ * </p>
+ */
+ protected void notifyProgress() {
+ // do nothing
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.common.monitor.ActivityMonitor#setCancelled(boolean)
+ */
+ public void setCancelled( boolean value ) {
+ this.cancelled.set(value);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.common.monitor.ActivityMonitor#worked(double)
+ */
+ public void worked( double work ) {
+ if (work > 0) {
+ try {
+ this.lock.writeLock().lock();
+ if (this.worked < this.totalWork) {
+ this.worked += work;
+ if (this.worked > this.totalWork) this.worked = this.totalWork;
+ }
+ } finally {
+ this.lock.writeLock().unlock();
+ }
+ notifyProgress();
+ }
+ }
+}
Deleted:
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/SimpleProgressMonitor.java
===================================================================
---
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/SimpleProgressMonitor.java 2008-10-29
18:23:01 UTC (rev 598)
+++
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/SimpleProgressMonitor.java 2008-10-29
20:09:42 UTC (rev 599)
@@ -1,230 +0,0 @@
-/*
- * 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.Locale;
-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;
-
-/**
- * A basic progress monitor.
- *
- * @author Randall Hauch
- * @author John Verhaeg
- */
-@ThreadSafe
-public class SimpleProgressMonitor implements ProgressMonitor {
-
- @GuardedBy( "lock" )
- private I18n taskName;
- @GuardedBy( "lock" )
- private Object[] taskNameParams;
- @GuardedBy( "lock" )
- private double totalWork;
- @GuardedBy( "lock" )
- private double worked;
-
- private final String activityName;
- private final String parentActivityName;
- private final ReadWriteLock lock = new ReentrantReadWriteLock();
- private final AtomicBoolean cancelled = new AtomicBoolean(false);
- private final Problems problems = new ThreadSafeProblems();
-
- public SimpleProgressMonitor( String activityName ) {
- this(activityName, null);
- }
-
- public SimpleProgressMonitor( String activityName,
- ProgressMonitor parentProgressMonitor ) {
- this.activityName = activityName == null ? "" : activityName.trim();
- this.parentActivityName = parentProgressMonitor == null ? "" :
parentProgressMonitor.getActivityName();
- this.taskName = null;
- this.taskNameParams = null;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.common.monitor.ProgressMonitor#beginTask(double,
org.jboss.dna.common.i18n.I18n, java.lang.Object[])
- */
- public void beginTask( double totalWork,
- I18n name,
- Object... params ) {
- CheckArg.isGreaterThan(totalWork, 0.0, "totalWork");
- try {
- this.lock.writeLock().lock();
- this.taskName = name;
- this.taskNameParams = params;
- this.totalWork = totalWork;
- this.worked = 0.0d;
- } finally {
- this.lock.writeLock().unlock();
- }
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.common.monitor.ProgressMonitor#createSubtask(double)
- */
- public ProgressMonitor createSubtask( double subtaskWork ) {
- return new SubProgressMonitor(this, subtaskWork);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.common.monitor.ProgressMonitor#done()
- */
- public void done() {
- boolean alreadyDone = false;
- try {
- this.lock.writeLock().lock();
- if (this.worked < this.totalWork) {
- this.worked = this.totalWork;
- } else {
- alreadyDone = true;
- }
- } finally {
- this.lock.writeLock().unlock();
- }
- if (!alreadyDone) notifyProgress();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.common.monitor.ProgressMonitor#getActivityName()
- */
- public String getActivityName() {
- return this.activityName;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.common.monitor.ProgressMonitor#getParentActivityName()
- */
- public String getParentActivityName() {
- return this.parentActivityName;
- }
-
- /**
- * {@inheritDoc}
- * <p>
- * Problems must only be added by the {@link ProgressMonitor
<strong>Updater</strong>}, and accessed by
- * {@link ProgressMonitor Observers} only after the activity has been {@link #done()
completed}.
- * </p>
- *
- * @see org.jboss.dna.common.monitor.ProgressMonitor#getProblems()
- */
- public Problems getProblems() {
- return problems;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.common.monitor.ProgressMonitor#getStatus(java.util.Locale)
- */
- public ProgressStatus getStatus( Locale locale ) {
- try {
- this.lock.readLock().lock();
- String localizedTaskName = this.taskName == null ? "" :
this.taskName.text(locale, this.taskNameParams);
- return new ProgressStatus(this.getActivityName(), localizedTaskName,
this.worked, this.totalWork, this.isCancelled());
- } finally {
- this.lock.readLock().unlock();
- }
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.common.monitor.ProgressMonitor#isCancelled()
- */
- public boolean isCancelled() {
- return this.cancelled.get();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.common.monitor.ProgressMonitor#isDone()
- */
- public boolean isDone() {
- lock.readLock().lock();
- try {
- return worked >= totalWork;
- } finally {
- lock.readLock().unlock();
- }
- }
-
- /**
- * Method that is called in {@link #worked(double)} (which is called by {@link
#createSubtask(double) subtasks}) when there
- * has been some positive work, or when the monitor is first marked as {@link
#done()}.
- * <p>
- * This method implementation does nothing, but subclasses can easily override this
method if they want to be updated with the
- * latest progress.
- * </p>
- */
- protected void notifyProgress() {
- // do nothing
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.common.monitor.ProgressMonitor#setCancelled(boolean)
- */
- public void setCancelled( boolean value ) {
- this.cancelled.set(value);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.common.monitor.ProgressMonitor#worked(double)
- */
- public void worked( double work ) {
- if (work > 0) {
- try {
- this.lock.writeLock().lock();
- if (this.worked < this.totalWork) {
- this.worked += work;
- if (this.worked > this.totalWork) this.worked = this.totalWork;
- }
- } finally {
- this.lock.writeLock().unlock();
- }
- notifyProgress();
- }
- }
-}
Copied:
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/SubActivityMonitor.java (from
rev 596,
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/SubProgressMonitor.java)
===================================================================
--- trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/SubActivityMonitor.java
(rev 0)
+++
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/SubActivityMonitor.java 2008-10-29
20:09:42 UTC (rev 599)
@@ -0,0 +1,209 @@
+/*
+ * 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.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 org.jboss.dna.common.i18n.I18n;
+
+/**
+ * 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 {
+
+ @GuardedBy( "lock" )
+ private I18n taskName;
+ @GuardedBy( "lock" )
+ private Object[] params;
+ @GuardedBy( "lock" )
+ private double totalWork;
+ @GuardedBy( "lock" )
+ private double parentWorkScaleFactor;
+ @GuardedBy( "lock" )
+ private double submittedToParent;
+
+ private final double subtaskTotalInParent;
+ private final ActivityMonitor parent;
+ private final ReadWriteLock lock = new ReentrantReadWriteLock();
+
+ public SubActivityMonitor( final ActivityMonitor parent,
+ final double subtaskTotalInParent ) {
+ assert subtaskTotalInParent > 0;
+ assert parent != null;
+ this.parent = parent;
+ this.subtaskTotalInParent = subtaskTotalInParent;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @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 ) {
+ assert totalWork > 0;
+ try {
+ this.lock.writeLock().lock();
+ this.taskName = name;
+ this.params = params;
+ this.totalWork = totalWork;
+ this.parentWorkScaleFactor = ((float)subtaskTotalInParent) /
((float)totalWork);
+ } finally {
+ this.lock.writeLock().unlock();
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.common.monitor.ActivityMonitor#createSubtask(double)
+ */
+ public ActivityMonitor createSubtask( double subtaskWork ) {
+ return new SubActivityMonitor(this, subtaskWork);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.common.monitor.ActivityMonitor#done()
+ */
+ public void done() {
+ // Compute the total work for this task in terms of the parent ...
+ double workInParentRemaining = 0.0d;
+ try {
+ this.lock.writeLock().lock();
+ double totalWorkInParent = this.totalWork * this.parentWorkScaleFactor;
+ workInParentRemaining = totalWorkInParent - this.submittedToParent;
+ } finally {
+ this.lock.writeLock().unlock();
+ }
+ // Don't do this in the lock: it's incremental, but doing so might cause
deadlock with future changes
+ this.parent.worked(workInParentRemaining);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.common.monitor.ActivityMonitor#getActivityName()
+ */
+ public String getActivityName() {
+ return parent.getActivityName();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see
org.jboss.dna.common.monitor.ActivityMonitor#getActivityName(java.util.Locale)
+ */
+ public String getActivityName( Locale locale ) {
+ return parent.getActivityName(locale);
+ }
+
+ /**
+ * @return parent
+ */
+ public ActivityMonitor getParent() {
+ return this.parent;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.common.monitor.ActivityMonitor#getProblems()
+ */
+ public Problems getProblems() {
+ return parent.getProblems();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.common.monitor.ActivityMonitor#getStatus(java.util.Locale)
+ */
+ 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());
+ } finally {
+ this.lock.readLock().unlock();
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.common.monitor.ActivityMonitor#isCancelled()
+ */
+ public boolean isCancelled() {
+ return this.parent.isCancelled();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.common.monitor.ActivityMonitor#isDone()
+ */
+ public boolean isDone() {
+ return parent.isDone();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.common.monitor.ActivityMonitor#setCancelled(boolean)
+ */
+ public void setCancelled( boolean value ) {
+ this.parent.setCancelled(value);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.common.monitor.ActivityMonitor#worked(double)
+ */
+ public void worked( double work ) {
+ if (this.isCancelled()) return;
+ if (work > 0) {
+ double workInParent = 0.0d;
+ try {
+ this.lock.writeLock().lock();
+ workInParent = work * parentWorkScaleFactor;
+ this.submittedToParent += workInParent;
+ } finally {
+ this.lock.writeLock().unlock();
+ }
+ // Don't do this in the lock: it's incremental, but doing so might
cause deadlock with future changes
+ this.parent.worked(workInParent);
+ }
+ }
+}
Deleted:
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/SubProgressMonitor.java
===================================================================
---
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/SubProgressMonitor.java 2008-10-29
18:23:01 UTC (rev 598)
+++
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/SubProgressMonitor.java 2008-10-29
20:09:42 UTC (rev 599)
@@ -1,208 +0,0 @@
-/*
- * 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.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 org.jboss.dna.common.i18n.I18n;
-
-/**
- * This class is thread-safe except when accessing or adding {@link #getProblems()
problems}. Problems must only be added by the
- * {@link ProgressMonitor <strong>Updater</strong>}, and accessed by {@link
ProgressMonitor Observers} only after the activity has
- * been {@link #done() completed}.
- *
- * @author Randall Hauch
- */
-public class SubProgressMonitor implements ProgressMonitor {
-
- @GuardedBy( "lock" )
- private I18n taskName;
- @GuardedBy( "lock" )
- private Object[] params;
- @GuardedBy( "lock" )
- private double totalWork;
- @GuardedBy( "lock" )
- private double parentWorkScaleFactor;
- @GuardedBy( "lock" )
- private double submittedToParent;
-
- private final double subtaskTotalInParent;
- private final ProgressMonitor parent;
- private final ReadWriteLock lock = new ReentrantReadWriteLock();
-
- public SubProgressMonitor( final ProgressMonitor parent,
- final double subtaskTotalInParent ) {
- assert subtaskTotalInParent > 0;
- assert parent != null;
- this.parent = parent;
- this.subtaskTotalInParent = subtaskTotalInParent;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.common.monitor.ProgressMonitor#beginTask(double,
org.jboss.dna.common.i18n.I18n, java.lang.Object[])
- */
- public void beginTask( double totalWork,
- I18n name,
- Object... params ) {
- assert totalWork > 0;
- try {
- this.lock.writeLock().lock();
- this.taskName = name;
- this.params = params;
- this.totalWork = totalWork;
- this.parentWorkScaleFactor = ((float)subtaskTotalInParent) /
((float)totalWork);
- } finally {
- this.lock.writeLock().unlock();
- }
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.common.monitor.ProgressMonitor#createSubtask(double)
- */
- public ProgressMonitor createSubtask( double subtaskWork ) {
- return new SubProgressMonitor(this, subtaskWork);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.common.monitor.ProgressMonitor#done()
- */
- public void done() {
- // Compute the total work for this task in terms of the parent ...
- double workInParentRemaining = 0.0d;
- try {
- this.lock.writeLock().lock();
- double totalWorkInParent = this.totalWork * this.parentWorkScaleFactor;
- workInParentRemaining = totalWorkInParent - this.submittedToParent;
- } finally {
- this.lock.writeLock().unlock();
- }
- // Don't do this in the lock: it's incremental, but doing so might cause
deadlock with future changes
- this.parent.worked(workInParentRemaining);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.common.monitor.ProgressMonitor#getActivityName()
- */
- public String getActivityName() {
- return this.parent.getActivityName();
- }
-
- /**
- * @return parent
- */
- public ProgressMonitor getParent() {
- return this.parent;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.common.monitor.ProgressMonitor#getParentActivityName()
- */
- public String getParentActivityName() {
- return parent.getParentActivityName();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.common.monitor.ProgressMonitor#getProblems()
- */
- public Problems getProblems() {
- return parent.getProblems();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.common.monitor.ProgressMonitor#getStatus(java.util.Locale)
- */
- public ProgressStatus getStatus( Locale locale ) {
- try {
- this.lock.readLock().lock();
- return new ProgressStatus(this.getActivityName(), this.taskName.text(locale,
this.params), this.submittedToParent,
- this.subtaskTotalInParent, this.isCancelled());
- } finally {
- this.lock.readLock().unlock();
- }
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.common.monitor.ProgressMonitor#isCancelled()
- */
- public boolean isCancelled() {
- return this.parent.isCancelled();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.common.monitor.ProgressMonitor#isDone()
- */
- public boolean isDone() {
- return parent.isDone();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.common.monitor.ProgressMonitor#setCancelled(boolean)
- */
- public void setCancelled( boolean value ) {
- this.parent.setCancelled(value);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.common.monitor.ProgressMonitor#worked(double)
- */
- public void worked( double work ) {
- if (this.isCancelled()) return;
- if (work > 0) {
- double workInParent = 0.0d;
- try {
- this.lock.writeLock().lock();
- workInParent = work * parentWorkScaleFactor;
- this.submittedToParent += workInParent;
- } finally {
- this.lock.writeLock().unlock();
- }
- // Don't do this in the lock: it's incremental, but doing so might
cause deadlock with future changes
- this.parent.worked(workInParent);
- }
- }
-}
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-29
18:23:01 UTC (rev 598)
+++
trunk/dna-common/src/main/resources/org/jboss/dna/common/CommonI18n.properties 2008-10-29
20:09:42 UTC (rev 599)
@@ -66,13 +66,13 @@
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
-initialProgressMonitorTaskName =
-nullProgressMonitorTaskName = Not available
+initialActivityMonitorTaskName =
+nullActivityMonitorTaskName = Not available
pathAncestorDegreeIsInvalid = Unable to obtain the {1} ancestor for {0}
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
-progressMonitorBeginTask = Beginning {0} ({1})
-progressMonitorStatus = {0}
+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/component/ComponentLibraryTest.java
===================================================================
---
trunk/dna-common/src/test/java/org/jboss/dna/common/component/ComponentLibraryTest.java 2008-10-29
18:23:01 UTC (rev 598)
+++
trunk/dna-common/src/test/java/org/jboss/dna/common/component/ComponentLibraryTest.java 2008-10-29
20:09:42 UTC (rev 599)
@@ -28,7 +28,7 @@
import static org.hamcrest.core.IsSame.sameInstance;
import static org.junit.Assert.assertThat;
import java.util.List;
-import org.jboss.dna.common.monitor.ProgressMonitor;
+import org.jboss.dna.common.monitor.ActivityMonitor;
import org.junit.Before;
import org.junit.Test;
import org.mockito.MockitoAnnotations;
@@ -47,7 +47,7 @@
private String validDescription;
private String[] validClasspath;
@Mock
- private ProgressMonitor nullMonitor;
+ private ActivityMonitor nullMonitor;
@Before
public void beforeEach() {
Modified:
trunk/dna-common/src/test/java/org/jboss/dna/common/component/MockComponentA.java
===================================================================
---
trunk/dna-common/src/test/java/org/jboss/dna/common/component/MockComponentA.java 2008-10-29
18:23:01 UTC (rev 598)
+++
trunk/dna-common/src/test/java/org/jboss/dna/common/component/MockComponentA.java 2008-10-29
20:09:42 UTC (rev 599)
@@ -25,11 +25,13 @@
import java.util.concurrent.atomic.AtomicInteger;
import net.jcip.annotations.ThreadSafe;
import org.jboss.dna.common.i18n.MockI18n;
-import org.jboss.dna.common.monitor.ProgressMonitor;
+import org.jboss.dna.common.monitor.ActivityMonitor;
/**
* A sequencer that can be used for basic unit testing.
+ *
* @author Randall Hauch
+ * @author John Verhaeg
*/
@ThreadSafe
public class MockComponentA implements SampleComponent {
@@ -47,14 +49,14 @@
/**
* {@inheritDoc}
*/
- public void doSomething( ProgressMonitor progressMonitor ) {
+ public void doSomething( ActivityMonitor activityMonitor ) {
try {
- progressMonitor.beginTask(1, MockI18n.passthrough, "Incrementing
counter");
+ activityMonitor.beginTask(1, MockI18n.passthrough, "Incrementing
counter");
// increment the counter and record the progress ...
this.counter.incrementAndGet();
- progressMonitor.worked(1);
+ activityMonitor.worked(1);
} finally {
- progressMonitor.done();
+ activityMonitor.done();
}
}
Modified:
trunk/dna-common/src/test/java/org/jboss/dna/common/component/MockComponentB.java
===================================================================
---
trunk/dna-common/src/test/java/org/jboss/dna/common/component/MockComponentB.java 2008-10-29
18:23:01 UTC (rev 598)
+++
trunk/dna-common/src/test/java/org/jboss/dna/common/component/MockComponentB.java 2008-10-29
20:09:42 UTC (rev 599)
@@ -25,11 +25,13 @@
import java.util.concurrent.atomic.AtomicInteger;
import net.jcip.annotations.ThreadSafe;
import org.jboss.dna.common.i18n.MockI18n;
-import org.jboss.dna.common.monitor.ProgressMonitor;
+import org.jboss.dna.common.monitor.ActivityMonitor;
/**
* A sequencer that can be used for basic unit testing.
+ *
* @author Randall Hauch
+ * @author John Verhaeg
*/
@ThreadSafe
public class MockComponentB implements SampleComponent {
@@ -47,14 +49,14 @@
/**
* {@inheritDoc}
*/
- public void doSomething( ProgressMonitor progressMonitor ) {
+ public void doSomething( ActivityMonitor activityMonitor ) {
try {
- progressMonitor.beginTask(1, MockI18n.passthrough, "Incrementing
counter");
+ activityMonitor.beginTask(1, MockI18n.passthrough, "Incrementing
counter");
// increment the counter and record the progress ...
this.counter.incrementAndGet();
- progressMonitor.worked(1);
+ activityMonitor.worked(1);
} finally {
- progressMonitor.done();
+ activityMonitor.done();
}
}
Modified:
trunk/dna-common/src/test/java/org/jboss/dna/common/component/SampleComponent.java
===================================================================
---
trunk/dna-common/src/test/java/org/jboss/dna/common/component/SampleComponent.java 2008-10-29
18:23:01 UTC (rev 598)
+++
trunk/dna-common/src/test/java/org/jboss/dna/common/component/SampleComponent.java 2008-10-29
20:09:42 UTC (rev 599)
@@ -21,12 +21,13 @@
*/
package org.jboss.dna.common.component;
-import org.jboss.dna.common.monitor.ProgressMonitor;
+import org.jboss.dna.common.monitor.ActivityMonitor;
/**
* @author Randall Hauch
+ * @author John Verhaeg
*/
public interface SampleComponent extends Component<SampleComponentConfig> {
- public void doSomething( ProgressMonitor progressMonitor );
+ public void doSomething( ActivityMonitor activityMonitor );
}
Copied:
trunk/dna-common/src/test/java/org/jboss/dna/common/monitor/ActivityStatusTest.java (from
rev 596,
trunk/dna-common/src/test/java/org/jboss/dna/common/monitor/ProgressStatusTest.java)
===================================================================
--- trunk/dna-common/src/test/java/org/jboss/dna/common/monitor/ActivityStatusTest.java
(rev 0)
+++
trunk/dna-common/src/test/java/org/jboss/dna/common/monitor/ActivityStatusTest.java 2008-10-29
20:09:42 UTC (rev 599)
@@ -0,0 +1,66 @@
+/*
+ * 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.number.IsCloseTo.closeTo;
+import static org.junit.Assert.assertThat;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author Randall Hauch
+ * @author John Verhaeg
+ */
+public class ActivityStatusTest {
+
+ private ActivityStatus status;
+ private String validActivityName;
+ private String validTaskName;
+
+ @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);
+ }
+
+ @Test
+ public void shouldComputePercentageAs100PercentIfWithinPrecision() {
+ assertThat(ActivityStatus.computePercentage(100.0d -
(ActivityStatus.PERCENT_PRECISION / 2.0d), 100.0d),
+ is(closeTo(100.0d, ActivityStatus.PERCENT_PRECISION)));
+ }
+
+ @Test
+ public void shouldComputePercentageOfZeroWorkAsZero() {
+ // Note that we should not get a divide by zero !!!
+ assertThat(ActivityStatus.computePercentage(0.0d, 0.0d), is(closeTo(0.0d,
ActivityStatus.PERCENT_PRECISION)));
+ assertThat(ActivityStatus.computePercentage(0.0d, 100.0d), is(closeTo(0.0d,
ActivityStatus.PERCENT_PRECISION)));
+ }
+
+ @Test
+ public void shouldHaveToStringThatIncludesPercentage() {
+ // System.out.println(this.status);
+ assertThat(this.status.toString().indexOf("10.0 %") > 0, is(true));
+ }
+}
Deleted:
trunk/dna-common/src/test/java/org/jboss/dna/common/monitor/ProgressStatusTest.java
===================================================================
---
trunk/dna-common/src/test/java/org/jboss/dna/common/monitor/ProgressStatusTest.java 2008-10-29
18:23:01 UTC (rev 598)
+++
trunk/dna-common/src/test/java/org/jboss/dna/common/monitor/ProgressStatusTest.java 2008-10-29
20:09:42 UTC (rev 599)
@@ -1,65 +0,0 @@
-/*
- * 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.number.IsCloseTo.closeTo;
-import static org.junit.Assert.assertThat;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * @author Randall Hauch
- */
-public class ProgressStatusTest {
-
- private ProgressStatus status;
- private String validActivityName;
- private String validTaskName;
-
- @Before
- public void beforeEach() {
- this.validActivityName = "Reading from file X";
- this.validTaskName = "Checking for file";
- this.status = new ProgressStatus(this.validActivityName, this.validTaskName,
10.0d, false);
- }
-
- @Test
- public void shouldComputePercentageAs100PercentIfWithinPrecision() {
- assertThat(ProgressStatus.computePercentage(100.0d -
(ProgressStatus.PERCENT_PRECISION / 2.0d), 100.0d),
- is(closeTo(100.0d, ProgressStatus.PERCENT_PRECISION)));
- }
-
- @Test
- public void shouldComputePercentageOfZeroWorkAsZero() {
- // Note that we should not get a divide by zero !!!
- assertThat(ProgressStatus.computePercentage(0.0d, 0.0d), is(closeTo(0.0d,
ProgressStatus.PERCENT_PRECISION)));
- assertThat(ProgressStatus.computePercentage(0.0d, 100.0d), is(closeTo(0.0d,
ProgressStatus.PERCENT_PRECISION)));
- }
-
- @Test
- public void shouldHaveToStringThatIncludesPercentage() {
- // System.out.println(this.status);
- assertThat(this.status.toString().indexOf("10.0 %") > 0, is(true));
- }
-}
Copied:
trunk/dna-common/src/test/java/org/jboss/dna/common/monitor/RecordingActivityMonitor.java
(from rev 596,
trunk/dna-common/src/test/java/org/jboss/dna/common/monitor/RecordingProgressMonitor.java)
===================================================================
---
trunk/dna-common/src/test/java/org/jboss/dna/common/monitor/RecordingActivityMonitor.java
(rev 0)
+++
trunk/dna-common/src/test/java/org/jboss/dna/common/monitor/RecordingActivityMonitor.java 2008-10-29
20:09:42 UTC (rev 599)
@@ -0,0 +1,111 @@
+/*
+ * 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 org.jboss.dna.common.i18n.I18n;
+import org.jboss.dna.common.i18n.MockI18n;
+
+/**
+ * @author Randall Hauch
+ * @author John Verhaeg
+ */
+public class RecordingActivityMonitor extends ActivityMonitorWrapper {
+
+ private int beginTaskCount;
+ private int doneCount;
+ private int createSubtaskCount;
+ private int setCancelledCount;
+
+ public RecordingActivityMonitor( ActivityMonitor delegate ) {
+ super(delegate);
+ }
+
+ public RecordingActivityMonitor( String name ) {
+ this(new SimpleActivityMonitor(MockI18n.passthrough, name));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void beginTask( double totalWork,
+ I18n name,
+ Object... params ) {
+ ++beginTaskCount;
+ super.beginTask(totalWork, name, params);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void done() {
+ ++doneCount;
+ super.done();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public ActivityMonitor createSubtask( double subtaskWork ) {
+ ++createSubtaskCount;
+ return super.createSubtask(subtaskWork);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void setCancelled( boolean value ) {
+ ++setCancelledCount;
+ super.setCancelled(value);
+ }
+
+ /**
+ * @return beginTaskCount
+ */
+ public int getBeginTaskCount() {
+ return this.beginTaskCount;
+ }
+
+ /**
+ * @return doneCount
+ */
+ public int getDoneCount() {
+ return this.doneCount;
+ }
+
+ /**
+ * @return createSubtaskCount
+ */
+ public int getCreateSubtaskCount() {
+ return this.createSubtaskCount;
+ }
+
+ /**
+ * @return setCancelledCount
+ */
+ public int getSetCancelledCount() {
+ return this.setCancelledCount;
+ }
+}
Property changes on:
trunk/dna-common/src/test/java/org/jboss/dna/common/monitor/RecordingActivityMonitor.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Deleted:
trunk/dna-common/src/test/java/org/jboss/dna/common/monitor/RecordingProgressMonitor.java
===================================================================
---
trunk/dna-common/src/test/java/org/jboss/dna/common/monitor/RecordingProgressMonitor.java 2008-10-29
18:23:01 UTC (rev 598)
+++
trunk/dna-common/src/test/java/org/jboss/dna/common/monitor/RecordingProgressMonitor.java 2008-10-29
20:09:42 UTC (rev 599)
@@ -1,114 +0,0 @@
-/*
- * 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 org.jboss.dna.common.i18n.I18n;
-
-/**
- * @author Randall Hauch
- */
-public class RecordingProgressMonitor extends ProgressMonitorWrapper {
-
- private int beginTaskCount;
- private int doneCount;
- private int createSubtaskCount;
- private int setCancelledCount;
-
- public RecordingProgressMonitor( ProgressMonitor delegate ) {
- super(delegate);
- }
-
- public RecordingProgressMonitor( String name ) {
- this(name, null);
- }
-
- public RecordingProgressMonitor( String name,
- ProgressMonitor parentProgressMonitor ) {
- this(new SimpleProgressMonitor(name, parentProgressMonitor));
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void beginTask( double totalWork,
- I18n name,
- Object... params ) {
- ++beginTaskCount;
- super.beginTask(totalWork, name, params);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void done() {
- ++doneCount;
- super.done();
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public ProgressMonitor createSubtask( double subtaskWork ) {
- ++createSubtaskCount;
- return super.createSubtask(subtaskWork);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void setCancelled( boolean value ) {
- ++setCancelledCount;
- super.setCancelled(value);
- }
-
- /**
- * @return beginTaskCount
- */
- public int getBeginTaskCount() {
- return this.beginTaskCount;
- }
-
- /**
- * @return doneCount
- */
- public int getDoneCount() {
- return this.doneCount;
- }
-
- /**
- * @return createSubtaskCount
- */
- public int getCreateSubtaskCount() {
- return this.createSubtaskCount;
- }
-
- /**
- * @return setCancelledCount
- */
- public int getSetCancelledCount() {
- return this.setCancelledCount;
- }
-}
Copied:
trunk/dna-common/src/test/java/org/jboss/dna/common/monitor/SimpleActivityMonitorTest.java
(from rev 596,
trunk/dna-common/src/test/java/org/jboss/dna/common/monitor/SimpleProgressMonitorTest.java)
===================================================================
---
trunk/dna-common/src/test/java/org/jboss/dna/common/monitor/SimpleActivityMonitorTest.java
(rev 0)
+++
trunk/dna-common/src/test/java/org/jboss/dna/common/monitor/SimpleActivityMonitorTest.java 2008-10-29
20:09:42 UTC (rev 599)
@@ -0,0 +1,356 @@
+/*
+ * 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.IsInstanceOf.instanceOf;
+import static org.hamcrest.core.IsNull.notNullValue;
+import static org.hamcrest.core.IsSame.sameInstance;
+import static org.hamcrest.number.IsCloseTo.closeTo;
+import static org.junit.Assert.assertThat;
+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.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author Randall Hauch
+ * @author John Verhaeg
+ */
+public class SimpleActivityMonitorTest {
+
+ private static final String VALID_TASK_NAME = "Checking for file";
+
+ private ActivityMonitor monitor;
+
+ @Before
+ public void beforeEach() {
+ this.monitor = new SimpleActivityMonitor(MockI18n.passthrough, "Reading from
file X");
+ }
+
+ @Test
+ public void shouldNotBeCancelledUponCreation() {
+ assertThat(monitor.isCancelled(), is(false));
+ }
+
+ @Test
+ public void shouldReturnActivityStatusWithEmptyMessageBeforeTaskIsBegun() {
+ ActivityStatus status = monitor.getStatus(Locale.FRANCE);
+ assertThat(status, is(notNullValue()));
+ assertThat(status.getMessage(), is(""));
+ assertThat(status.getPercentWorked(), is(closeTo(0.0d, 0.001d)));
+
+ status = monitor.getStatus(null);
+ assertThat(status, is(notNullValue()));
+ assertThat(status.getMessage(), is(""));
+ assertThat(status.getPercentWorked(), is(closeTo(0.0d, 0.001d)));
+ }
+
+ @Test
+ public void shouldReturnActivityStatusWithCorrectMessageAfterTaskIsBegun() {
+ monitor.beginTask(100, I18nMessages.testTaskName);
+ monitor.worked(10.0d);
+ ActivityStatus status = monitor.getStatus(Locale.FRANCE);
+ assertThat(status, is(notNullValue()));
+ assertThat(status.getMessage(), 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.getPercentWorked(), is(closeTo(10.0d, 0.001d)));
+
+ status = monitor.getStatus(Locale.getDefault());
+ assertThat(status, is(notNullValue()));
+ assertThat(status.getMessage(), 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.getPercentWorked(), is(closeTo(10.0d, 0.001d)));
+ }
+
+ @Test
+ public void
shouldReturnActivityStatusWithCorrectMessageAndSubstitutedParametersAfterTaskIsBegun() {
+ monitor.beginTask(100, I18nMessages.testTaskName2, 2);
+ monitor.worked(10.0d);
+ ActivityStatus status = monitor.getStatus(Locale.FRANCE);
+ assertThat(status, is(notNullValue()));
+ assertThat(status.getMessage(), 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.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.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.getPercentWorked(), is(closeTo(10.0d, 0.001d)));
+ }
+
+ @Test
+ public void shouldHaveProgressOfZeroPercentUponCreation() {
+ ActivityStatus status = monitor.getStatus(null);
+ assertThat(status, is(notNullValue()));
+ assertThat(status.getActivityName(), is(monitor.getActivityName()));
+ assertThat(status.getMessage(), is(""));
+ assertThat(status.getPercentWorked(), is(closeTo(0.0d, 0.001d)));
+ }
+
+ @Test
+ public void shouldHaveProgressOfZeroPercentUponBeginningTask() {
+ this.monitor.beginTask(100, MockI18n.passthrough, VALID_TASK_NAME);
+ ActivityStatus status = monitor.getStatus(null);
+ assertThat(status, is(notNullValue()));
+ assertThat(status.getActivityName(), is(monitor.getActivityName()));
+ assertThat(status.getMessage(), is(VALID_TASK_NAME));
+ assertThat(status.getPercentWorked(), is(closeTo(0.0d, 0.001d)));
+ }
+
+ @Test
+ public void shouldShowProperStatus() {
+ this.monitor.beginTask(1000, MockI18n.passthrough, VALID_TASK_NAME);
+ ActivityStatus status = monitor.getStatus(null);
+ assertThat(status, is(notNullValue()));
+ assertThat(status.getActivityName(), is(monitor.getActivityName()));
+ assertThat(status.getMessage(), is(VALID_TASK_NAME));
+ assertThat(status.getPercentWorked(), is(closeTo(0.0d, 0.001d)));
+ for (int i = 1; i <= 9; ++i) {
+ this.monitor.worked(100);
+ // Check the monitor's status ...
+ status = monitor.getStatus(null);
+ assertThat(status, is(notNullValue()));
+ assertThat(status.getActivityName(), is(monitor.getActivityName()));
+ assertThat(status.getMessage(), is(VALID_TASK_NAME));
+ assertThat(status.getPercentWorked(), is(closeTo(10 * i, 0.001d)));
+ assertThat(status.isDone(), is(false));
+ }
+ monitor.done();
+ // Check the monitor's status shows 100%
+ status = monitor.getStatus(null);
+ assertThat(status, is(notNullValue()));
+ assertThat(status.getActivityName(), is(monitor.getActivityName()));
+ assertThat(status.getMessage(), is(VALID_TASK_NAME));
+ assertThat(status.getPercentWorked(), is(closeTo(100, 0.001d)));
+ assertThat(status.isDone(), is(true));
+ }
+
+ @Test
+ public void shouldShowProperStatusUsingSubtasks() {
+ monitor.beginTask(1000, MockI18n.passthrough, VALID_TASK_NAME);
+ ActivityStatus status = monitor.getStatus(null);
+ assertThat(status, is(notNullValue()));
+ assertThat(status.getActivityName(), is(monitor.getActivityName()));
+ assertThat(status.getMessage(), is(VALID_TASK_NAME));
+ assertThat(status.getPercentWorked(), is(closeTo(0.0d, 0.001d)));
+
+ // Create subtasks ...
+ for (int i = 1; i <= 9; ++i) {
+ ActivityMonitor subtask = monitor.createSubtask(100);
+ assertThat(subtask, is(notNullValue()));
+ assertThat(subtask, is(instanceOf(SubActivityMonitor.class)));
+ assertThat(((SubActivityMonitor)subtask).getParent(),
is(sameInstance(monitor)));
+
+ String subtaskName = "Subtask " + i;
+ subtask.beginTask(10, MockI18n.passthrough, subtaskName); // note the
different total work for the subtask
+ for (int j = 1; j <= 10; ++j) {
+ // Work the subtask
+ subtask.worked(1);
+
+ // Check the submonitor's status
+ status = subtask.getStatus(null);
+ assertThat(status, is(notNullValue()));
+ assertThat(status.getActivityName(), is(monitor.getActivityName()));
+ assertThat(status.getMessage(), is(subtaskName));
+ assertThat(status.getPercentWorked(), is(closeTo(10 * j, 0.001d)));
+ assertThat(status.isDone(), is(j == 10));
+
+ // System.out.println(status);
+ }
+ subtask.done();
+
+ // Check the main monitor's status
+ status = monitor.getStatus(null);
+ assertThat(status, is(notNullValue()));
+ assertThat(status.getActivityName(), is(monitor.getActivityName()));
+ assertThat(status.getMessage(), is(VALID_TASK_NAME));
+ assertThat(status.getPercentWorked(), is(closeTo(10 * i, 0.001d)));
+ assertThat(status.isDone(), is(false));
+ }
+ monitor.done();
+
+ // Check the monitor's status shows 100%
+ status = monitor.getStatus(null);
+ assertThat(status, is(notNullValue()));
+ assertThat(status.getActivityName(), is(monitor.getActivityName()));
+ assertThat(status.getMessage(), is(VALID_TASK_NAME));
+ assertThat(status.getPercentWorked(), is(closeTo(100, 0.001d)));
+ assertThat(status.isDone(), is(true));
+ }
+
+ @Test
+ public void shouldAllowDoneToBeCalledEvenAfterFinished() {
+ monitor.beginTask(1000, MockI18n.passthrough, VALID_TASK_NAME);
+ ActivityStatus status = monitor.getStatus(null);
+ assertThat(status, is(notNullValue()));
+ assertThat(status.getActivityName(), is(monitor.getActivityName()));
+ assertThat(status.getMessage(), is(VALID_TASK_NAME));
+ assertThat(status.getPercentWorked(), is(closeTo(0.0d, 0.001d)));
+ assertThat(status.isDone(), is(false));
+
+ for (int i = 0; i != 3; ++i) {
+ // Just mark it as done ...
+ monitor.done();
+
+ // Check the status ...
+ status = monitor.getStatus(null);
+ assertThat(status, is(notNullValue()));
+ assertThat(status.getActivityName(), is(monitor.getActivityName()));
+ assertThat(status.getMessage(), is(VALID_TASK_NAME));
+ assertThat(status.getPercentWorked(), is(closeTo(100, 0.001d)));
+ assertThat(status.isDone(), is(true));
+ }
+ }
+
+ @Test
+ public void shouldNotBeMarkedAsDoneAfterCancel() {
+ monitor.beginTask(100, MockI18n.passthrough, VALID_TASK_NAME);
+ monitor.setCancelled(true);
+ assertThat(monitor.isCancelled(), is(true));
+ assertThat(monitor.isDone(), is(false));
+ }
+
+ @Test
+ public void shouldAllowCancelToBeRejected() {
+ monitor.beginTask(1000, MockI18n.passthrough, VALID_TASK_NAME);
+ ActivityStatus status = monitor.getStatus(null);
+ assertThat(status, is(notNullValue()));
+ assertThat(status.getActivityName(), is(monitor.getActivityName()));
+ assertThat(status.getMessage(), is(VALID_TASK_NAME));
+ assertThat(status.getPercentWorked(), is(closeTo(0.0d, 0.001d)));
+ for (int i = 1; i <= 9; ++i) {
+ monitor.worked(100);
+
+ // Check the monitor's status ...
+ status = monitor.getStatus(null);
+ assertThat(status, is(notNullValue()));
+ assertThat(status.getActivityName(), is(monitor.getActivityName()));
+ assertThat(status.getMessage(), is(VALID_TASK_NAME));
+ assertThat(status.getPercentWorked(), is(closeTo(10 * i, 0.001d)));
+ assertThat(status.isDone(), is(false));
+
+ // Cancel the activity ...
+ monitor.setCancelled(true);
+ assertThat(monitor.isCancelled(), is(true));
+ }
+ monitor.done();
+ // Check the monitor's status shows 100%
+ status = monitor.getStatus(null);
+ assertThat(status, is(notNullValue()));
+ assertThat(status.getActivityName(), is(monitor.getActivityName()));
+ assertThat(status.getMessage(), is(VALID_TASK_NAME));
+ assertThat(status.getPercentWorked(), is(closeTo(100, 0.001d)));
+ assertThat(status.isDone(), is(true));
+
+ }
+
+ @Test
+ public void shouldContinueToRecordWorkEvenWhenCancelled() {
+ monitor.beginTask(1000, MockI18n.passthrough, VALID_TASK_NAME);
+ ActivityStatus status = monitor.getStatus(null);
+ assertThat(status, is(notNullValue()));
+ assertThat(status.getActivityName(), is(monitor.getActivityName()));
+ assertThat(status.getMessage(), is(VALID_TASK_NAME));
+ assertThat(status.getPercentWorked(), is(closeTo(0.0d, 0.001d)));
+ for (int i = 1; i <= 9; ++i) {
+ monitor.worked(100);
+
+ // Check the monitor's status ...
+ status = monitor.getStatus(null);
+ assertThat(status, is(notNullValue()));
+ assertThat(status.getActivityName(), is(monitor.getActivityName()));
+ assertThat(status.getMessage(), is(VALID_TASK_NAME));
+ assertThat(status.getPercentWorked(), is(closeTo(10 * i, 0.001d)));
+ assertThat(status.isDone(), is(false));
+
+ // Cancel the activity ...
+ monitor.setCancelled(true);
+ assertThat(monitor.isCancelled(), is(monitor.isCancelled()));
+ }
+ monitor.done();
+ // Check the monitor's status shows 100%
+ status = monitor.getStatus(null);
+ assertThat(status, is(notNullValue()));
+ assertThat(status.getActivityName(), is(monitor.getActivityName()));
+ assertThat(status.getMessage(), 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 static class I18nMessages {
+
+ public static I18n testTaskName;
+ public static I18n testTaskName2;
+
+ static {
+ try {
+ I18n.initialize(SimpleActivityMonitorTest.I18nMessages.class);
+ } catch (final Exception err) {
+ System.err.println(err);
+ }
+ }
+
+ public static Set<Locale> getLocalizationProblemLocales() {
+ return I18n.getLocalizationProblemLocales(CommonI18n.class);
+ }
+
+ public static Set<String> getLocalizationProblems() {
+ return I18n.getLocalizationProblems(CommonI18n.class);
+ }
+
+ public static Set<String> getLocalizationProblems( Locale locale ) {
+ return I18n.getLocalizationProblems(CommonI18n.class, locale);
+ }
+
+ }
+}
Deleted:
trunk/dna-common/src/test/java/org/jboss/dna/common/monitor/SimpleProgressMonitorTest.java
===================================================================
---
trunk/dna-common/src/test/java/org/jboss/dna/common/monitor/SimpleProgressMonitorTest.java 2008-10-29
18:23:01 UTC (rev 598)
+++
trunk/dna-common/src/test/java/org/jboss/dna/common/monitor/SimpleProgressMonitorTest.java 2008-10-29
20:09:42 UTC (rev 599)
@@ -1,358 +0,0 @@
-/*
- * 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.IsInstanceOf.instanceOf;
-import static org.hamcrest.core.IsNull.notNullValue;
-import static org.hamcrest.core.IsSame.sameInstance;
-import static org.hamcrest.number.IsCloseTo.closeTo;
-import static org.junit.Assert.assertThat;
-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.junit.Before;
-import org.junit.Test;
-
-/**
- * @author Randall Hauch
- * @author John Verhaeg
- */
-public class SimpleProgressMonitorTest {
-
- private ProgressMonitor monitor;
- private String validActivityName;
- private String validTaskName;
-
- @Before
- public void beforeEach() {
- this.validActivityName = "Reading from file X";
- this.validTaskName = "Checking for file";
- this.monitor = new SimpleProgressMonitor(this.validActivityName);
- }
-
- @Test
- public void shouldNotBeCancelledUponCreation() {
- assertThat(monitor.isCancelled(), is(false));
- }
-
- @Test
- public void shouldReturnProgressStatusWithEmptyMessageBeforeTaskIsBegun() {
- ProgressStatus status = monitor.getStatus(Locale.FRANCE);
- assertThat(status, is(notNullValue()));
- assertThat(status.getMessage(), is(""));
- assertThat(status.getPercentWorked(), is(closeTo(0.0d, 0.001d)));
-
- status = monitor.getStatus(null);
- assertThat(status, is(notNullValue()));
- assertThat(status.getMessage(), is(""));
- assertThat(status.getPercentWorked(), is(closeTo(0.0d, 0.001d)));
- }
-
- @Test
- public void shouldReturnProgressStatusWithCorrectMessageAfterTaskIsBegun() {
- monitor.beginTask(100, I18nMessages.testTaskName);
- monitor.worked(10.0d);
- ProgressStatus status = monitor.getStatus(Locale.FRANCE);
- assertThat(status, is(notNullValue()));
- assertThat(status.getMessage(), 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.getPercentWorked(), is(closeTo(10.0d, 0.001d)));
-
- status = monitor.getStatus(Locale.getDefault());
- assertThat(status, is(notNullValue()));
- assertThat(status.getMessage(), 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.getPercentWorked(), is(closeTo(10.0d, 0.001d)));
- }
-
- @Test
- public void
shouldReturnProgressStatusWithCorrectMessageAndSubstitutedParametersAfterTaskIsBegun() {
- monitor.beginTask(100, I18nMessages.testTaskName2, 2);
- monitor.worked(10.0d);
- ProgressStatus status = monitor.getStatus(Locale.FRANCE);
- assertThat(status, is(notNullValue()));
- assertThat(status.getMessage(), 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.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.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.getPercentWorked(), is(closeTo(10.0d, 0.001d)));
- }
-
- @Test
- public void shouldHaveProgressOfZeroPercentUponCreation() {
- ProgressStatus status = monitor.getStatus(null);
- assertThat(status, is(notNullValue()));
- assertThat(status.getActivityName(),
is(sameInstance(monitor.getActivityName())));
- assertThat(status.getMessage(), is(""));
- assertThat(status.getPercentWorked(), is(closeTo(0.0d, 0.001d)));
- }
-
- @Test
- public void shouldHaveProgressOfZeroPercentUponBeginningTask() {
- this.monitor.beginTask(100, MockI18n.passthrough, validTaskName);
- ProgressStatus status = monitor.getStatus(null);
- assertThat(status, is(notNullValue()));
- assertThat(status.getActivityName(),
is(sameInstance(monitor.getActivityName())));
- assertThat(status.getMessage(), is(validTaskName));
- assertThat(status.getPercentWorked(), is(closeTo(0.0d, 0.001d)));
- }
-
- @Test
- public void shouldShowProperProgress() {
- this.monitor.beginTask(1000, MockI18n.passthrough, validTaskName);
- ProgressStatus status = monitor.getStatus(null);
- assertThat(status, is(notNullValue()));
- assertThat(status.getActivityName(),
is(sameInstance(monitor.getActivityName())));
- assertThat(status.getMessage(), is(validTaskName));
- assertThat(status.getPercentWorked(), is(closeTo(0.0d, 0.001d)));
- for (int i = 1; i <= 9; ++i) {
- this.monitor.worked(100);
- // Check the monitor's status ...
- status = monitor.getStatus(null);
- assertThat(status, is(notNullValue()));
- assertThat(status.getActivityName(),
is(sameInstance(monitor.getActivityName())));
- assertThat(status.getMessage(), is(validTaskName));
- assertThat(status.getPercentWorked(), is(closeTo(10 * i, 0.001d)));
- assertThat(status.isDone(), is(false));
- }
- monitor.done();
- // Check the monitor's status shows 100%
- status = monitor.getStatus(null);
- assertThat(status, is(notNullValue()));
- assertThat(status.getActivityName(),
is(sameInstance(monitor.getActivityName())));
- assertThat(status.getMessage(), is(validTaskName));
- assertThat(status.getPercentWorked(), is(closeTo(100, 0.001d)));
- assertThat(status.isDone(), is(true));
- }
-
- @Test
- public void shouldShowProperProgressUsingSubtasks() {
- monitor.beginTask(1000, MockI18n.passthrough, validTaskName);
- ProgressStatus status = monitor.getStatus(null);
- assertThat(status, is(notNullValue()));
- assertThat(status.getActivityName(),
is(sameInstance(monitor.getActivityName())));
- assertThat(status.getMessage(), is(validTaskName));
- assertThat(status.getPercentWorked(), is(closeTo(0.0d, 0.001d)));
-
- // Create subtasks ...
- for (int i = 1; i <= 9; ++i) {
- ProgressMonitor subtask = monitor.createSubtask(100);
- assertThat(subtask, is(notNullValue()));
- assertThat(subtask, is(instanceOf(SubProgressMonitor.class)));
- assertThat(((SubProgressMonitor)subtask).getParent(),
is(sameInstance(monitor)));
-
- String subtaskName = "Subtask " + i;
- subtask.beginTask(10, MockI18n.passthrough, subtaskName); // note the
different total work for the subtask
- for (int j = 1; j <= 10; ++j) {
- // Work the subtask
- subtask.worked(1);
-
- // Check the submonitor's status
- status = subtask.getStatus(null);
- assertThat(status, is(notNullValue()));
- assertThat(status.getActivityName(),
is(sameInstance(monitor.getActivityName())));
- assertThat(status.getMessage(), is(subtaskName));
- assertThat(status.getPercentWorked(), is(closeTo(10 * j, 0.001d)));
- assertThat(status.isDone(), is(j == 10));
-
- // System.out.println(status);
- }
- subtask.done();
-
- // Check the main monitor's status
- status = monitor.getStatus(null);
- assertThat(status, is(notNullValue()));
- assertThat(status.getActivityName(),
is(sameInstance(monitor.getActivityName())));
- assertThat(status.getMessage(), is(validTaskName));
- assertThat(status.getPercentWorked(), is(closeTo(10 * i, 0.001d)));
- assertThat(status.isDone(), is(false));
- }
- monitor.done();
-
- // Check the monitor's status shows 100%
- status = monitor.getStatus(null);
- assertThat(status, is(notNullValue()));
- assertThat(status.getActivityName(),
is(sameInstance(monitor.getActivityName())));
- assertThat(status.getMessage(), is(validTaskName));
- assertThat(status.getPercentWorked(), is(closeTo(100, 0.001d)));
- assertThat(status.isDone(), is(true));
- }
-
- @Test
- public void shouldAllowDoneToBeCalledEvenAfterFinished() {
- monitor.beginTask(1000, MockI18n.passthrough, validTaskName);
- ProgressStatus status = monitor.getStatus(null);
- assertThat(status, is(notNullValue()));
- assertThat(status.getActivityName(),
is(sameInstance(monitor.getActivityName())));
- assertThat(status.getMessage(), is(validTaskName));
- assertThat(status.getPercentWorked(), is(closeTo(0.0d, 0.001d)));
- assertThat(status.isDone(), is(false));
-
- for (int i = 0; i != 3; ++i) {
- // Just mark it as done ...
- monitor.done();
-
- // Check the status ...
- status = monitor.getStatus(null);
- assertThat(status, is(notNullValue()));
- assertThat(status.getActivityName(),
is(sameInstance(monitor.getActivityName())));
- assertThat(status.getMessage(), is(validTaskName));
- assertThat(status.getPercentWorked(), is(closeTo(100, 0.001d)));
- assertThat(status.isDone(), is(true));
- }
- }
-
- @Test
- public void shouldNotBeMarkedAsDoneAfterCancel() {
- monitor.beginTask(100, MockI18n.passthrough, validTaskName);
- monitor.setCancelled(true);
- assertThat(monitor.isCancelled(), is(true));
- assertThat(monitor.isDone(), is(false));
- }
-
- @Test
- public void shouldAllowCancelToBeRejected() {
- monitor.beginTask(1000, MockI18n.passthrough, validTaskName);
- ProgressStatus status = monitor.getStatus(null);
- assertThat(status, is(notNullValue()));
- assertThat(status.getActivityName(),
is(sameInstance(monitor.getActivityName())));
- assertThat(status.getMessage(), is(validTaskName));
- assertThat(status.getPercentWorked(), is(closeTo(0.0d, 0.001d)));
- for (int i = 1; i <= 9; ++i) {
- monitor.worked(100);
-
- // Check the monitor's status ...
- status = monitor.getStatus(null);
- assertThat(status, is(notNullValue()));
- assertThat(status.getActivityName(),
is(sameInstance(monitor.getActivityName())));
- assertThat(status.getMessage(), is(validTaskName));
- assertThat(status.getPercentWorked(), is(closeTo(10 * i, 0.001d)));
- assertThat(status.isDone(), is(false));
-
- // Cancel the activity ...
- monitor.setCancelled(true);
- assertThat(monitor.isCancelled(), is(true));
- }
- monitor.done();
- // Check the monitor's status shows 100%
- status = monitor.getStatus(null);
- assertThat(status, is(notNullValue()));
- assertThat(status.getActivityName(),
is(sameInstance(monitor.getActivityName())));
- assertThat(status.getMessage(), is(validTaskName));
- assertThat(status.getPercentWorked(), is(closeTo(100, 0.001d)));
- assertThat(status.isDone(), is(true));
-
- }
-
- @Test
- public void shouldContinueToRecordWorkEvenWhenCancelled() {
- monitor.beginTask(1000, MockI18n.passthrough, validTaskName);
- ProgressStatus status = monitor.getStatus(null);
- assertThat(status, is(notNullValue()));
- assertThat(status.getActivityName(),
is(sameInstance(monitor.getActivityName())));
- assertThat(status.getMessage(), is(validTaskName));
- assertThat(status.getPercentWorked(), is(closeTo(0.0d, 0.001d)));
- for (int i = 1; i <= 9; ++i) {
- monitor.worked(100);
-
- // Check the monitor's status ...
- status = monitor.getStatus(null);
- assertThat(status, is(notNullValue()));
- assertThat(status.getActivityName(),
is(sameInstance(monitor.getActivityName())));
- assertThat(status.getMessage(), is(validTaskName));
- assertThat(status.getPercentWorked(), is(closeTo(10 * i, 0.001d)));
- assertThat(status.isDone(), is(false));
-
- // Cancel the activity ...
- monitor.setCancelled(true);
- assertThat(monitor.isCancelled(), is(monitor.isCancelled()));
- }
- monitor.done();
- // Check the monitor's status shows 100%
- status = monitor.getStatus(null);
- assertThat(status, is(notNullValue()));
- assertThat(status.getActivityName(),
is(sameInstance(monitor.getActivityName())));
- assertThat(status.getMessage(), is(validTaskName));
- 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, validTaskName);
- monitor.getProblems().addWarning(MockI18n.passthrough);
- monitor.done();
- assertThat(monitor.getProblems().hasWarnings(), is(true));
- }
-
- public static class I18nMessages {
-
- public static I18n testTaskName;
- public static I18n testTaskName2;
-
- static {
- try {
- I18n.initialize(SimpleProgressMonitorTest.I18nMessages.class);
- } catch (final Exception err) {
- System.err.println(err);
- }
- }
-
- public static Set<Locale> getLocalizationProblemLocales() {
- return I18n.getLocalizationProblemLocales(CommonI18n.class);
- }
-
- public static Set<String> getLocalizationProblems() {
- return I18n.getLocalizationProblems(CommonI18n.class);
- }
-
- public static Set<String> getLocalizationProblems( Locale locale ) {
- return I18n.getLocalizationProblems(CommonI18n.class, locale);
- }
-
- }
-}
Copied:
trunk/dna-common/src/test/resources/org/jboss/dna/common/monitor/SimpleActivityMonitorTest$I18nMessages_en.properties
(from rev 598,
trunk/dna-common/src/test/resources/org/jboss/dna/common/monitor/SimpleProgressMonitorTest$I18nMessages_en.properties)
===================================================================
---
trunk/dna-common/src/test/resources/org/jboss/dna/common/monitor/SimpleActivityMonitorTest$I18nMessages_en.properties
(rev 0)
+++
trunk/dna-common/src/test/resources/org/jboss/dna/common/monitor/SimpleActivityMonitorTest$I18nMessages_en.properties 2008-10-29
20:09:42 UTC (rev 599)
@@ -0,0 +1,2 @@
+testTaskName = test task
+testTaskName2 = second test task {0}
\ No newline at end of file
Property changes on:
trunk/dna-common/src/test/resources/org/jboss/dna/common/monitor/SimpleActivityMonitorTest$I18nMessages_en.properties
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:mime-type
+ text/plain
Copied:
trunk/dna-common/src/test/resources/org/jboss/dna/common/monitor/SimpleActivityMonitorTest$I18nMessages_fr.properties
(from rev 598,
trunk/dna-common/src/test/resources/org/jboss/dna/common/monitor/SimpleProgressMonitorTest$I18nMessages_fr.properties)
===================================================================
---
trunk/dna-common/src/test/resources/org/jboss/dna/common/monitor/SimpleActivityMonitorTest$I18nMessages_fr.properties
(rev 0)
+++
trunk/dna-common/src/test/resources/org/jboss/dna/common/monitor/SimpleActivityMonitorTest$I18nMessages_fr.properties 2008-10-29
20:09:42 UTC (rev 599)
@@ -0,0 +1,2 @@
+testTaskName = examinez le message
+testTaskName2 = examinez le message {0}
\ No newline at end of file
Property changes on:
trunk/dna-common/src/test/resources/org/jboss/dna/common/monitor/SimpleActivityMonitorTest$I18nMessages_fr.properties
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:mime-type
+ text/plain
Deleted:
trunk/dna-common/src/test/resources/org/jboss/dna/common/monitor/SimpleProgressMonitorTest$I18nMessages_en.properties
===================================================================
---
trunk/dna-common/src/test/resources/org/jboss/dna/common/monitor/SimpleProgressMonitorTest$I18nMessages_en.properties 2008-10-29
18:23:01 UTC (rev 598)
+++
trunk/dna-common/src/test/resources/org/jboss/dna/common/monitor/SimpleProgressMonitorTest$I18nMessages_en.properties 2008-10-29
20:09:42 UTC (rev 599)
@@ -1,2 +0,0 @@
-testTaskName = test task
-testTaskName2 = second test task {0}
\ No newline at end of file
Deleted:
trunk/dna-common/src/test/resources/org/jboss/dna/common/monitor/SimpleProgressMonitorTest$I18nMessages_fr.properties
===================================================================
---
trunk/dna-common/src/test/resources/org/jboss/dna/common/monitor/SimpleProgressMonitorTest$I18nMessages_fr.properties 2008-10-29
18:23:01 UTC (rev 598)
+++
trunk/dna-common/src/test/resources/org/jboss/dna/common/monitor/SimpleProgressMonitorTest$I18nMessages_fr.properties 2008-10-29
20:09:42 UTC (rev 599)
@@ -1,2 +0,0 @@
-testTaskName = examinez le message
-testTaskName2 = examinez le message {0}
\ No newline at end of file
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/ExecutionContext.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/ExecutionContext.java 2008-10-29
18:23:01 UTC (rev 598)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/ExecutionContext.java 2008-10-29
20:09:42 UTC (rev 599)
@@ -25,7 +25,7 @@
import javax.security.auth.Subject;
import javax.security.auth.login.LoginContext;
import org.jboss.dna.common.component.ClassLoaderFactory;
-import org.jboss.dna.common.monitor.ProgressMonitor;
+import org.jboss.dna.common.monitor.ActivityMonitor;
import org.jboss.dna.common.util.Logger;
import org.jboss.dna.graph.properties.NamespaceRegistry;
import org.jboss.dna.graph.properties.Property;
@@ -50,6 +50,13 @@
AccessControlContext getAccessControlContext();
/**
+ * Returns the thread-safe activity monitor associated with this execution context.
+ *
+ * @return the activity monitor; never <code>null</code>;
+ */
+ ActivityMonitor getActivityMonitor();
+
+ /**
* Return a logger associated with this context. This logger records only those
activities within the context and provide a
* way to capture the context-specific activities. All log messages are also sent to
the system logger, so classes that log
* via this mechanism should <i>not</i> also {@link
Logger#getLogger(Class) obtain a system logger}.
@@ -84,13 +91,6 @@
NamespaceRegistry getNamespaceRegistry();
/**
- * Returns the thread-safe progress monitor associated with this execution context.
- *
- * @return the progress monitor; never <code>null</code>;
- */
- ProgressMonitor getProgressMonitor();
-
- /**
* Get the factory for creating {@link Property} objects.
*
* @return the property factory; never <code>null</code>
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/ExecutionContexts.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/ExecutionContexts.java 2008-10-29
18:23:01 UTC (rev 598)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/ExecutionContexts.java 2008-10-29
20:09:42 UTC (rev 599)
@@ -24,7 +24,7 @@
import java.security.AccessControlContext;
import javax.security.auth.Subject;
import javax.security.auth.login.LoginContext;
-import org.jboss.dna.common.monitor.ProgressMonitor;
+import org.jboss.dna.common.monitor.ActivityMonitor;
import org.jboss.dna.common.util.CheckArg;
import org.jboss.dna.common.util.Logger;
import org.jboss.dna.graph.properties.NameFactory;
@@ -188,10 +188,10 @@
/**
* {@inheritDoc}
*
- * @see org.jboss.dna.graph.ExecutionContext#getProgressMonitor()
+ * @see org.jboss.dna.graph.ExecutionContext#getActivityMonitor()
*/
- public ProgressMonitor getProgressMonitor() {
- return delegate.getProgressMonitor();
+ public ActivityMonitor getActivityMonitor() {
+ return delegate.getActivityMonitor();
}
/**
Modified:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connectors/BasicExecutionContext.java
===================================================================
---
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connectors/BasicExecutionContext.java 2008-10-29
18:23:01 UTC (rev 598)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connectors/BasicExecutionContext.java 2008-10-29
20:09:42 UTC (rev 599)
@@ -25,10 +25,11 @@
import java.security.AccessController;
import javax.security.auth.Subject;
import javax.security.auth.login.LoginContext;
+import org.jboss.dna.common.CommonI18n;
import org.jboss.dna.common.component.ClassLoaderFactory;
import org.jboss.dna.common.component.StandardClassLoaderFactory;
-import org.jboss.dna.common.monitor.ProgressMonitor;
-import org.jboss.dna.common.monitor.SimpleProgressMonitor;
+import org.jboss.dna.common.monitor.ActivityMonitor;
+import org.jboss.dna.common.monitor.SimpleActivityMonitor;
import org.jboss.dna.common.util.Logger;
import org.jboss.dna.graph.ExecutionContext;
import org.jboss.dna.graph.properties.NamespaceRegistry;
@@ -51,7 +52,7 @@
private final PropertyFactory propertyFactory;
private final ValueFactories valueFactories;
private final NamespaceRegistry namespaceRegistry;
- private final ProgressMonitor progressMonitor;
+ private final ActivityMonitor activityMonitor;
public BasicExecutionContext() {
this(null, null, null, null, null, null);
@@ -68,24 +69,24 @@
public BasicExecutionContext( NamespaceRegistry namespaceRegistry,
ValueFactories valueFactories,
PropertyFactory propertyFactory,
- ProgressMonitor progressMonitor ) {
- this(null, null, namespaceRegistry, valueFactories, propertyFactory,
progressMonitor);
+ ActivityMonitor activityMonitor ) {
+ this(null, null, namespaceRegistry, valueFactories, propertyFactory,
activityMonitor);
}
public BasicExecutionContext( LoginContext loginContext,
NamespaceRegistry namespaceRegistry,
ValueFactories valueFactories,
PropertyFactory propertyFactory,
- ProgressMonitor progressMonitor ) {
- this(loginContext, null, namespaceRegistry, valueFactories, propertyFactory,
progressMonitor);
+ ActivityMonitor activityMonitor ) {
+ this(loginContext, null, namespaceRegistry, valueFactories, propertyFactory,
activityMonitor);
}
public BasicExecutionContext( AccessControlContext accessControlContext,
NamespaceRegistry namespaceRegistry,
ValueFactories valueFactories,
PropertyFactory propertyFactory,
- ProgressMonitor progressMonitor ) {
- this(null, accessControlContext, namespaceRegistry, valueFactories,
propertyFactory, progressMonitor);
+ ActivityMonitor activityMonitor ) {
+ this(null, accessControlContext, namespaceRegistry, valueFactories,
propertyFactory, activityMonitor);
}
/*
@@ -96,7 +97,7 @@
NamespaceRegistry namespaceRegistry,
ValueFactories valueFactories,
PropertyFactory propertyFactory,
- ProgressMonitor progressMonitor ) {
+ ActivityMonitor activityMonitor ) {
this.loginContext = loginContext;
this.accessControlContext = accessControlContext;
if (loginContext == null) {
@@ -107,7 +108,7 @@
this.namespaceRegistry = namespaceRegistry == null ? new BasicNamespaceRegistry()
: namespaceRegistry;
this.valueFactories = valueFactories == null ? new
StandardValueFactories(this.namespaceRegistry) : valueFactories;
this.propertyFactory = propertyFactory == null ? new
BasicPropertyFactory(this.valueFactories) : propertyFactory;
- this.progressMonitor = progressMonitor == null ? new SimpleProgressMonitor(null)
: progressMonitor;
+ this.activityMonitor = activityMonitor == null ? new
SimpleActivityMonitor(CommonI18n.nullActivityMonitorTaskName) : activityMonitor;
this.classLoaderFactory = new StandardClassLoaderFactory();
}
@@ -148,10 +149,10 @@
/**
* {@inheritDoc}
*
- * @see org.jboss.dna.graph.ExecutionContext#getProgressMonitor()
+ * @see org.jboss.dna.graph.ExecutionContext#getActivityMonitor()
*/
- public ProgressMonitor getProgressMonitor() {
- return progressMonitor;
+ public ActivityMonitor getActivityMonitor() {
+ return activityMonitor;
}
/**
Modified:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/sequencers/StreamSequencer.java
===================================================================
---
trunk/dna-graph/src/main/java/org/jboss/dna/graph/sequencers/StreamSequencer.java 2008-10-29
18:23:01 UTC (rev 598)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/sequencers/StreamSequencer.java 2008-10-29
20:09:42 UTC (rev 599)
@@ -22,7 +22,7 @@
package org.jboss.dna.graph.sequencers;
import java.io.InputStream;
-import org.jboss.dna.common.monitor.ProgressMonitor;
+import org.jboss.dna.common.monitor.ActivityMonitor;
/**
* The interface for a DNA sequencer that processes a property as a stream to extract
information from the content and store in
@@ -32,6 +32,7 @@
* </p>
*
* @author Randall Hauch
+ * @author John Verhaeg
*/
public interface StreamSequencer {
@@ -44,30 +45,30 @@
* along with the interface used to register the output. The framework takes care of
all the rest.
* </p>
* <p>
- * This operation should report progress to the supplied {@link ProgressMonitor}. At
the beginning of the operation, call
- * {@link ProgressMonitor#beginTask(double, org.jboss.dna.common.i18n.I18n,
Object...)} with a meaningful message describing
+ * This operation should report progress to the supplied {@link ActivityMonitor}. At
the beginning of the operation, call
+ * {@link ActivityMonitor#beginTask(double, org.jboss.dna.common.i18n.I18n,
Object...)} with a meaningful message describing
* the operation and a total for the amount of work that will be done by this
sequencer. Then perform the sequencing work,
- * periodically reporting work by specifying the {@link
ProgressMonitor#worked(double) amount of work} that has was just
- * completed or by {@link ProgressMonitor#createSubtask(double) creating a subtask}
and reporting work against that subtask
+ * periodically reporting work by specifying the {@link
ActivityMonitor#worked(double) amount of work} that has was just
+ * completed or by {@link ActivityMonitor#createSubtask(double) creating a subtask}
and reporting work against that subtask
* monitor.
* </p>
* <p>
- * The implementation should also periodically check whether the operation has been
- * {@link ProgressMonitor#isCancelled() cancelled}. If this method returns true, the
implementation should abort all work as
- * soon as possible and close any resources that were acquired or opened.
+ * The implementation should also periodically check whether the operation has been
{@link ActivityMonitor#isCancelled()
+ * cancelled}. If this method returns true, the implementation should abort all work
as soon as possible and close any
+ * resources that were acquired or opened.
* </p>
* <p>
- * Finally, the implementation should call {@link ProgressMonitor#done()} when the
operation has finished.
+ * Finally, the implementation should call {@link ActivityMonitor#done()} when the
operation has finished.
* </p>
*
* @param stream the stream with the data to be sequenced; never
<code>null</code>
* @param output the output from the sequencing operation; never
<code>null</code>
* @param context the context for the sequencing operation; never
<code>null</code>
- * @param progressMonitor the progress monitor that should be kept updated with the
sequencer's progress and that should be
- * frequently consulted as to whether this operation has been {@link
ProgressMonitor#isCancelled() cancelled}.
+ * @param activityMonitor the activity monitor that should be kept updated with the
sequencer's progress and that should be
+ * frequently consulted as to whether this operation has been {@link
ActivityMonitor#isCancelled() cancelled}.
*/
void sequence( InputStream stream,
SequencerOutput output,
SequencerContext context,
- ProgressMonitor progressMonitor );
+ ActivityMonitor activityMonitor );
}
Modified:
trunk/dna-graph/src/test/java/org/jboss/dna/graph/sequencers/MockSequencerContext.java
===================================================================
---
trunk/dna-graph/src/test/java/org/jboss/dna/graph/sequencers/MockSequencerContext.java 2008-10-29
18:23:01 UTC (rev 598)
+++
trunk/dna-graph/src/test/java/org/jboss/dna/graph/sequencers/MockSequencerContext.java 2008-10-29
20:09:42 UTC (rev 599)
@@ -26,7 +26,7 @@
import javax.security.auth.Subject;
import javax.security.auth.login.LoginContext;
import net.jcip.annotations.Immutable;
-import org.jboss.dna.common.monitor.ProgressMonitor;
+import org.jboss.dna.common.monitor.ActivityMonitor;
import org.jboss.dna.common.util.Logger;
import org.jboss.dna.graph.DnaLexicon;
import org.jboss.dna.graph.properties.Name;
@@ -39,7 +39,7 @@
import org.jboss.dna.graph.properties.basic.StandardValueFactories;
/**
- * @author jverhaeg
+ * @author John Verhaeg
*/
@Immutable
public class MockSequencerContext implements SequencerContext {
@@ -150,9 +150,9 @@
/**
* {@inheritDoc}
*
- * @see org.jboss.dna.graph.ExecutionContext#getProgressMonitor()
+ * @see org.jboss.dna.graph.ExecutionContext#getActivityMonitor()
*/
- public ProgressMonitor getProgressMonitor() {
+ public ActivityMonitor getActivityMonitor() {
return null;
}
Modified:
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/Sequencer.java
===================================================================
---
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/Sequencer.java 2008-10-29
18:23:01 UTC (rev 598)
+++
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/Sequencer.java 2008-10-29
20:09:42 UTC (rev 599)
@@ -27,7 +27,7 @@
import javax.jcr.Session;
import net.jcip.annotations.ThreadSafe;
import org.jboss.dna.common.component.Component;
-import org.jboss.dna.common.monitor.ProgressMonitor;
+import org.jboss.dna.common.monitor.ActivityMonitor;
import org.jboss.dna.repository.observation.NodeChange;
import org.jboss.dna.repository.observation.NodeChangeListener;
import org.jboss.dna.repository.observation.NodeChanges;
@@ -41,7 +41,9 @@
* <p>
* Implementations must provide a no-argument constructor.
* </p>
+ *
* @author Randall Hauch
+ * @author John Verhaeg
*/
@ThreadSafe
public interface Sequencer extends Component<SequencerConfig> {
@@ -50,13 +52,13 @@
* Execute the sequencing operation on the supplied node, which has recently been
created or changed. The implementation of
* this method is responsible for {@link JcrExecutionContext#getSessionFactory()
getting sessions}, modifying the appropriate
* nodes, {@link Session#save() saving} any changes made by this sequencer, and
{@link Session#logout() closing} all sessions
- * (and any other acquired resources), even in the case of {@link
ProgressMonitor#isCancelled() cancellation} or exceptions.
+ * (and any other acquired resources), even in the case of {@link
ActivityMonitor#isCancelled() cancellation} or exceptions.
* <p>
* The {@link SequencingService} determines the sequencers that should be executed by
monitoring the changes to one or more
- * workspaces (it is a {@link NodeChangeListener} registered with the {@link
ObservationService}). Changes in those
- * workspaces are aggregated for each transaction, and organized into {@link
NodeChanges changes for each node}. The
- * SequencingService then determines for each {@link NodeChange set of changes to a
node} the set of full paths to the
- * properties that have changed and whether those paths {@link
SequencerPathExpression#matcher(String) match} the sequencer's
+ * workspaces (it is a {@link NodeChangeListener} registered with the {@link
ObservationService}). Changes in those workspaces
+ * are aggregated for each transaction, and organized into {@link NodeChanges changes
for each node}. The SequencingService
+ * then determines for each {@link NodeChange set of changes to a node} the set of
full paths to the properties that have
+ * changed and whether those paths {@link SequencerPathExpression#matcher(String)
match} the sequencer's
* {@link SequencerConfig#getPathExpressions() path expressions}. Each path
expression produces the path to the output node,
* and these output paths are accumulated and (with the original node that changed,
the node change summary, and other
* information) supplied to the sequencer via this method.
@@ -67,34 +69,39 @@
* the behavior in such cases.
* </p>
* <p>
- * This operation should report progress to the supplied {@link ProgressMonitor}. At
the beginning of the operation, call
- * {@link ProgressMonitor#beginTask(double, org.jboss.dna.common.i18n.I18n,
Object...)} with a meaningful message describing
+ * This operation should report progress to the supplied {@link ActivityMonitor}. At
the beginning of the operation, call
+ * {@link ActivityMonitor#beginTask(double, org.jboss.dna.common.i18n.I18n,
Object...)} with a meaningful message describing
* the operation and a total for the amount of work that will be done by this
sequencer. Then perform the sequencing work,
- * periodically reporting work by specifying the {@link
ProgressMonitor#worked(double) amount of work} that has was just
- * completed or by {@link ProgressMonitor#createSubtask(double) creating a subtask}
and reporting work against that subtask
+ * periodically reporting work by specifying the {@link
ActivityMonitor#worked(double) amount of work} that has was just
+ * completed or by {@link ActivityMonitor#createSubtask(double) creating a subtask}
and reporting work against that subtask
* monitor.
* </p>
* <p>
- * The implementation should also periodically check whether the operation has been
- * {@link ProgressMonitor#isCancelled() cancelled}. If this method returns true, the
implementation should abort all work as
- * soon as possible and close any resources that were acquired or opened.
+ * The implementation should also periodically check whether the operation has been
{@link ActivityMonitor#isCancelled()
+ * cancelled}. If this method returns true, the implementation should abort all work
as soon as possible and close any
+ * resources that were acquired or opened.
* </p>
* <p>
- * Finally, the implementation should call {@link ProgressMonitor#done()} when the
operation has finished.
+ * Finally, the implementation should call {@link ActivityMonitor#done()} when the
operation has finished.
* </p>
+ *
* @param input the node that has recently been created or changed; never null
* @param sequencedPropertyName the name of the property that caused this sequencer
to be executed; never null and never empty
- * @param changes the immutable summary of changes that occurred on the
<code>input</code> node within the transaction;
- * never null
+ * @param changes the immutable summary of changes that occurred on the
<code>input</code> node within the transaction; never
+ * null
* @param outputPaths the paths to the nodes where the sequencing content should be
placed; never null and never empty, but
- * the set may contain paths for non-existant nodes or may reference the
<code>input</code> node
+ * the set may contain paths for non-existant nodes or may reference the
<code>input</code> node
* @param context the context in which this sequencer is executing; never null
- * @param progress the progress monitor that should be kept updated with the
sequencer's progress and that should be
- * frequently consulted as to whether this operation has been {@link
ProgressMonitor#isCancelled() cancelled}.
+ * @param activityMonitor the activity monitor that should be kept updated with the
sequencer's progress and that should be
+ * frequently consulted as to whether this operation has been {@link
ActivityMonitor#isCancelled() cancelled}.
* @throws RepositoryException if there is a problem while working with the
repository
* @throws SequencerException if there is an error in this sequencer
*/
- void execute( Node input, String sequencedPropertyName, NodeChange changes,
Set<RepositoryNodePath> outputPaths, JcrExecutionContext context, ProgressMonitor
progress )
- throws RepositoryException, SequencerException;
+ void execute( Node input,
+ String sequencedPropertyName,
+ NodeChange changes,
+ Set<RepositoryNodePath> outputPaths,
+ JcrExecutionContext context,
+ ActivityMonitor activityMonitor ) throws RepositoryException,
SequencerException;
}
Modified:
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencerNodeContext.java
===================================================================
---
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencerNodeContext.java 2008-10-29
18:23:01 UTC (rev 598)
+++
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencerNodeContext.java 2008-10-29
20:09:42 UTC (rev 599)
@@ -35,7 +35,7 @@
import javax.security.auth.Subject;
import javax.security.auth.login.LoginContext;
import net.jcip.annotations.Immutable;
-import org.jboss.dna.common.monitor.ProgressMonitor;
+import org.jboss.dna.common.monitor.ActivityMonitor;
import org.jboss.dna.common.util.CheckArg;
import org.jboss.dna.common.util.Logger;
import org.jboss.dna.graph.properties.Name;
@@ -264,10 +264,10 @@
/**
* {@inheritDoc}
*
- * @see org.jboss.dna.graph.ExecutionContext#getProgressMonitor()
+ * @see org.jboss.dna.graph.ExecutionContext#getActivityMonitor()
*/
- public ProgressMonitor getProgressMonitor() {
- return context.getProgressMonitor();
+ public ActivityMonitor getActivityMonitor() {
+ return context.getActivityMonitor();
}
/**
Modified:
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencingService.java
===================================================================
---
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencingService.java 2008-10-29
18:23:01 UTC (rev 598)
+++
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencingService.java 2008-10-29
20:09:42 UTC (rev 599)
@@ -46,9 +46,9 @@
import org.jboss.dna.common.component.ClassLoaderFactory;
import org.jboss.dna.common.component.ComponentLibrary;
import org.jboss.dna.common.component.StandardClassLoaderFactory;
-import org.jboss.dna.common.monitor.LoggingProgressMonitor;
-import org.jboss.dna.common.monitor.ProgressMonitor;
-import org.jboss.dna.common.monitor.SimpleProgressMonitor;
+import org.jboss.dna.common.monitor.ActivityMonitor;
+import org.jboss.dna.common.monitor.LoggingActivityMonitor;
+import org.jboss.dna.common.monitor.SimpleActivityMonitor;
import org.jboss.dna.common.util.CheckArg;
import org.jboss.dna.common.util.HashCode;
import org.jboss.dna.common.util.Logger;
@@ -514,12 +514,12 @@
}
} else {
// Run each of those sequencers ...
- ProgressMonitor progressMonitor = new
SimpleProgressMonitor(RepositoryI18n.sequencerTask.text(changedNode));
+ ActivityMonitor activityMonitor = new
SimpleActivityMonitor(RepositoryI18n.sequencerTask, changedNode);
if (logger.isTraceEnabled()) {
- progressMonitor = new LoggingProgressMonitor(progressMonitor,
logger, Logger.Level.TRACE);
+ activityMonitor = new LoggingActivityMonitor(activityMonitor,
logger, Logger.Level.TRACE);
}
try {
- progressMonitor.beginTask(sequencerCalls.size(),
RepositoryI18n.sequencerTask, changedNode);
+ activityMonitor.beginTask(sequencerCalls.size(),
RepositoryI18n.sequencerTask, changedNode);
for (Map.Entry<SequencerCall,
Set<RepositoryNodePath>> entry : sequencerCalls.entrySet()) {
final SequencerCall sequencerCall = entry.getKey();
final Set<RepositoryNodePath> outputPaths =
entry.getValue();
@@ -532,7 +532,7 @@
// Create a new execution context for each sequencer
final Context executionContext = new Context(context);
- final ProgressMonitor sequenceMonitor =
progressMonitor.createSubtask(1);
+ final ActivityMonitor sequenceMonitor =
activityMonitor.createSubtask(1);
try {
sequenceMonitor.beginTask(100,
RepositoryI18n.sequencerSubtask, sequencerName);
sequencer.execute(node,
@@ -563,7 +563,7 @@
}
this.statistics.recordNodeSequenced();
} finally {
- progressMonitor.done();
+ activityMonitor.done();
}
}
} finally {
@@ -642,10 +642,10 @@
/**
* {@inheritDoc}
*
- * @see org.jboss.dna.graph.ExecutionContext#getProgressMonitor()
+ * @see org.jboss.dna.graph.ExecutionContext#getActivityMonitor()
*/
- public ProgressMonitor getProgressMonitor() {
- return delegate.getProgressMonitor();
+ public ActivityMonitor getActivityMonitor() {
+ return delegate.getActivityMonitor();
}
/**
Modified:
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/StreamSequencerAdapter.java
===================================================================
---
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/StreamSequencerAdapter.java 2008-10-29
18:23:01 UTC (rev 598)
+++
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/StreamSequencerAdapter.java 2008-10-29
20:09:42 UTC (rev 599)
@@ -31,7 +31,7 @@
import javax.jcr.Property;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
-import org.jboss.dna.common.monitor.ProgressMonitor;
+import org.jboss.dna.common.monitor.ActivityMonitor;
import org.jboss.dna.common.util.Logger;
import org.jboss.dna.graph.properties.Binary;
import org.jboss.dna.graph.properties.DateTime;
@@ -49,6 +49,7 @@
* An adapter class that wraps a {@link StreamSequencer} instance to be a {@link
Sequencer}.
*
* @author Randall Hauch
+ * @author John Verhaeg
*/
public class StreamSequencerAdapter implements Sequencer {
@@ -81,14 +82,14 @@
NodeChange changes,
Set<RepositoryNodePath> outputPaths,
JcrExecutionContext execContext,
- ProgressMonitor progressMonitor ) throws RepositoryException,
SequencerException {
+ ActivityMonitor activityMonitor ) throws RepositoryException,
SequencerException {
// 'sequencedPropertyName' contains the name of the modified property on
'input' that resulted in the call to this
// sequencer.
// 'changes' contains all of the changes to this node that occurred in
the transaction.
// 'outputPaths' contains the paths of the node(s) where this sequencer
is to save it's data.
try {
- progressMonitor.beginTask(100, RepositoryI18n.sequencingPropertyOnNode,
sequencedPropertyName, input.getPath());
+ activityMonitor.beginTask(100, RepositoryI18n.sequencingPropertyOnNode,
sequencedPropertyName, input.getPath());
// Get the property that contains the data, given by 'propertyName'
...
Property sequencedProperty = null;
@@ -98,13 +99,13 @@
String msg =
RepositoryI18n.unableToFindPropertyForSequencing.text(sequencedPropertyName,
input.getPath());
throw new SequencerException(msg, e);
}
- progressMonitor.worked(10);
+ activityMonitor.worked(10);
// Get the binary property with the image content, and build the image
metadata from the image ...
SequencerOutputMap output = new
SequencerOutputMap(execContext.getValueFactories());
InputStream stream = null;
Throwable firstError = null;
- ProgressMonitor sequencingMonitor = progressMonitor.createSubtask(50);
+ ActivityMonitor sequencingMonitor = activityMonitor.createSubtask(50);
try {
stream = sequencedProperty.getStream();
SequencerNodeContext sequencerContext = new SequencerNodeContext(input,
sequencedProperty, execContext);
@@ -131,8 +132,8 @@
}
// Find each output node and save the image metadata there ...
- ProgressMonitor writingProgress = progressMonitor.createSubtask(40);
- writingProgress.beginTask(outputPaths.size(),
+ ActivityMonitor writingActivity = activityMonitor.createSubtask(40);
+ writingActivity.beginTask(outputPaths.size(),
RepositoryI18n.writingOutputSequencedFromPropertyOnNodes,
sequencedPropertyName,
input.getPath(),
@@ -155,14 +156,14 @@
session.save();
}
} finally {
- writingProgress.worked(1);
+ writingActivity.worked(1);
// Always close the session ...
if (session != null) session.logout();
}
}
- writingProgress.done();
+ writingActivity.done();
} finally {
- progressMonitor.done();
+ activityMonitor.done();
}
}
Modified:
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/MockSequencerA.java
===================================================================
---
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/MockSequencerA.java 2008-10-29
18:23:01 UTC (rev 598)
+++
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/MockSequencerA.java 2008-10-29
20:09:42 UTC (rev 599)
@@ -29,14 +29,16 @@
import javax.jcr.Node;
import net.jcip.annotations.ThreadSafe;
import org.jboss.dna.common.i18n.MockI18n;
-import org.jboss.dna.common.monitor.ProgressMonitor;
+import org.jboss.dna.common.monitor.ActivityMonitor;
import org.jboss.dna.repository.observation.NodeChange;
import org.jboss.dna.repository.util.JcrExecutionContext;
import org.jboss.dna.repository.util.RepositoryNodePath;
/**
* A sequencer that can be used for basic unit testing.
+ *
* @author Randall Hauch
+ * @author John Verhaeg
*/
@ThreadSafe
public class MockSequencerA implements Sequencer {
@@ -49,7 +51,8 @@
this.latch = new CountDownLatch(numExpected);
}
- public boolean awaitExecution( long timeout, TimeUnit unit ) throws
InterruptedException {
+ public boolean awaitExecution( long timeout,
+ TimeUnit unit ) throws InterruptedException {
return this.latch.await(timeout, unit);
}
@@ -63,15 +66,20 @@
/**
* {@inheritDoc}
*/
- public void execute( Node input, String sequencedPropertyName, NodeChange changes,
Set<RepositoryNodePath> outputPaths, JcrExecutionContext context, ProgressMonitor
progress ) {
+ public void execute( Node input,
+ String sequencedPropertyName,
+ NodeChange changes,
+ Set<RepositoryNodePath> outputPaths,
+ JcrExecutionContext context,
+ ActivityMonitor activityMonitor ) {
try {
- progress.beginTask(1, MockI18n.passthrough, "Incrementing
counter");
+ activityMonitor.beginTask(1, MockI18n.passthrough, "Incrementing
counter");
// increment the counter and record the progress ...
this.counter.incrementAndGet();
this.latch.countDown();
- progress.worked(1);
+ activityMonitor.worked(1);
} finally {
- progress.done();
+ activityMonitor.done();
}
}
Modified:
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/MockSequencerB.java
===================================================================
---
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/MockSequencerB.java 2008-10-29
18:23:01 UTC (rev 598)
+++
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/MockSequencerB.java 2008-10-29
20:09:42 UTC (rev 599)
@@ -29,14 +29,16 @@
import javax.jcr.Node;
import net.jcip.annotations.ThreadSafe;
import org.jboss.dna.common.i18n.MockI18n;
-import org.jboss.dna.common.monitor.ProgressMonitor;
+import org.jboss.dna.common.monitor.ActivityMonitor;
import org.jboss.dna.repository.observation.NodeChange;
import org.jboss.dna.repository.util.JcrExecutionContext;
import org.jboss.dna.repository.util.RepositoryNodePath;
/**
* A sequencer that can be used for basic unit testing.
+ *
* @author Randall Hauch
+ * @author John Verhaeg
*/
@ThreadSafe
public class MockSequencerB implements Sequencer {
@@ -49,7 +51,8 @@
this.latch = new CountDownLatch(numExpected);
}
- public boolean awaitExecution( long timeout, TimeUnit unit ) throws
InterruptedException {
+ public boolean awaitExecution( long timeout,
+ TimeUnit unit ) throws InterruptedException {
return this.latch.await(timeout, unit);
}
@@ -63,15 +66,20 @@
/**
* {@inheritDoc}
*/
- public void execute( Node input, String sequencedPropertyName, NodeChange changes,
Set<RepositoryNodePath> outputPaths, JcrExecutionContext context, ProgressMonitor
progress ) {
+ public void execute( Node input,
+ String sequencedPropertyName,
+ NodeChange changes,
+ Set<RepositoryNodePath> outputPaths,
+ JcrExecutionContext context,
+ ActivityMonitor activityMonitor ) {
try {
- progress.beginTask(1, MockI18n.passthrough, "Incrementing
counter");
+ activityMonitor.beginTask(1, MockI18n.passthrough, "Incrementing
counter");
// increment the counter and record the progress ...
this.counter.incrementAndGet();
this.latch.countDown();
- progress.worked(1);
+ activityMonitor.worked(1);
} finally {
- progress.done();
+ activityMonitor.done();
}
}
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-29
18:23:01 UTC (rev 598)
+++
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/StreamSequencerAdapterTest.java 2008-10-29
20:09:42 UTC (rev 599)
@@ -37,8 +37,8 @@
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.ProgressMonitor;
-import org.jboss.dna.common.monitor.RecordingProgressMonitor;
+import org.jboss.dna.common.monitor.ActivityMonitor;
+import org.jboss.dna.common.monitor.RecordingActivityMonitor;
import org.jboss.dna.graph.properties.NamespaceRegistry;
import org.jboss.dna.graph.properties.Path;
import org.jboss.dna.graph.sequencers.SequencerContext;
@@ -70,7 +70,7 @@
private SequencerOutputMap sequencerOutput;
private String sampleData = "The little brown fox didn't something
bad.";
private JcrExecutionContext context;
- private RecordingProgressMonitor progressMonitor;
+ private RecordingActivityMonitor activityMonitor;
private String repositoryWorkspaceName = "something";
@Before
@@ -86,7 +86,7 @@
NamespaceRegistry registry = new JcrNamespaceRegistry(sessionFactory,
"doesn't matter");
this.context = new BasicJcrExecutionContext(sessionFactory, registry, null,
null);
this.sequencerOutput = new SequencerOutputMap(this.context.getValueFactories());
- this.progressMonitor = new
RecordingProgressMonitor(StreamSequencerAdapterTest.class.getName());
+ this.activityMonitor = new
RecordingActivityMonitor(StreamSequencerAdapterTest.class.getName());
final SequencerOutputMap finalOutput = sequencerOutput;
this.streamSequencer = new StreamSequencer() {
@@ -97,7 +97,7 @@
public void sequence( InputStream stream,
SequencerOutput output,
SequencerContext context,
- ProgressMonitor progressMonitor ) {
+ ActivityMonitor activityMonitor ) {
for (SequencerOutputMap.Entry entry : finalOutput) {
Path nodePath = entry.getPath();
for (SequencerOutputMap.PropertyValue property :
entry.getPropertyValues()) {
@@ -135,11 +135,11 @@
public void sequence( InputStream stream,
SequencerOutput output,
SequencerContext context,
- ProgressMonitor progressMonitor ) {
+ ActivityMonitor activityMonitor ) {
try {
- sequencer.sequence(stream, output, context, progressMonitor);
+ sequencer.sequence(stream, output, context, activityMonitor);
} catch (AssertionError err) {
- progressMonitor.getProblems().addError(err, null);
+ activityMonitor.getProblems().addError(err, null);
}
}
};
@@ -154,8 +154,8 @@
Set<RepositoryNodePath> outputPaths = new
HashSet<RepositoryNodePath>();
outputPaths.add(new RepositoryNodePath(repositoryWorkspaceName,
outputNode.getPath()));
sequencerOutput.setProperty("alpha/beta", "isSomething",
true);
- adapter.execute(inputNode, "sequencedProperty", nodeChange,
outputPaths, context, progressMonitor);
- for (Problem problem : progressMonitor.getProblems()) {
+ adapter.execute(inputNode, "sequencedProperty", nodeChange,
outputPaths, context, activityMonitor);
+ for (Problem problem : activityMonitor.getProblems()) {
throw (AssertionError)problem.getThrowable();
}
}
@@ -219,7 +219,7 @@
sequencerOutput.setProperty("alpha/beta", "isSomething",
true);
// Call the sequencer ...
- sequencer.execute(nodeC, "sequencedProperty", nodeChange, outputPaths,
context, progressMonitor);
+ sequencer.execute(nodeC, "sequencedProperty", nodeChange, outputPaths,
context, activityMonitor);
}
@Test( expected = SequencerException.class )
@@ -252,7 +252,7 @@
sequencerOutput.setProperty("alpha/beta", "isSomething",
true);
// Call the sequencer, which should cause the exception ...
- sequencer.execute(nodeC, "sequencedProperty", nodeChange, outputPaths,
context, progressMonitor);
+ sequencer.execute(nodeC, "sequencedProperty", nodeChange, outputPaths,
context, activityMonitor);
}
@Test
@@ -285,7 +285,7 @@
sequencerOutput.setProperty("alpha/beta", "isSomething",
true);
// Call the sequencer ...
- sequencer.execute(nodeC, "sequencedProperty", nodeChange, outputPaths,
context, progressMonitor);
+ sequencer.execute(nodeC, "sequencedProperty", nodeChange, outputPaths,
context, activityMonitor);
// Check to see that the output nodes have been created ...
assertThat(session.getRootNode().hasNode("d/e"), is(true));
@@ -317,7 +317,7 @@
sequencerOutput.setProperty("alpha/beta", "isSomething",
true);
// Call the sequencer ...
- sequencer.execute(nodeC, "sequencedProperty", nodeChange, outputPaths,
context, progressMonitor);
+ sequencer.execute(nodeC, "sequencedProperty", nodeChange, outputPaths,
context, activityMonitor);
// Check to see that the "/d/e" node has been created ...
assertThat(session.getRootNode().hasNode("d/e"), is(true));
@@ -351,7 +351,7 @@
sequencerOutput.setProperty("alpha/beta", "isSomething",
true);
// Call the sequencer ...
- sequencer.execute(nodeC, "sequencedProperty", nodeChange, outputPaths,
context, progressMonitor);
+ sequencer.execute(nodeC, "sequencedProperty", nodeChange, outputPaths,
context, activityMonitor);
// Check to see that the output nodes have been created ...
assertThat(session.getRootNode().hasNode("d/e"), is(true));
@@ -381,7 +381,7 @@
public void sequence( InputStream stream,
SequencerOutput output,
SequencerContext context,
- ProgressMonitor progressMonitor ) {
+ ActivityMonitor activityMonitor ) {
assertThat(stream, notNullValue());
}
});
@@ -394,7 +394,7 @@
public void sequence( InputStream stream,
SequencerOutput output,
SequencerContext context,
- ProgressMonitor progressMonitor ) {
+ ActivityMonitor activityMonitor ) {
assertThat(output, notNullValue());
}
});
@@ -407,21 +407,21 @@
public void sequence( InputStream stream,
SequencerOutput output,
SequencerContext context,
- ProgressMonitor progressMonitor ) {
+ ActivityMonitor activityMonitor ) {
assertThat(context, notNullValue());
}
});
}
@Test
- public void shouldPassNonNullProgressMonitorToSequencer() throws Exception {
+ public void shouldPassNonNullActivityMonitorToSequencer() throws Exception {
testSequencer(new StreamSequencer() {
public void sequence( InputStream stream,
SequencerOutput output,
SequencerContext context,
- ProgressMonitor progressMonitor ) {
- assertThat(progressMonitor, notNullValue());
+ ActivityMonitor activityMonitor ) {
+ assertThat(activityMonitor, notNullValue());
}
});
}
Modified:
trunk/extensions/dna-sequencer-images/src/main/java/org/jboss/dna/sequencer/images/ImageMetadataSequencer.java
===================================================================
---
trunk/extensions/dna-sequencer-images/src/main/java/org/jboss/dna/sequencer/images/ImageMetadataSequencer.java 2008-10-29
18:23:01 UTC (rev 598)
+++
trunk/extensions/dna-sequencer-images/src/main/java/org/jboss/dna/sequencer/images/ImageMetadataSequencer.java 2008-10-29
20:09:42 UTC (rev 599)
@@ -22,7 +22,7 @@
package org.jboss.dna.sequencer.images;
import java.io.InputStream;
-import org.jboss.dna.common.monitor.ProgressMonitor;
+import org.jboss.dna.common.monitor.ActivityMonitor;
import org.jboss.dna.graph.properties.NameFactory;
import org.jboss.dna.graph.properties.Path;
import org.jboss.dna.graph.properties.PathFactory;
@@ -87,13 +87,13 @@
/**
* {@inheritDoc}
*
- * @see StreamSequencer#sequence(InputStream, SequencerOutput, SequencerContext,
ProgressMonitor)
+ * @see StreamSequencer#sequence(InputStream, SequencerOutput, SequencerContext,
ActivityMonitor)
*/
public void sequence( InputStream stream,
SequencerOutput output,
SequencerContext context,
- ProgressMonitor progressMonitor ) {
- progressMonitor.beginTask(10, ImageSequencerI18n.sequencerTaskName);
+ ActivityMonitor activityMonitor ) {
+ activityMonitor.beginTask(10, ImageSequencerI18n.sequencerTaskName);
ImageMetadata metadata = new ImageMetadata();
metadata.setInput(stream);
@@ -104,8 +104,8 @@
if (!metadata.check()) {
metadata = null;
}
- progressMonitor.worked(5);
- if (progressMonitor.isCancelled()) return;
+ activityMonitor.worked(5);
+ if (activityMonitor.isCancelled()) return;
// Generate the output graph if we found useful metadata ...
if (metadata != null) {
@@ -130,6 +130,6 @@
output.setProperty(metadataNode,
nameFactory.create(IMAGE_PHYSICAL_HEIGHT_INCHES), metadata.getPhysicalHeightInch());
}
- progressMonitor.done();
+ activityMonitor.done();
}
}
Modified:
trunk/extensions/dna-sequencer-images/src/test/java/org/jboss/dna/sequencer/images/ImageMetadataSequencerTest.java
===================================================================
---
trunk/extensions/dna-sequencer-images/src/test/java/org/jboss/dna/sequencer/images/ImageMetadataSequencerTest.java 2008-10-29
18:23:01 UTC (rev 598)
+++
trunk/extensions/dna-sequencer-images/src/test/java/org/jboss/dna/sequencer/images/ImageMetadataSequencerTest.java 2008-10-29
20:09:42 UTC (rev 599)
@@ -28,8 +28,9 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
-import org.jboss.dna.common.monitor.ProgressMonitor;
-import org.jboss.dna.common.monitor.SimpleProgressMonitor;
+import org.jboss.dna.common.i18n.MockI18n;
+import org.jboss.dna.common.monitor.ActivityMonitor;
+import org.jboss.dna.common.monitor.SimpleActivityMonitor;
import org.jboss.dna.graph.sequencers.MockSequencerContext;
import org.jboss.dna.graph.sequencers.MockSequencerOutput;
import org.jboss.dna.graph.sequencers.SequencerContext;
@@ -46,7 +47,7 @@
private ImageMetadataSequencer sequencer;
private InputStream content;
private MockSequencerOutput output;
- private ProgressMonitor progress;
+ private ActivityMonitor activityMonitor;
private URL cautionGif;
private URL cautionJpg;
private URL cautionPict;
@@ -59,7 +60,7 @@
context = new MockSequencerContext();
context.getNamespaceRegistry().register("image",
"http://jboss.org/dna/images/1.0");
output = new MockSequencerOutput(context);
- progress = new SimpleProgressMonitor("Test activity");
+ activityMonitor = new SimpleActivityMonitor(MockI18n.passthrough, "Test
Activity");
cautionGif =
this.getClass().getClassLoader().getResource("caution.gif");
cautionJpg =
this.getClass().getClassLoader().getResource("caution.jpg");
cautionPict =
this.getClass().getClassLoader().getResource("caution.pict");
@@ -83,7 +84,7 @@
assertThat(url, is(notNullValue()));
content = url.openStream();
assertThat(content, is(notNullValue()));
- sequencer.sequence(content, output, context, progress);
+ sequencer.sequence(content, output, context, activityMonitor);
assertThat(output.getPropertyValues("image:metadata",
"jcr:primaryType"), is(new Object[] {"image:metadata"}));
assertThat(output.getPropertyValues("image:metadata",
"jcr:mimeType"), is(new Object[] {"image/jpeg"}));
assertThat(output.getPropertyValues("image:metadata",
"image:formatName"), is(new Object[] {"JPEG"}));
@@ -106,7 +107,7 @@
assertThat(url, is(notNullValue()));
content = url.openStream();
assertThat(content, is(notNullValue()));
- sequencer.sequence(content, output, context, progress);
+ sequencer.sequence(content, output, context, activityMonitor);
assertThat(output.getPropertyValues("image:metadata",
"jcr:primaryType"), is(new Object[] {"image:metadata"}));
assertThat(output.getPropertyValues("image:metadata",
"jcr:mimeType"), is(new Object[] {"image/png"}));
assertThat(output.getPropertyValues("image:metadata",
"image:formatName"), is(new Object[] {"PNG"}));
@@ -127,7 +128,7 @@
assertThat(url, is(notNullValue()));
content = url.openStream();
assertThat(content, is(notNullValue()));
- sequencer.sequence(content, output, context, progress);
+ sequencer.sequence(content, output, context, activityMonitor);
assertThat(output.getPropertyValues("image:metadata",
"jcr:mimeType"), is(new Object[] {"image/gif"}));
assertThat(output.getPropertyValues("image:metadata",
"image:formatName"), is(new Object[] {"GIF"}));
assertThat(output.getPropertyValues("image:metadata",
"image:width"), is(new Object[] {48}));
@@ -147,7 +148,7 @@
assertThat(url, is(notNullValue()));
content = url.openStream();
assertThat(content, is(notNullValue()));
- sequencer.sequence(content, output, context, progress);
+ sequencer.sequence(content, output, context, activityMonitor);
assertThat(output.hasProperties(), is(false));
}
Modified:
trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/JavaMetadataSequencer.java
===================================================================
---
trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/JavaMetadataSequencer.java 2008-10-29
18:23:01 UTC (rev 598)
+++
trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/JavaMetadataSequencer.java 2008-10-29
20:09:42 UTC (rev 599)
@@ -25,7 +25,7 @@
import java.io.InputStream;
import java.util.List;
import org.apache.commons.lang.StringUtils;
-import org.jboss.dna.common.monitor.ProgressMonitor;
+import org.jboss.dna.common.monitor.ActivityMonitor;
import org.jboss.dna.graph.properties.NameFactory;
import org.jboss.dna.graph.properties.Path;
import org.jboss.dna.graph.properties.PathFactory;
@@ -176,21 +176,21 @@
*
* @see org.jboss.dna.graph.sequencers.StreamSequencer#sequence(java.io.InputStream,
* org.jboss.dna.graph.sequencers.SequencerOutput,
org.jboss.dna.graph.sequencers.SequencerContext,
- * org.jboss.dna.common.monitor.ProgressMonitor)
+ * org.jboss.dna.common.monitor.ActivityMonitor)
*/
public void sequence( InputStream stream,
SequencerOutput output,
SequencerContext context,
- ProgressMonitor progressMonitor ) {
- progressMonitor.beginTask(10, JavaMetadataI18n.sequencerTaskName);
+ ActivityMonitor activityMonitor ) {
+ activityMonitor.beginTask(10, JavaMetadataI18n.sequencerTaskName);
JavaMetadata javaMetadata = null;
NameFactory nameFactory = context.getValueFactories().getNameFactory();
PathFactory pathFactory = context.getValueFactories().getPathFactory();
try {
- javaMetadata = JavaMetadata.instance(stream, JavaMetadataUtil.length(stream),
null, progressMonitor.createSubtask(10));
- if (progressMonitor.isCancelled()) return;
+ javaMetadata = JavaMetadata.instance(stream, JavaMetadataUtil.length(stream),
null, activityMonitor.createSubtask(10));
+ if (activityMonitor.isCancelled()) return;
} catch (IOException e) {
e.printStackTrace();
return;
@@ -721,6 +721,6 @@
}
}
- progressMonitor.done();
+ activityMonitor.done();
}
}
Modified:
trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/metadata/JavaMetadata.java
===================================================================
---
trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/metadata/JavaMetadata.java 2008-10-29
18:23:01 UTC (rev 598)
+++
trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/metadata/JavaMetadata.java 2008-10-29
20:09:42 UTC (rev 599)
@@ -24,13 +24,14 @@
import java.io.InputStream;
import java.util.List;
import org.eclipse.jdt.core.dom.CompilationUnit;
-import org.jboss.dna.common.monitor.ProgressMonitor;
+import org.jboss.dna.common.monitor.ActivityMonitor;
import org.jboss.dna.sequencer.java.AbstractJavaMetadata;
import org.jboss.dna.sequencer.java.CompilationUnitParser;
import org.jboss.dna.sequencer.java.JavaMetadataUtil;
/**
* @author Serge Pagop
+ * @author John Verhaeg
*/
public class JavaMetadata extends AbstractJavaMetadata {
@@ -52,7 +53,7 @@
* @param inputStream - the <code>InputStream</code> in our case a
<code>FileInputStream</code> of the java file.
* @param length - the length of the java file.
* @param encoding - the encoding that can be used.
- * @param progressMonitor - The basic <code>ProgressMonitor</code> that
facilitates the updating and monitoring of progress
+ * @param activityMonitor - The basic <code>ActivityMonitor</code> that
facilitates the updating and monitoring of progress
* towards the completion of an activity.
* @return the new instace of <code>JavaMetadata</code>
* @see java.io.File#length()
@@ -60,7 +61,7 @@
public static JavaMetadata instance( InputStream inputStream,
long length,
String encoding,
- ProgressMonitor progressMonitor ) {
+ ActivityMonitor activityMonitor ) {
JavaMetadata javaMetadata = new JavaMetadata();
char[] source = null;
Modified:
trunk/extensions/dna-sequencer-java/src/test/java/org/jboss/dna/sequencer/java/JavaMetadataSequencerTest.java
===================================================================
---
trunk/extensions/dna-sequencer-java/src/test/java/org/jboss/dna/sequencer/java/JavaMetadataSequencerTest.java 2008-10-29
18:23:01 UTC (rev 598)
+++
trunk/extensions/dna-sequencer-java/src/test/java/org/jboss/dna/sequencer/java/JavaMetadataSequencerTest.java 2008-10-29
20:09:42 UTC (rev 599)
@@ -29,8 +29,9 @@
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
-import org.jboss.dna.common.monitor.ProgressMonitor;
-import org.jboss.dna.common.monitor.SimpleProgressMonitor;
+import org.jboss.dna.common.i18n.MockI18n;
+import org.jboss.dna.common.monitor.ActivityMonitor;
+import org.jboss.dna.common.monitor.SimpleActivityMonitor;
import org.jboss.dna.graph.sequencers.MockSequencerContext;
import org.jboss.dna.graph.sequencers.MockSequencerOutput;
import org.jboss.dna.graph.sequencers.SequencerContext;
@@ -46,7 +47,7 @@
private JavaMetadataSequencer sequencer;
private InputStream content;
private MockSequencerOutput output;
- private ProgressMonitor progress;
+ private ActivityMonitor activityMonitor;
private File source;
private SequencerContext context;
@@ -56,7 +57,7 @@
context.getNamespaceRegistry().register("java",
"http://jboss.org/dna/java/1.0");
sequencer = new JavaMetadataSequencer();
output = new MockSequencerOutput(context);
- this.progress = new SimpleProgressMonitor("Test java monitor
activity");
+ this.activityMonitor = new SimpleActivityMonitor(MockI18n.passthrough, "Test
java monitor activity");
source = new
File("src/test/workspace/projectX/src/org/acme/MySource.java");
}
@@ -79,7 +80,7 @@
public void shouldGenerateMetadataForJavaSourceFile() throws IOException {
content = getJavaSrc(source);
assertThat(content, is(notNullValue()));
- sequencer.sequence(content, output, context, progress);
+ sequencer.sequence(content, output, context, activityMonitor);
assertThat(output.getPropertyValues("java:compilationUnit",
"jcr:primaryType"), is(new Object[] {"java:compilationUnit"}));
// support sequencing package declaration( FQL name of the package). Not
supported is to get information for package
Modified:
trunk/extensions/dna-sequencer-mp3/src/main/java/org/jboss/dna/sequencer/mp3/Mp3MetadataSequencer.java
===================================================================
---
trunk/extensions/dna-sequencer-mp3/src/main/java/org/jboss/dna/sequencer/mp3/Mp3MetadataSequencer.java 2008-10-29
18:23:01 UTC (rev 598)
+++
trunk/extensions/dna-sequencer-mp3/src/main/java/org/jboss/dna/sequencer/mp3/Mp3MetadataSequencer.java 2008-10-29
20:09:42 UTC (rev 599)
@@ -22,7 +22,7 @@
package org.jboss.dna.sequencer.mp3;
import java.io.InputStream;
-import org.jboss.dna.common.monitor.ProgressMonitor;
+import org.jboss.dna.common.monitor.ActivityMonitor;
import org.jboss.dna.graph.sequencers.SequencerContext;
import org.jboss.dna.graph.sequencers.SequencerOutput;
import org.jboss.dna.graph.sequencers.StreamSequencer;
@@ -47,6 +47,7 @@
*
* @author Stefano Maestri
* @author Randall Hauch
+ * @author John Verhaeg
*/
public class Mp3MetadataSequencer implements StreamSequencer {
@@ -61,12 +62,12 @@
/**
* {@inheritDoc}
*
- * @see StreamSequencer#sequence(InputStream, SequencerOutput, SequencerContext,
ProgressMonitor)
+ * @see StreamSequencer#sequence(InputStream, SequencerOutput, SequencerContext,
ActivityMonitor)
*/
public void sequence( InputStream stream,
SequencerOutput output,
SequencerContext context,
- ProgressMonitor progressMonitor ) {
+ ActivityMonitor activityMonitor ) {
Mp3Metadata metadata = Mp3Metadata.instance(stream);
if (metadata != null) {
Modified:
trunk/extensions/dna-sequencer-msoffice/src/main/java/org/jboss/dna/sequencer/msoffice/MSOfficeMetadataSequencer.java
===================================================================
---
trunk/extensions/dna-sequencer-msoffice/src/main/java/org/jboss/dna/sequencer/msoffice/MSOfficeMetadataSequencer.java 2008-10-29
18:23:01 UTC (rev 598)
+++
trunk/extensions/dna-sequencer-msoffice/src/main/java/org/jboss/dna/sequencer/msoffice/MSOfficeMetadataSequencer.java 2008-10-29
20:09:42 UTC (rev 599)
@@ -24,7 +24,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
-import org.jboss.dna.common.monitor.ProgressMonitor;
+import org.jboss.dna.common.monitor.ActivityMonitor;
import org.jboss.dna.graph.sequencers.SequencerContext;
import org.jboss.dna.graph.sequencers.SequencerOutput;
import org.jboss.dna.graph.sequencers.StreamSequencer;
@@ -75,6 +75,7 @@
* </p>
*
* @author Michael Trezzi
+ * @author John Verhaeg
*/
public class MSOfficeMetadataSequencer implements StreamSequencer {
@@ -115,11 +116,11 @@
public void sequence( InputStream stream,
SequencerOutput output,
SequencerContext context,
- ProgressMonitor progressMonitor ) {
- progressMonitor.beginTask(10, MSOfficeMetadataI18n.sequencerTaskName);
+ ActivityMonitor activityMonitor ) {
+ activityMonitor.beginTask(10, MSOfficeMetadataI18n.sequencerTaskName);
MSOfficeMetadata metadata = MSOfficeMetadataReader.instance(stream);
- progressMonitor.worked(3);
+ activityMonitor.worked(3);
String mimeType = context.getMimeType();
@@ -146,7 +147,7 @@
} else {
return;
}
- progressMonitor.worked(1);
+ activityMonitor.worked(1);
// process PowerPoint specific metadata
if (mimeType.equals("application/vnd.ms-powerpoint")) { // replace true
with check if it's ppt file being sequenced
try {
@@ -164,7 +165,7 @@
context.getLogger(this.getClass()).debug(e, "Error while extracting
the PowerPoint metadata");
}
}
- progressMonitor.worked(2);
+ activityMonitor.worked(2);
if (mimeType.equals("application/vnd.ms-word")) {
// Sometime in the future this will sequence WORD Table of contents.
@@ -176,7 +177,7 @@
}
}
- progressMonitor.worked(2);
+ activityMonitor.worked(2);
if (mimeType.equals("application/vnd.ms-excel")) {
try {
@@ -192,7 +193,7 @@
context.getLogger(this.getClass()).debug(e, "Error while extracting
the Excel metadata");
}
}
- progressMonitor.worked(2);
- progressMonitor.done();
+ activityMonitor.worked(2);
+ activityMonitor.done();
}
}
Modified:
trunk/extensions/dna-sequencer-zip/src/main/java/org/jboss/dna/sequencer/zip/ZipSequencer.java
===================================================================
---
trunk/extensions/dna-sequencer-zip/src/main/java/org/jboss/dna/sequencer/zip/ZipSequencer.java 2008-10-29
18:23:01 UTC (rev 598)
+++
trunk/extensions/dna-sequencer-zip/src/main/java/org/jboss/dna/sequencer/zip/ZipSequencer.java 2008-10-29
20:09:42 UTC (rev 599)
@@ -26,13 +26,14 @@
import java.io.InputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
-import org.jboss.dna.common.monitor.ProgressMonitor;
+import org.jboss.dna.common.monitor.ActivityMonitor;
import org.jboss.dna.graph.sequencers.SequencerContext;
import org.jboss.dna.graph.sequencers.SequencerOutput;
import org.jboss.dna.graph.sequencers.StreamSequencer;
/**
* @author Michael Trezzi
+ * @author John Verhaeg
*/
public class ZipSequencer implements StreamSequencer {
@@ -41,12 +42,12 @@
*
* @see org.jboss.dna.graph.sequencers.StreamSequencer#sequence(java.io.InputStream,
* org.jboss.dna.graph.sequencers.SequencerOutput,
org.jboss.dna.graph.sequencers.SequencerContext,
- * org.jboss.dna.common.monitor.ProgressMonitor)
+ * org.jboss.dna.common.monitor.ActivityMonitor)
*/
public void sequence( InputStream stream,
SequencerOutput output,
SequencerContext context,
- ProgressMonitor progressMonitor ) {
+ ActivityMonitor activityMonitor ) {
try {
ZipInputStream in = new ZipInputStream(stream);
ZipEntry entry = in.getNextEntry();