Author: jverhaeg(a)redhat.com
Date: 2008-10-28 13:55:47 -0400 (Tue, 28 Oct 2008)
New Revision: 593
Modified:
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/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/RecordingProgressMonitor.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/util/GraphImporter.java
Log:
DNA-186: Added getParentActivity method to ProgressMonitor that returns the name of the
parent activity that spawned the activity for the monitor.
Modified:
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-28
17:53:41 UTC (rev 592)
+++
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/ProgressMonitor.java 2008-10-28
17:55:47 UTC (rev 593)
@@ -32,14 +32,15 @@
* 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)}).
+ * {@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)}.
+ * 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
@@ -48,14 +49,6 @@
public interface ProgressMonitor {
/**
- * 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
- */
- String getActivityName();
-
- /**
* Called by the <strong>Updater</strong> to indicate work has started on
the task, specifying the total amount of work that
* this task constitutes.
*
@@ -68,13 +61,6 @@
Object... params );
/**
- * 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 );
-
- /**
* 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()}).
*
@@ -90,32 +76,32 @@
void done();
/**
- * Return whether this activity has completed.
+ * 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 <code>true</code> if this activity has completed.
+ * @return the activity's name; never <code>null</code>
*/
- boolean isDone();
+ String getActivityName();
/**
- * 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>).
+ * Get the name of the activity that spawned this activity. This should never change
for a progress monitor.
*
- * @param value <code>true</code> if requesting the activity be
cancelled.
+ * @return the parent activity's name; never <code>null</code>
*/
- void setCancelled( boolean value );
+ String getParentActivityName();
/**
- * Return whether a request was made by an <strong>Observer</strong> to
{@link #setCancelled(boolean) cancel} this activity.
+ * Return the problems encountered during the {@link #getStatus(Locale) progress}
made towards completing the associated
+ * {@link #getActivityName() activity}.
*
- * @return <code>true</code> if this activity has been requested to be
cancelled.
+ * @return the list of problems
*/
- boolean isCancelled();
+ 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.
+ * 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
@@ -124,10 +110,32 @@
ProgressStatus getStatus( Locale locale );
/**
- * Return the problems encountered during the {@link #getStatus(Locale) progress}
made towards completing the associated
- * {@link #getActivityName() activity}.
+ * Return whether a request was made by an <strong>Observer</strong> to
{@link #setCancelled(boolean) cancel} this activity.
*
- * @return the list of problems
+ * @return <code>true</code> if this activity has been requested to be
cancelled.
*/
- Problems getProblems();
+ 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 );
}
Modified:
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-28
17:53:41 UTC (rev 592)
+++
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/ProgressMonitorWrapper.java 2008-10-28
17:55:47 UTC (rev 593)
@@ -40,10 +40,6 @@
this.delegate = delegate;
}
- public ProgressMonitor getWrappedMonitor() {
- return this.delegate;
- }
-
public void beginTask( double totalWork,
I18n name,
Object... params ) {
@@ -62,14 +58,17 @@
return this.delegate.getActivityName();
}
- public ProgressStatus getStatus( Locale locale ) {
- return this.delegate.getStatus(locale);
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.common.monitor.ProgressMonitor#getParentActivityName()
+ */
+ public String getParentActivityName() {
+ return this.delegate.getParentActivityName();
}
/**
- * <p>
* {@inheritDoc}
- * </p>
*
* @see org.jboss.dna.common.monitor.ProgressMonitor#getProblems()
*/
@@ -77,6 +76,14 @@
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();
}
Modified:
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-28
17:53:41 UTC (rev 592)
+++
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/SimpleProgressMonitor.java 2008-10-28
17:55:47 UTC (rev 593)
@@ -31,6 +31,8 @@
import org.jboss.dna.common.collection.Problems;
import org.jboss.dna.common.collection.ThreadSafeProblems;
import org.jboss.dna.common.i18n.I18n;
+import org.jboss.dna.common.util.CheckArg;
+import org.jboss.dna.common.util.StringUtil;
/**
* A basic progress monitor.
@@ -51,30 +53,32 @@
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 = activityName != null ? activityName.trim() : "";
+ this(activityName, null);
+ }
+
+ public SimpleProgressMonitor( String activityName,
+ ProgressMonitor parentProgressMonitor ) {
+ this.activityName = activityName == null ? StringUtil.EMPTY_STRING :
activityName.trim();
+ this.parentActivityName = parentProgressMonitor == null ? StringUtil.EMPTY_STRING
: 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 String getActivityName() {
- return this.activityName;
- }
-
- /**
- * {@inheritDoc}
- */
public void beginTask( double totalWork,
I18n name,
Object... params ) {
- assert totalWork > 0;
+ CheckArg.isGreaterThan(totalWork, 0.0, "totalWork");
try {
this.lock.writeLock().lock();
this.taskName = name;
@@ -88,15 +92,15 @@
/**
* {@inheritDoc}
+ *
+ * @see org.jboss.dna.common.monitor.ProgressMonitor#createSubtask(double)
*/
public ProgressMonitor createSubtask( double subtaskWork ) {
return new SubProgressMonitor(this, subtaskWork);
}
/**
- * <p>
* {@inheritDoc}
- * </p>
*
* @see org.jboss.dna.common.monitor.ProgressMonitor#done()
*/
@@ -117,60 +121,70 @@
/**
* {@inheritDoc}
+ *
+ * @see org.jboss.dna.common.monitor.ProgressMonitor#getActivityName()
*/
- public boolean isCancelled() {
- return this.cancelled.get();
+ public String getActivityName() {
+ return this.activityName;
}
/**
* {@inheritDoc}
*
- * @see org.jboss.dna.common.monitor.ProgressMonitor#isDone()
+ * @see org.jboss.dna.common.monitor.ProgressMonitor#getParentActivityName()
*/
- public boolean isDone() {
- lock.readLock().lock();
- try {
- return worked >= totalWork;
- } finally {
- lock.readLock().unlock();
- }
+ 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 void setCancelled( boolean value ) {
- this.cancelled.set(value);
+ public Problems getProblems() {
+ return problems;
}
/**
* {@inheritDoc}
+ *
+ * @see org.jboss.dna.common.monitor.ProgressMonitor#getStatus(java.util.Locale)
*/
- 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();
+ 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 ProgressStatus getStatus( Locale locale ) {
+ public boolean isCancelled() {
+ return this.cancelled.get();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.common.monitor.ProgressMonitor#isDone()
+ */
+ public boolean isDone() {
+ lock.readLock().lock();
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());
+ return worked >= totalWork;
} finally {
- this.lock.readLock().unlock();
+ lock.readLock().unlock();
}
}
@@ -188,14 +202,30 @@
/**
* {@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()
+ * @see org.jboss.dna.common.monitor.ProgressMonitor#setCancelled(boolean)
*/
- public Problems getProblems() {
- return problems;
+ 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();
+ }
+ }
}
Modified:
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-28
17:53:41 UTC (rev 592)
+++
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/SubProgressMonitor.java 2008-10-28
17:55:47 UTC (rev 593)
@@ -31,8 +31,8 @@
/**
* 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}.
+ * {@link ProgressMonitor <strong>Updater</strong>}, and accessed by {@link
ProgressMonitor Observers} only after the activity has
+ * been {@link #done() completed}.
*
* @author Randall Hauch
*/
@@ -63,21 +63,9 @@
/**
* {@inheritDoc}
+ *
+ * @see org.jboss.dna.common.monitor.ProgressMonitor#beginTask(double,
org.jboss.dna.common.i18n.I18n, java.lang.Object[])
*/
- public String getActivityName() {
- return this.parent.getActivityName();
- }
-
- /**
- * @return parent
- */
- public ProgressMonitor getParent() {
- return this.parent;
- }
-
- /**
- * {@inheritDoc}
- */
public void beginTask( double totalWork,
I18n name,
Object... params ) {
@@ -95,6 +83,8 @@
/**
* {@inheritDoc}
+ *
+ * @see org.jboss.dna.common.monitor.ProgressMonitor#createSubtask(double)
*/
public ProgressMonitor createSubtask( double subtaskWork ) {
return new SubProgressMonitor(this, subtaskWork);
@@ -102,6 +92,8 @@
/**
* {@inheritDoc}
+ *
+ * @see org.jboss.dna.common.monitor.ProgressMonitor#done()
*/
public void done() {
// Compute the total work for this task in terms of the parent ...
@@ -119,7 +111,58 @@
/**
* {@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();
}
@@ -135,6 +178,8 @@
/**
* {@inheritDoc}
+ *
+ * @see org.jboss.dna.common.monitor.ProgressMonitor#setCancelled(boolean)
*/
public void setCancelled( boolean value ) {
this.parent.setCancelled(value);
@@ -142,6 +187,8 @@
/**
* {@inheritDoc}
+ *
+ * @see org.jboss.dna.common.monitor.ProgressMonitor#worked(double)
*/
public void worked( double work ) {
if (this.isCancelled()) return;
@@ -158,26 +205,4 @@
this.parent.worked(workInParent);
}
}
-
- /**
- * {@inheritDoc}
- */
- 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#getProblems()
- */
- public Problems getProblems() {
- return parent.getProblems();
- }
}
Modified:
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-28
17:53:41 UTC (rev 592)
+++
trunk/dna-common/src/test/java/org/jboss/dna/common/monitor/RecordingProgressMonitor.java 2008-10-28
17:55:47 UTC (rev 593)
@@ -38,14 +38,21 @@
}
public RecordingProgressMonitor( String name ) {
- this(new SimpleProgressMonitor(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 ) {
+ public void beginTask( double totalWork,
+ I18n name,
+ Object... params ) {
++beginTaskCount;
super.beginTask(totalWork, name, params);
}
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/util/GraphImporter.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/util/GraphImporter.java 2008-10-28
17:53:41 UTC (rev 592)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/util/GraphImporter.java 2008-10-28
17:55:47 UTC (rev 593)
@@ -154,7 +154,7 @@
// Now run the sequencer ...
String activity = GraphI18n.errorImportingContent.text(location.getPath(),
contentUri);
- ProgressMonitor progressMonitor = new SimpleProgressMonitor(activity);
+ ProgressMonitor progressMonitor = new SimpleProgressMonitor(activity,
getContext().getProgressMonitor());
Graph.Batch batch = getGraph().batch();
ImporterOutput importedContent = new ImporterOutput(batch, location.getPath());
InputStream stream = null;