summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-07-29 09:01:35 (EDT)
committerEike Stepper2007-07-29 09:01:35 (EDT)
commit1608f35e31c8ae93bab04434ece7bdee35eb3246 (patch)
tree9e1152e0190d7dd4495b58cce9db683149c2db65
parentf8d2c0ada768b162275e9bb50bd23859556058fc (diff)
downloadcdo-1608f35e31c8ae93bab04434ece7bdee35eb3246.zip
cdo-1608f35e31c8ae93bab04434ece7bdee35eb3246.tar.gz
cdo-1608f35e31c8ae93bab04434ece7bdee35eb3246.tar.bz2
*** empty log message ***
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/monitor/Monitor.java72
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/monitor/RootMonitor.java (renamed from plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/progress/RootMonitor.java)24
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/monitor/SubMonitor.java (renamed from plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/progress/SubMonitor.java)18
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/progress/LegacyMonitor.java21
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/progress/Monitor.java63
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/LegacyUtil.java11
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/PROGRESS.java142
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/monitor/EclipseMonitor.java43
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/monitor/LegacyMonitor.java (renamed from plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/progress/EclipseMonitor.java)18
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/monitor/LegacyTest.java (renamed from plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/Test.java)32
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/monitor/MONITOR.java161
11 files changed, 314 insertions, 291 deletions
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
new file mode 100644
index 0000000..fa55f86
--- /dev/null
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/monitor/Monitor.java
@@ -0,0 +1,72 @@
+package org.eclipse.net4j.internal.util.om.monitor;
+
+import org.eclipse.net4j.util.om.monitor.MONITOR;
+
+/**
+ * @author Eike Stepper
+ */
+public abstract class Monitor
+{
+ private static final int UNINITIALIZED = 0;
+
+ private int totalWork = UNINITIALIZED;
+
+ private int work;
+
+ private String task;
+
+ public Monitor()
+ {
+ }
+
+ public final String getTask()
+ {
+ return task;
+ }
+
+ public final void setTask(String task, int level)
+ {
+ this.task = task;
+ message(task, level);
+ }
+
+ public int getTotalWork()
+ {
+ return totalWork;
+ }
+
+ public void begin(int totalWork, String task, int level)
+ {
+ if (this.totalWork != UNINITIALIZED)
+ {
+ throw new IllegalStateException("Monitoring has already begun");
+ }
+
+ this.totalWork = totalWork;
+ if (task != null)
+ {
+ setTask(task, level);
+ }
+ }
+
+ public void worked(int work, String msg, int level)
+ {
+ if (this.totalWork == UNINITIALIZED)
+ {
+ throw new IllegalStateException("Monitoring has not yet begun");
+ }
+
+ this.work += work;
+ if (totalWork != MONITOR.UNKNOWN && this.work > totalWork)
+ {
+ throw new IllegalStateException("Work has exceeded total work");
+ }
+
+ if (msg != null)
+ {
+ message(msg, level);
+ }
+ }
+
+ public abstract void message(String msg, int level);
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/progress/RootMonitor.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/monitor/RootMonitor.java
index 652b074..58e1517 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/progress/RootMonitor.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/monitor/RootMonitor.java
@@ -8,35 +8,25 @@
* Contributors:
* Eike Stepper - initial API and implementation
**************************************************************************/
-package org.eclipse.net4j.internal.util.om.progress;
+package org.eclipse.net4j.internal.util.om.monitor;
/**
* @author Eike Stepper
*/
public abstract class RootMonitor extends Monitor
{
- private transient String task;
-
public RootMonitor()
{
}
@Override
- public void onSuccess(String success)
- {
- System.out.println(success);
- }
-
- @Override
- public String getTask()
+ public void message(String msg, int level)
{
- return task;
- }
+ for (int i = 0; i < level; i++)
+ {
+ System.out.print(" ");
+ }
- @Override
- public void setTask(String task)
- {
- this.task = task;
- System.out.println(task);
+ System.out.println(msg);
}
}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/progress/SubMonitor.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/monitor/SubMonitor.java
index aefca3b..3781c78 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/progress/SubMonitor.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/monitor/SubMonitor.java
@@ -1,4 +1,4 @@
-package org.eclipse.net4j.internal.util.om.progress;
+package org.eclipse.net4j.internal.util.om.monitor;
/**
* @author Eike Stepper
@@ -26,20 +26,8 @@ public class SubMonitor extends Monitor
}
@Override
- public void onSuccess(String success)
+ public void message(String msg, int level)
{
- parent.onSuccess(success);
- }
-
- @Override
- public String getTask()
- {
- return parent.getTask();
- }
-
- @Override
- public void setTask(String task)
- {
- parent.setTask(task);
+ parent.message(msg, level + 1);
}
} \ No newline at end of file
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/progress/LegacyMonitor.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/progress/LegacyMonitor.java
deleted file mode 100644
index 3ec2a27..0000000
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/progress/LegacyMonitor.java
+++ /dev/null
@@ -1,21 +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.internal.util.om.progress;
-
-/**
- * @author Eike Stepper
- */
-public class LegacyMonitor extends RootMonitor
-{
- public LegacyMonitor()
- {
- }
-}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/progress/Monitor.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/progress/Monitor.java
deleted file mode 100644
index b0be5af..0000000
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/progress/Monitor.java
+++ /dev/null
@@ -1,63 +0,0 @@
-package org.eclipse.net4j.internal.util.om.progress;
-
-import org.eclipse.net4j.util.om.PROGRESS;
-
-/**
- * @author Eike Stepper
- */
-public abstract class Monitor
-{
- private static final int UNINITIALIZED = 0;
-
- protected int totalWork = UNINITIALIZED;
-
- protected int work;
-
- public Monitor()
- {
- }
-
- public int getTotalWork()
- {
- return totalWork;
- }
-
- public void begin(int totalWork, String task)
- {
- if (this.totalWork != UNINITIALIZED)
- {
- throw new IllegalStateException("Monitoring has already begun");
- }
-
- this.totalWork = totalWork;
- if (task != null)
- {
- setTask(task);
- }
- }
-
- public void worked(int work, String success)
- {
- if (this.totalWork == UNINITIALIZED)
- {
- throw new IllegalStateException("Monitoring has not yet begun");
- }
-
- this.work += work;
- if (totalWork != PROGRESS.UNKNOWN && this.work > totalWork)
- {
- throw new IllegalStateException("Work has exceeded total work");
- }
-
- if (success != null)
- {
- onSuccess(success);
- }
- }
-
- public abstract void onSuccess(String success);
-
- public abstract String getTask();
-
- public abstract void setTask(String task);
-} \ No newline at end of file
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/LegacyUtil.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/LegacyUtil.java
index abb28a7..62917c3 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/LegacyUtil.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/LegacyUtil.java
@@ -11,7 +11,6 @@
package org.eclipse.net4j.util.om;
import org.eclipse.net4j.internal.util.om.LegacyBundle;
-import org.eclipse.net4j.internal.util.om.progress.LegacyMonitor;
/**
* @author Eike Stepper
@@ -37,14 +36,4 @@ public final class LegacyUtil
((LegacyBundle)bundles[i]).stop();
}
}
-
- public static void startMonitoring()
- {
- PROGRESS.startMonitoring(new LegacyMonitor());
- }
-
- public static void stopMonitoring()
- {
- PROGRESS.stopMonitoring();
- }
}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/PROGRESS.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/PROGRESS.java
deleted file mode 100644
index 3941124..0000000
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/PROGRESS.java
+++ /dev/null
@@ -1,142 +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;
-
-import org.eclipse.net4j.internal.util.om.progress.Monitor;
-import org.eclipse.net4j.internal.util.om.progress.RootMonitor;
-import org.eclipse.net4j.internal.util.om.progress.SubMonitor;
-
-import java.text.MessageFormat;
-
-/**
- * @author Eike Stepper
- */
-public final class PROGRESS
-{
- public static final int UNKNOWN = -1;
-
- private static final ThreadLocal<Monitor> MONITOR = new ThreadLocal();
-
- private PROGRESS()
- {
- }
-
- public static void begin(int totalWork, String taskPattern, String... singularAndPlural)
- {
- Monitor monitor = getMonitor();
- String task = null;
- if (taskPattern != null)
- {
- task = format(totalWork, taskPattern, singularAndPlural);
- }
-
- monitor.begin(totalWork, task);
- }
-
- public static void worked(int work, String successPattern, String... singularAndPlural)
- {
- Monitor monitor = getMonitor();
- String success = null;
- if (successPattern != null)
- {
- success = format(work, successPattern, singularAndPlural);
- }
-
- monitor.worked(work, success);
- }
-
- public static void fork(int workFromParent, Runnable runnable, String successPattern, String... singularAndPlural)
- {
- Monitor monitor = getMonitor();
- SubMonitor subMonitor = new SubMonitor(monitor, workFromParent);
- MONITOR.set(subMonitor);
-
- try
- {
- runnable.run();
- if (successPattern != null)
- {
- String success = format(workFromParent, successPattern, singularAndPlural);
- subMonitor.onSuccess(success);
- }
- }
- finally
- {
- Monitor current = MONITOR.get();
- if (current != subMonitor)
- {
- throw new IllegalStateException("Illegal monitor nesting");
- }
-
- MONITOR.set(subMonitor.getParent());
- }
- }
-
- static void startMonitoring(RootMonitor rootMonitor)
- {
- Monitor monitor = MONITOR.get();
- if (monitor != null)
- {
- throw new IllegalStateException("Monitoring has already been started");
- }
-
- MONITOR.set(rootMonitor);
- }
-
- static void stopMonitoring()
- {
- Monitor monitor = MONITOR.get();
- if (monitor == null)
- {
- throw new IllegalStateException("Monitoring has not been started");
- }
-
- if (!(monitor instanceof RootMonitor))
- {
- throw new IllegalStateException("Illegal monitor nesting");
- }
-
- MONITOR.set(null);
- }
-
- private static String format(int totalWork, String pattern, String... singularAndPlural)
- {
- String task;
- if (singularAndPlural != null && singularAndPlural.length != 0)
- {
- if (singularAndPlural.length != 2)
- {
- throw new IllegalArgumentException("Give exactly singular and plural form after the pattern");
- }
-
- String singular = singularAndPlural[0];
- String plural = singularAndPlural[1];
- String arg = String.valueOf(totalWork) + " " + (totalWork == 1 ? singular : plural);
- task = MessageFormat.format(pattern, arg);
- }
- else
- {
- task = MessageFormat.format(pattern, totalWork);
- }
- return task;
- }
-
- private static Monitor getMonitor()
- {
- Monitor monitor = MONITOR.get();
- if (monitor == null)
- {
- throw new IllegalStateException("No monitor available");
- }
-
- return monitor;
- }
-}
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/util/om/monitor/EclipseMonitor.java
new file mode 100644
index 0000000..663e5df
--- /dev/null
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/monitor/EclipseMonitor.java
@@ -0,0 +1,43 @@
+/***************************************************************************
+ * 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.RootMonitor;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+
+/**
+ * @author Eike Stepper
+ */
+public final class EclipseMonitor extends RootMonitor
+{
+ private IProgressMonitor progressMonitor;
+
+ private EclipseMonitor(IProgressMonitor progressMonitor)
+ {
+ this.progressMonitor = progressMonitor;
+ }
+
+ public IProgressMonitor getProgressMonitor()
+ {
+ return progressMonitor;
+ }
+
+ public static void startMonitoring(IProgressMonitor progressMonitor)
+ {
+ MONITOR.startMonitoring(new EclipseMonitor(progressMonitor));
+ }
+
+ public static void stopMonitoring()
+ {
+ MONITOR.stopMonitoring();
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/progress/EclipseMonitor.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/monitor/LegacyMonitor.java
index 68b58aa..f9ecf7f 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/progress/EclipseMonitor.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/monitor/LegacyMonitor.java
@@ -8,24 +8,26 @@
* Contributors:
* Eike Stepper - initial API and implementation
**************************************************************************/
-package org.eclipse.net4j.internal.util.om.progress;
+package org.eclipse.net4j.util.om.monitor;
-import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.net4j.internal.util.om.monitor.RootMonitor;
/**
* @author Eike Stepper
*/
-public class EclipseMonitor extends RootMonitor
+public final class LegacyMonitor extends RootMonitor
{
- private IProgressMonitor eclipseMonitor;
+ private LegacyMonitor()
+ {
+ }
- public EclipseMonitor(IProgressMonitor eclipseMonitor)
+ public static void startMonitoring()
{
- this.eclipseMonitor = eclipseMonitor;
+ MONITOR.startMonitoring(new LegacyMonitor());
}
- public IProgressMonitor getEclipseMonitor()
+ public static void stopMonitoring()
{
- return eclipseMonitor;
+ MONITOR.stopMonitoring();
}
}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/Test.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/monitor/LegacyTest.java
index 175c616..6c6e05d 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/Test.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/monitor/LegacyTest.java
@@ -8,54 +8,58 @@
* Contributors:
* Eike Stepper - initial API and implementation
**************************************************************************/
-package org.eclipse.net4j.util.om;
+package org.eclipse.net4j.util.om.monitor;
/**
* @author Eike Stepper
*/
-public class Test
+public class LegacyTest
{
+ private static final String[] CLASSES = { "A", "B", "C", "D", "E" };
+
+ private static final String[] FIELDS = { "x", "y", "z" };
+
public static void main(String[] args)
{
- LegacyUtil.startMonitoring();
+ LegacyMonitor.startMonitoring();
readClasses();
- LegacyUtil.stopMonitoring();
+ LegacyMonitor.stopMonitoring();
}
/**
- * Supports {@link PROGRESS progress monitoring}.
+ * Supports {@link MONITOR progress monitoring}.
*/
private static void readClasses()
{
- int num = 3;
- PROGRESS.begin(2 * num, "Reading {0}", "class", "classes");
+ int num = CLASSES.length;
+ MONITOR.begin(2 * num, "Reading " + num + " classes");
for (int i = 0; i < num; i++)
{
// Create class buffer
- PROGRESS.worked(1, "Created class buffer {0}");
+ MONITOR.worked(1, "Created class buffer for " + CLASSES[i]);
// Read class
- PROGRESS.fork(1, new Runnable()
+ MONITOR.fork(1, new Runnable()
{
public void run()
{
readFields();
}
- }, "Read {0}", "class", "classes");
+ }, "Read class " + CLASSES[i]);
}
}
/**
- * Supports {@link PROGRESS progress monitoring}.
+ * Supports {@link MONITOR progress monitoring}.
*/
private static void readFields()
{
- int num = 5;
- PROGRESS.begin(num, "Reading {0}", "field", "fields");
+ int num = FIELDS.length;
+ MONITOR.begin(num, "Reading " + num + " fields");
for (int i = 0; i < num; i++)
{
// Read field
- PROGRESS.worked(1, "Read {0}", "field", "fields");
+ MONITOR.worked(1, "Read field " + FIELDS[i]);
}
}
}
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
new file mode 100644
index 0000000..18da473
--- /dev/null
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/monitor/MONITOR.java
@@ -0,0 +1,161 @@
+/***************************************************************************
+ * 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;
+import org.eclipse.net4j.internal.util.om.monitor.RootMonitor;
+import org.eclipse.net4j.internal.util.om.monitor.SubMonitor;
+
+/**
+ * @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;
+ }
+
+ SubMonitor subMonitor = new SubMonitor(monitor, 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(RootMonitor 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 instanceof RootMonitor))
+ {
+ throw new IllegalStateException("Illegal monitor nesting");
+ }
+
+ CURRENT.set(null);
+ }
+}