summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-07-30 03:22:49 (EDT)
committerEike Stepper2007-07-30 03:22:49 (EDT)
commit215029ca6d5124ec002bf6c1996b999005c5f2c6 (patch)
treedb91707aac75300feed708d0b6069728103e2909
parent16c5111012cf8f5068d39eb5f1a0f20f0eb9970c (diff)
downloadcdo-215029ca6d5124ec002bf6c1996b999005c5f2c6.zip
cdo-215029ca6d5124ec002bf6c1996b999005c5f2c6.tar.gz
cdo-215029ca6d5124ec002bf6c1996b999005c5f2c6.tar.bz2
*** empty log message ***
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/monitor/EclipseMonitor.java (renamed from plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/monitor/EclipseMonitor.java)66
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/monitor/InternalOMMonitor.java21
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/monitor/LegacyMonitor.java (renamed from plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/monitor/LegacyMonitor.java)22
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/monitor/LegacyTest.java6
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/monitor/MON.java96
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/monitor/Monitor.java185
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/monitor/MonitorTest.java44
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/monitor/NullMonitor.java96
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/monitor/IllegalMonitorNestingException.java38
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/monitor/MONITOR.java159
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/monitor/MonitorException.java38
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/monitor/MonitorNotBegunException.java38
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/monitor/MonitorUtil.java79
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/monitor/MonitoredJob.java4
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/monitor/OMMonitor.java49
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/monitor/OMSubMonitor.java21
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/monitor/TotalWorkExceededException.java38
17 files changed, 734 insertions, 266 deletions
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/monitor/EclipseMonitor.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/monitor/EclipseMonitor.java
index 757f475..8bc99f4 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/monitor/EclipseMonitor.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/monitor/EclipseMonitor.java
@@ -8,9 +8,7 @@
* Contributors:
* Eike Stepper - initial API and implementation
**************************************************************************/
-package org.eclipse.net4j.util.om.monitor;
-
-import org.eclipse.net4j.internal.util.om.monitor.Monitor;
+package org.eclipse.net4j.internal.util.om.monitor;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.SubProgressMonitor;
@@ -22,48 +20,39 @@ public final class EclipseMonitor extends Monitor
{
private IProgressMonitor progressMonitor;
- private EclipseMonitor(EclipseMonitor parent, int workFromParent)
- {
- super(parent, workFromParent);
- progressMonitor = new SubProgressMonitor(parent.getProgressMonitor(), workFromParent);
- }
-
- private EclipseMonitor(IProgressMonitor progressMonitor)
+ public EclipseMonitor(IProgressMonitor progressMonitor)
{
super(null, 0);
- this.progressMonitor = progressMonitor;
- }
+ if (progressMonitor == null)
+ {
+ throw new IllegalArgumentException("progressMonitor == null");
+ }
- public IProgressMonitor getProgressMonitor()
- {
- return progressMonitor;
+ this.progressMonitor = progressMonitor;
}
- @Override
- public void begin(int totalWork, String task, int level)
+ private EclipseMonitor(EclipseMonitor parent, int workFromParent)
{
- super.begin(totalWork, task, level);
- progressMonitor.beginTask(task == null ? "" : task, totalWork);
+ super(parent, workFromParent);
+ progressMonitor = new SubProgressMonitor(parent.getProgressMonitor(), workFromParent);
}
- @Override
- public void message(String msg, int level)
+ public IProgressMonitor getProgressMonitor()
{
- super.message(msg, level);
- progressMonitor.subTask(msg);
+ return progressMonitor;
}
@Override
- public void setTask(String task, int level)
+ public void setTask(String task)
{
- super.setTask(task, level);
+ super.setTask(task);
progressMonitor.setTaskName(task);
}
@Override
- public void worked(int work, String msg, int level)
+ public void worked(int work, String msg)
{
- super.worked(work, msg, level);
+ super.worked(work, msg);
progressMonitor.worked(work);
if (msg != null)
{
@@ -72,18 +61,29 @@ public final class EclipseMonitor extends Monitor
}
@Override
- public EclipseMonitor subMonitor(int workFromParent)
+ protected void begin(int totalWork, String task)
{
- return new EclipseMonitor(this, workFromParent);
+ super.begin(totalWork, task);
+ progressMonitor.beginTask(task == null ? "" : task, totalWork);
}
- public static void startMonitoring(IProgressMonitor progressMonitor)
+ @Override
+ protected void done()
{
- MONITOR.startMonitoring(new EclipseMonitor(progressMonitor));
+ super.done();
+ progressMonitor.done();
}
- public static void stopMonitoring()
+ @Override
+ protected void message(String msg, int level)
{
- MONITOR.stopMonitoring();
+ super.message(msg, level);
+ progressMonitor.subTask(msg);
+ }
+
+ @Override
+ protected EclipseMonitor subMonitor(int workFromParent)
+ {
+ return new EclipseMonitor(this, workFromParent);
}
}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/monitor/InternalOMMonitor.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/monitor/InternalOMMonitor.java
new file mode 100644
index 0000000..e1fa825
--- /dev/null
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/monitor/InternalOMMonitor.java
@@ -0,0 +1,21 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.net4j.internal.util.om.monitor;
+
+import org.eclipse.net4j.util.om.monitor.OMMonitor;
+import org.eclipse.net4j.util.om.monitor.OMSubMonitor;
+
+/**
+ * @author Eike Stepper
+ */
+public interface InternalOMMonitor extends OMMonitor, OMSubMonitor
+{
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/monitor/LegacyMonitor.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/monitor/LegacyMonitor.java
index 769b872..3beb032 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/monitor/LegacyMonitor.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/monitor/LegacyMonitor.java
@@ -8,23 +8,21 @@
* Contributors:
* Eike Stepper - initial API and implementation
**************************************************************************/
-package org.eclipse.net4j.util.om.monitor;
-
-import org.eclipse.net4j.internal.util.om.monitor.Monitor;
+package org.eclipse.net4j.internal.util.om.monitor;
/**
* @author Eike Stepper
*/
public final class LegacyMonitor extends Monitor
{
- private LegacyMonitor(LegacyMonitor parent, int workFromParent)
+ public LegacyMonitor()
{
- super(parent, workFromParent);
+ super(null, 0);
}
- private LegacyMonitor()
+ private LegacyMonitor(LegacyMonitor parent, int workFromParent)
{
- super(null, 0);
+ super(parent, workFromParent);
}
@Override
@@ -32,14 +30,4 @@ public final class LegacyMonitor extends Monitor
{
return new LegacyMonitor(this, workFromParent);
}
-
- public static void startMonitoring()
- {
- MONITOR.startMonitoring(new LegacyMonitor());
- }
-
- public static void stopMonitoring()
- {
- MONITOR.stopMonitoring();
- }
}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/monitor/LegacyTest.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/monitor/LegacyTest.java
index 40a7135..e3405d1 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/monitor/LegacyTest.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/monitor/LegacyTest.java
@@ -10,7 +10,7 @@
**************************************************************************/
package org.eclipse.net4j.internal.util.om.monitor;
-import org.eclipse.net4j.util.om.monitor.LegacyMonitor;
+import org.eclipse.net4j.util.om.monitor.MonitorUtil;
/**
* @author Eike Stepper
@@ -19,8 +19,8 @@ public class LegacyTest extends MonitorTest
{
public static void main(String[] args)
{
- LegacyMonitor.startMonitoring();
+ MonitorUtil.Legacy.startMonitoring();
readClasses();
- LegacyMonitor.stopMonitoring();
+ MonitorUtil.Legacy.stopMonitoring();
}
}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/monitor/MON.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/monitor/MON.java
new file mode 100644
index 0000000..1a0b97c
--- /dev/null
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/monitor/MON.java
@@ -0,0 +1,96 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.net4j.internal.util.om.monitor;
+
+import org.eclipse.net4j.util.om.monitor.IllegalMonitorNestingException;
+import org.eclipse.net4j.util.om.monitor.MonitorNotBegunException;
+import org.eclipse.net4j.util.om.monitor.OMMonitor;
+
+/**
+ * @author Eike Stepper
+ */
+public final class MON
+{
+ public static final int UNKNOWN = -1;
+
+ private static final ThreadLocal<Monitor> CURRENT = new ThreadLocal();
+
+ private static final NullMonitor NULL_MONITOR = new NullMonitor();
+
+ private MON()
+ {
+ }
+
+ public static void startMonitoring(Monitor rootMonitor)
+ {
+ Monitor current = CURRENT.get();
+ if (current != null)
+ {
+ throw new IllegalMonitorNestingException("Monitoring has already been started");
+ }
+
+ CURRENT.set(rootMonitor);
+ }
+
+ public static void stopMonitoring()
+ {
+ Monitor current = CURRENT.get();
+ if (current == null)
+ {
+ throw new IllegalMonitorNestingException("Monitoring has not been started");
+ }
+
+ if (current.getParent() != null)
+ {
+ throw new IllegalMonitorNestingException("Illegal monitor nesting");
+ }
+
+ current.done();
+ CURRENT.set(null);
+ }
+
+ public static OMMonitor begin(int totalWork, String task)
+ {
+ Monitor current = CURRENT.get();
+ if (current == null)
+ {
+ return NULL_MONITOR;
+ }
+
+ if (current.hasBegun())
+ {
+ throw new IllegalStateException("Monitor has already begun");
+ }
+
+ current.begin(totalWork, task);
+ return current;
+ }
+
+ static void checkMonitor(Monitor monitor)
+ {
+ Monitor current = CURRENT.get();
+ if (current != monitor)
+ {
+ throw new IllegalMonitorNestingException("Illegal monitor nesting\nCurrent:\n" + current.dump() + "Used:\n"
+ + monitor.dump());
+ }
+
+ if (!current.hasBegun())
+ {
+ throw new MonitorNotBegunException("Monitor has not begun");
+ }
+ }
+
+ static void setMonitor(Monitor monitor)
+ {
+ CURRENT.set(monitor);
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/monitor/Monitor.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/monitor/Monitor.java
index 0e8fe21..011b3a3 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/monitor/Monitor.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/monitor/Monitor.java
@@ -1,11 +1,12 @@
package org.eclipse.net4j.internal.util.om.monitor;
-import org.eclipse.net4j.util.om.monitor.MONITOR;
+import org.eclipse.net4j.util.om.monitor.OMSubMonitor;
+import org.eclipse.net4j.util.om.monitor.TotalWorkExceededException;
/**
* @author Eike Stepper
*/
-public abstract class Monitor
+public abstract class Monitor implements InternalOMMonitor
{
private static final int UNINITIALIZED = 0;
@@ -25,25 +26,15 @@ public abstract class Monitor
this.workFromParent = workFromParent;
}
- public Monitor getParent()
- {
- return parent;
- }
-
- public int getWorkFromParent()
- {
- return workFromParent;
- }
-
public String getTask()
{
return task;
}
- public void setTask(String task, int level)
+ public void setTask(String task)
{
this.task = task;
- message(task, level);
+ message(task);
}
public int getTotalWork()
@@ -51,40 +42,140 @@ public abstract class Monitor
return totalWork;
}
- public void begin(int totalWork, String task, int level)
+ public boolean hasBegun()
{
- if (this.totalWork != UNINITIALIZED)
- {
- throw new IllegalStateException("Monitoring has already begun");
- }
+ return totalWork != UNINITIALIZED;
+ }
- this.totalWork = totalWork;
- if (task != null)
+ public void message(String msg)
+ {
+ if (msg != null)
{
- setTask(task, level);
+ message(msg, 0);
}
}
- public void worked(int work, String msg, int level)
+ public void worked(int work, String msg)
{
- if (this.totalWork == UNINITIALIZED)
- {
- throw new IllegalStateException("Monitoring has not yet begun");
- }
+ MON.checkMonitor(this);
+ checkWork(work);
this.work += work;
- if (totalWork != MONITOR.UNKNOWN && this.work > totalWork)
+ message(msg);
+ }
+
+ public void worked(int work)
+ {
+ worked(work, null);
+ }
+
+ public void worked(String msg)
+ {
+ worked(1, msg);
+ }
+
+ public void worked()
+ {
+ worked(1, null);
+ }
+
+ public void fork(int workFromParent, Runnable runnable, String msg)
+ {
+ MON.checkMonitor(this);
+ checkWork(workFromParent);
+
+ Monitor subMonitor = subMonitor(workFromParent);
+ MON.setMonitor(subMonitor);
+
+ try
{
- throw new IllegalStateException("Work has exceeded total work");
+ runnable.run();
+ }
+ finally
+ {
+ MON.checkMonitor(subMonitor);
+ subMonitor.done();
+ MON.setMonitor(this);
}
- if (msg != null)
+ work += workFromParent;
+ message(msg);
+ }
+
+ public void fork(int workFromParent, Runnable runnable)
+ {
+ fork(workFromParent, runnable, null);
+ }
+
+ public void fork(Runnable runnable, String msg)
+ {
+ fork(UNKNOWN, runnable, msg);
+ }
+
+ public void fork(Runnable runnable)
+ {
+ fork(UNKNOWN, runnable, null);
+ }
+
+ public OMSubMonitor fork(int workFromParent)
+ {
+ MON.checkMonitor(this);
+ checkWork(workFromParent);
+
+ Monitor subMonitor = subMonitor(workFromParent);
+ MON.setMonitor(subMonitor);
+ return subMonitor;
+ }
+
+ public OMSubMonitor fork()
+ {
+ return fork(UNKNOWN);
+ }
+
+ public void join(String msg)
+ {
+ MON.checkMonitor(this);
+ done();
+ MON.setMonitor(parent);
+ parent.message(msg);
+ }
+
+ public void join()
+ {
+ join(null);
+ }
+
+ protected Monitor getParent()
+ {
+ return parent;
+ }
+
+ protected int getWorkFromParent()
+ {
+ return workFromParent;
+ }
+
+ protected String dump()
+ {
+ StringBuilder builder = new StringBuilder();
+ dump(builder, 0);
+ return builder.toString();
+ }
+
+ protected void begin(int totalWork, String task)
+ {
+ this.totalWork = totalWork;
+ if (task != null)
{
- message(msg, level);
+ setTask(task);
}
}
- public void message(String msg, int level)
+ protected void done()
+ {
+ }
+
+ protected void message(String msg, int level)
{
if (parent != null)
{
@@ -101,5 +192,33 @@ public abstract class Monitor
}
}
- public abstract Monitor subMonitor(int workFromParent);
+ protected abstract Monitor subMonitor(int workFromParent);
+
+ private void checkWork(int work)
+ {
+ if (totalWork != UNKNOWN && this.work + work > totalWork)
+ {
+ throw new TotalWorkExceededException(("Work of " + work + " exceeded total work of " + totalWork));
+ }
+ }
+
+ private int dump(StringBuilder builder, int level)
+ {
+ if (parent != null)
+ {
+ int line = parent.dump(builder, level + 1);
+ builder.append(line);
+ builder.append(": ");
+ builder.append(task);
+ builder.append("\n");
+ return line + 1;
+ }
+ else
+ {
+ builder.append("1: ");
+ builder.append(task);
+ builder.append("\n");
+ return 2;
+ }
+ }
} \ No newline at end of file
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/monitor/MonitorTest.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/monitor/MonitorTest.java
index b8b8b0a..c0bc521 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/monitor/MonitorTest.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/monitor/MonitorTest.java
@@ -10,51 +10,57 @@
**************************************************************************/
package org.eclipse.net4j.internal.util.om.monitor;
-import org.eclipse.net4j.util.om.monitor.MONITOR;
+import org.eclipse.net4j.util.om.monitor.MonitorUtil;
+import org.eclipse.net4j.util.om.monitor.OMMonitor;
+import org.eclipse.net4j.util.om.monitor.OMSubMonitor;
/**
* @author Eike Stepper
*/
public abstract class MonitorTest
{
- private static final String[] CLASSES = { "A", "B", "C", "D", "E" };
+ private static final String[] CLASSES = { "Pair", "Triple" };
- private static final String[] FIELDS = { "x", "y", "z" };
+ private static final String[][] FIELDS = { { "x", "y" }, { "x", "y", "z" } };
/**
- * Supports {@link MONITOR progress monitoring}.
+ * Supports {@link MonitorUtil progress monitoring}.
*/
public static void readClasses()
{
int num = CLASSES.length;
- MONITOR.begin(2 * num, "Reading " + num + " classes");
- for (int i = 0; i < num; i++)
+ OMMonitor monitor = MonitorUtil.begin(2 * num, "Reading " + num + " classes");
+ for (int c = 0; c < num; c++)
{
// Create class buffer
- MONITOR.worked(1, "Created class buffer for " + CLASSES[i]);
+ monitor.worked(1, "Created class buffer for " + CLASSES[c]);
// Read class
- MONITOR.fork(1, new Runnable()
+ OMSubMonitor subMonitor = monitor.fork();
+ try
{
- public void run()
- {
- readFields();
- }
- }, "Read class " + CLASSES[i]);
+ readFields(c);
+ }
+ finally
+ {
+ subMonitor.join("Read class " + CLASSES[c]);
+ }
}
}
/**
- * Supports {@link MONITOR progress monitoring}.
+ * Supports {@link MonitorUtil progress monitoring}.
+ *
+ * @param i2
*/
- public static void readFields()
+ public static void readFields(int c)
{
- int num = FIELDS.length;
- MONITOR.begin(num, "Reading " + num + " fields");
- for (int i = 0; i < num; i++)
+ int num = FIELDS[c].length;
+ OMMonitor monitor = MonitorUtil.begin(num, "Reading " + num + " fields");
+ for (int f = 0; f < num; f++)
{
// Read field
- MONITOR.worked(1, "Read field " + FIELDS[i]);
+ monitor.worked(1, "Read field " + FIELDS[c][f]);
}
}
}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/monitor/NullMonitor.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/monitor/NullMonitor.java
new file mode 100644
index 0000000..783a668
--- /dev/null
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/monitor/NullMonitor.java
@@ -0,0 +1,96 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.net4j.internal.util.om.monitor;
+
+import org.eclipse.net4j.util.om.monitor.OMSubMonitor;
+
+/**
+ * @author Eike Stepper
+ */
+public class NullMonitor implements InternalOMMonitor
+{
+ public NullMonitor()
+ {
+ }
+
+ public void fork(Runnable runnable)
+ {
+ }
+
+ public void fork(int workFromParent, Runnable runnable)
+ {
+ }
+
+ public void fork(Runnable runnable, String msg)
+ {
+ }
+
+ public void fork(int workFromParent, Runnable runnable, String msg)
+ {
+ }
+
+ public OMSubMonitor fork()
+ {
+ return this;
+ }
+
+ public OMSubMonitor fork(int workFromParent)
+ {
+ return this;
+ }
+
+ public String getTask()
+ {
+ return null;
+ }
+
+ public void setTask(String task)
+ {
+ }
+
+ public void worked()
+ {
+ }
+
+ public void worked(int work)
+ {
+ }
+
+ public void worked(String msg)
+ {
+ }
+
+ public void worked(int work, String msg)
+ {
+ }
+
+ public void join()
+ {
+ }
+
+ public void join(String msg)
+ {
+ }
+
+ public int getTotalWork()
+ {
+ return 0;
+ }
+
+ public boolean hasBegun()
+ {
+ return true;
+ }
+
+ public void message(String msg)
+ {
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/monitor/IllegalMonitorNestingException.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/monitor/IllegalMonitorNestingException.java
new file mode 100644
index 0000000..b2fd37c
--- /dev/null
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/monitor/IllegalMonitorNestingException.java
@@ -0,0 +1,38 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.net4j.util.om.monitor;
+
+/**
+ * @author Eike Stepper
+ */
+public class IllegalMonitorNestingException extends MonitorException
+{
+ private static final long serialVersionUID = 1L;
+
+ public IllegalMonitorNestingException()
+ {
+ }
+
+ public IllegalMonitorNestingException(String s)
+ {
+ super(s);
+ }
+
+ public IllegalMonitorNestingException(Throwable cause)
+ {
+ super(cause);
+ }
+
+ public IllegalMonitorNestingException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/monitor/MONITOR.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/monitor/MONITOR.java
deleted file mode 100644
index ae9fdb7..0000000
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/monitor/MONITOR.java
+++ /dev/null
@@ -1,159 +0,0 @@
-/***************************************************************************
- * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- **************************************************************************/
-package org.eclipse.net4j.util.om.monitor;
-
-import org.eclipse.net4j.internal.util.om.monitor.Monitor;
-
-/**
- * @author Eike Stepper
- */
-public final class MONITOR
-{
- public static final int UNKNOWN = -1;
-
- private static final ThreadLocal<Monitor> CURRENT = new ThreadLocal();
-
- private MONITOR()
- {
- }
-
- public static void begin()
- {
- begin(UNKNOWN, null);
- }
-
- public static void begin(int totalWork)
- {
- begin(totalWork, null);
- }
-
- public static void begin(String task)
- {
- begin(UNKNOWN, task);
- }
-
- public static void begin(int totalWork, String task)
- {
- Monitor monitor = CURRENT.get();
- if (monitor != null)
- {
- monitor.begin(totalWork, task, 0);
- }
- }
-
- public static void worked()
- {
- worked(1, null);
- }
-
- public static void worked(int work)
- {
- worked(work, null);
- }
-
- public static void worked(String msg)
- {
- worked(1, msg);
- }
-
- public static void worked(int work, String msg)
- {
- Monitor monitor = CURRENT.get();
- if (monitor != null)
- {
- monitor.worked(work, msg, 0);
- }
- }
-
- public static void fork(Runnable runnable)
- {
- fork(1, runnable, null);
- }
-
- public static void fork(int workFromParent, Runnable runnable)
- {
- fork(workFromParent, runnable, null);
- }
-
- public static void fork(Runnable runnable, String msg)
- {
- fork(1, runnable, msg);
- }
-
- public static void fork(int workFromParent, Runnable runnable, String msg)
- {
- Monitor monitor = CURRENT.get();
- if (monitor == null)
- {
- runnable.run();
- return;
- }
-
- Monitor subMonitor = monitor.subMonitor(workFromParent);
- CURRENT.set(subMonitor);
-
- try
- {
- runnable.run();
- }
- finally
- {
- Monitor current = CURRENT.get();
- if (current != subMonitor)
- {
- throw new IllegalStateException("Illegal monitor nesting");
- }
-
- CURRENT.set(subMonitor.getParent());
- }
-
- if (msg != null)
- {
- subMonitor.message(msg, 0);
- }
- }
-
- public static void message(String msg)
- {
- Monitor monitor = CURRENT.get();
- if (monitor != null)
- {
- monitor.message(msg, 0);
- }
- }
-
- static void startMonitoring(Monitor rootMonitor)
- {
- Monitor monitor = CURRENT.get();
- if (monitor != null)
- {
- throw new IllegalStateException("Monitoring has already been started");
- }
-
- CURRENT.set(rootMonitor);
- }
-
- static void stopMonitoring()
- {
- Monitor monitor = CURRENT.get();
- if (monitor == null)
- {
- throw new IllegalStateException("Monitoring has not been started");
- }
-
- if (monitor.getParent() != null)
- {
- throw new IllegalStateException("Illegal monitor nesting");
- }
-
- CURRENT.set(null);
- }
-}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/monitor/MonitorException.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/monitor/MonitorException.java
new file mode 100644
index 0000000..74cd608
--- /dev/null
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/monitor/MonitorException.java
@@ -0,0 +1,38 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.net4j.util.om.monitor;
+
+/**
+ * @author Eike Stepper
+ */
+public class MonitorException extends IllegalStateException
+{
+ private static final long serialVersionUID = 1L;
+
+ public MonitorException()
+ {
+ }
+
+ public MonitorException(String s)
+ {
+ super(s);
+ }
+
+ public MonitorException(Throwable cause)
+ {
+ super(cause);
+ }
+
+ public MonitorException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/monitor/MonitorNotBegunException.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/monitor/MonitorNotBegunException.java
new file mode 100644
index 0000000..d579b45
--- /dev/null
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/monitor/MonitorNotBegunException.java
@@ -0,0 +1,38 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.net4j.util.om.monitor;
+
+/**
+ * @author Eike Stepper
+ */
+public class MonitorNotBegunException extends MonitorException
+{
+ private static final long serialVersionUID = 1L;
+
+ public MonitorNotBegunException()
+ {
+ }
+
+ public MonitorNotBegunException(String s)
+ {
+ super(s);
+ }
+
+ public MonitorNotBegunException(Throwable cause)
+ {
+ super(cause);
+ }
+
+ public MonitorNotBegunException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/monitor/MonitorUtil.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/monitor/MonitorUtil.java
new file mode 100644
index 0000000..ca5946f
--- /dev/null
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/monitor/MonitorUtil.java
@@ -0,0 +1,79 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.net4j.util.om.monitor;
+
+import org.eclipse.net4j.internal.util.om.monitor.EclipseMonitor;
+import org.eclipse.net4j.internal.util.om.monitor.LegacyMonitor;
+import org.eclipse.net4j.internal.util.om.monitor.MON;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+
+/**
+ * @author Eike Stepper
+ */
+public final class MonitorUtil
+{
+ private MonitorUtil()
+ {
+ }
+
+ public static OMMonitor begin()
+ {
+ return MON.begin(OMMonitor.UNKNOWN, null);
+ }
+
+ public static OMMonitor begin(int totalWork)
+ {
+ return MON.begin(totalWork, null);
+ }
+
+ public static OMMonitor begin(String task)
+ {
+ return MON.begin(OMMonitor.UNKNOWN, task);
+ }
+
+ public static OMMonitor begin(int totalWork, String task)
+ {
+ return MON.begin(totalWork, task);
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static final class Eclipse
+ {
+ public static void startMonitoring(IProgressMonitor progressMonitor)
+ {
+ MON.startMonitoring(new EclipseMonitor(progressMonitor));
+ }
+
+ public static void stopMonitoring()
+ {
+ MON.stopMonitoring();
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static final class Legacy
+ {
+ public static void startMonitoring()
+ {
+ MON.startMonitoring(new LegacyMonitor());
+ }
+
+ public static void stopMonitoring()
+ {
+ MON.stopMonitoring();
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/monitor/MonitoredJob.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/monitor/MonitoredJob.java
index f6d42a5..7e7c0a1 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/monitor/MonitoredJob.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/monitor/MonitoredJob.java
@@ -31,7 +31,7 @@ public abstract class MonitoredJob extends Job
@Override
protected final IStatus run(IProgressMonitor monitor)
{
- EclipseMonitor.startMonitoring(monitor);
+ MonitorUtil.Eclipse.startMonitoring(monitor);
try
{
@@ -44,7 +44,7 @@ public abstract class MonitoredJob extends Job
}
finally
{
- EclipseMonitor.stopMonitoring();
+ MonitorUtil.Eclipse.stopMonitoring();
}
}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/monitor/OMMonitor.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/monitor/OMMonitor.java
new file mode 100644
index 0000000..fe628b8
--- /dev/null
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/monitor/OMMonitor.java
@@ -0,0 +1,49 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.net4j.util.om.monitor;
+
+/**
+ * @author Eike Stepper
+ */
+public interface OMMonitor
+{
+ public static final int UNKNOWN = -1;
+
+ public String getTask();
+
+ public void setTask(String task);
+
+ public int getTotalWork();
+
+ public boolean hasBegun();
+
+ public void message(String msg);
+
+ public void worked(int work, String msg);
+
+ public void worked(int work);
+
+ public void worked(String msg);
+
+ public void worked();
+
+ public void fork(int workFromParent, Runnable runnable, String msg);
+
+ public void fork(int workFromParent, Runnable runnable);
+
+ public void fork(Runnable runnable, String msg);
+
+ public void fork(Runnable runnable);
+
+ public OMSubMonitor fork(int workFromParent);
+
+ public OMSubMonitor fork();
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/monitor/OMSubMonitor.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/monitor/OMSubMonitor.java
new file mode 100644
index 0000000..6c496b9
--- /dev/null
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/monitor/OMSubMonitor.java
@@ -0,0 +1,21 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.net4j.util.om.monitor;
+
+/**
+ * @author Eike Stepper
+ */
+public interface OMSubMonitor
+{
+ public void join(String msg);
+
+ public void join();
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/monitor/TotalWorkExceededException.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/monitor/TotalWorkExceededException.java
new file mode 100644
index 0000000..f515f45
--- /dev/null
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/monitor/TotalWorkExceededException.java
@@ -0,0 +1,38 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.net4j.util.om.monitor;
+
+/**
+ * @author Eike Stepper
+ */
+public class TotalWorkExceededException extends MonitorException
+{
+ private static final long serialVersionUID = 1L;
+
+ public TotalWorkExceededException()
+ {
+ }
+
+ public TotalWorkExceededException(String s)
+ {
+ super(s);
+ }
+
+ public TotalWorkExceededException(Throwable cause)
+ {
+ super(cause);
+ }
+
+ public TotalWorkExceededException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+}