summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-07-30 05:41:32 (EDT)
committerEike Stepper2007-07-30 05:41:32 (EDT)
commitfc95a6dc48c81f403d9b3b34c9a298adbb1df8d1 (patch)
treea22e20ff8e0dc664122d466b05753d9f2b67d80f
parentd3190f669dd9c168e244504e73ea10800fa7b6c2 (diff)
downloadcdo-fc95a6dc48c81f403d9b3b34c9a298adbb1df8d1.zip
cdo-fc95a6dc48c81f403d9b3b34c9a298adbb1df8d1.tar.gz
cdo-fc95a6dc48c81f403d9b3b34c9a298adbb1df8d1.tar.bz2
*** empty log message ***
-rw-r--r--plugins/org.eclipse.net4j.tests/Net4j MonitorTest.launch20
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/MonitorTest.java79
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/monitor/MON.java36
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/monitor/Monitor.java8
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/monitor/NullMonitor.java77
5 files changed, 115 insertions, 105 deletions
diff --git a/plugins/org.eclipse.net4j.tests/Net4j MonitorTest.launch b/plugins/org.eclipse.net4j.tests/Net4j MonitorTest.launch
new file mode 100644
index 0000000..0b87a1c
--- /dev/null
+++ b/plugins/org.eclipse.net4j.tests/Net4j MonitorTest.launch
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<launchConfiguration type="org.eclipse.jdt.junit.launchconfig">
+<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
+<listEntry value="/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/MonitorTest.java"/>
+</listAttribute>
+<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
+<listEntry value="1"/>
+</listAttribute>
+<booleanAttribute key="org.eclipse.debug.core.appendEnvironmentVariables" value="true"/>
+<listAttribute key="org.eclipse.debug.ui.favoriteGroups">
+<listEntry value="org.eclipse.debug.ui.launchGroup.debug"/>
+<listEntry value="org.eclipse.debug.ui.launchGroup.run"/>
+</listAttribute>
+<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value=""/>
+<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/>
+<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/>
+<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit3"/>
+<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.eclipse.net4j.tests.MonitorTest"/>
+<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.eclipse.net4j.tests"/>
+</launchConfiguration>
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/MonitorTest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/MonitorTest.java
index 8d3ea99..d957e53 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/MonitorTest.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/MonitorTest.java
@@ -28,57 +28,73 @@ public class MonitorTest extends AbstractOMTest
public void testJoined() throws Exception
{
MonitorUtil.Legacy.startMonitoring();
- readClasses(CLASSES, FIELDS, true);
- MonitorUtil.Legacy.stopMonitoring();
+ try
+ {
+ readClasses(CLASSES, FIELDS, true, true);
+ }
+ finally
+ {
+ MonitorUtil.Legacy.stopMonitoring();
+ }
}
public void testJoinedNotStarted() throws Exception
{
- readClasses(CLASSES, FIELDS, true);
+ readClasses(CLASSES, FIELDS, true, true);
}
public void testJoinedStopNotStarted() throws Exception
{
+ readClasses(CLASSES, FIELDS, true, true);
+ MonitorUtil.Legacy.stopMonitoring();
+ }
+
+ public void testUnjoined() throws Exception
+ {
+ MonitorUtil.Legacy.startMonitoring();
try
{
- readClasses(CLASSES, FIELDS, true);
- MonitorUtil.Legacy.stopMonitoring();
+ readClasses(CLASSES, FIELDS, true, false);
fail("IllegalMonitorNestingException expected");
}
catch (IllegalMonitorNestingException ex)
{
}
+ finally
+ {
+ MonitorUtil.Legacy.stopMonitoring();
+ }
}
- public void testUnjoined() throws Exception
+ public void testUnjoinedNotStarted() throws Exception
{
try
{
- MonitorUtil.Legacy.startMonitoring();
- readClasses(CLASSES, FIELDS, false);
- fail("IllegalMonitorNestingException expected");
+ readClasses(CLASSES, FIELDS, true, false);
+ fail("MonitorAlreadyBegunException expected");
}
- catch (IllegalMonitorNestingException ex)
+ catch (MonitorAlreadyBegunException ex)
{
}
}
- public void testUnjoinedNotStarted() throws Exception
+ public void testNotForked() throws Exception
{
+ MonitorUtil.Legacy.startMonitoring();
try
{
- readClasses(CLASSES, FIELDS, false);
- fail("MonitorAlreadyBegunException expected");
+ readClasses(CLASSES, FIELDS, false, false);
}
- catch (MonitorAlreadyBegunException ex)
+ finally
{
+ MonitorUtil.Legacy.stopMonitoring();
}
}
/**
* Supports {@link MonitorUtil progress monitoring}.
*/
- private static void readClasses(String[] classes, String[][] fields, boolean join)
+ private static void readClasses(String[] classes, String[][] fields, boolean fork, boolean join)
{
int num = classes.length;
OMMonitor monitor = MonitorUtil.begin(2 * num, "Reading " + num + " classes");
@@ -88,10 +104,10 @@ public class MonitorTest extends AbstractOMTest
monitor.worked(1, "Created class buffer for " + classes[i]);
// Read class
- OMSubMonitor subMonitor = monitor.fork();
+ OMSubMonitor subMonitor = fork ? monitor.fork() : null;
try
{
- readFields(fields[i]);
+ readFields(fields[i], fork, join);
}
finally
{
@@ -105,17 +121,38 @@ public class MonitorTest extends AbstractOMTest
/**
* Supports {@link MonitorUtil progress monitoring}.
- *
- * @param i2
*/
- private static void readFields(String[] fields)
+ private static void readFields(String[] fields, boolean fork, boolean join)
{
int num = fields.length;
- OMMonitor monitor = MonitorUtil.begin(num, "Reading " + num + " fields");
+ OMMonitor monitor = MonitorUtil.begin(2 * num, "Reading " + num + " fields");
for (int i = 0; i < num; i++)
{
// Read field
monitor.worked(1, "Read field " + fields[i]);
+
+ OMSubMonitor subMonitor = fork ? monitor.fork() : null;
+ try
+ {
+ readSetting();
+ }
+ finally
+ {
+ if (join)
+ {
+ subMonitor.join();
+ }
+ }
}
}
+
+ /**
+ * Supports {@link MonitorUtil progress monitoring}.
+ */
+ private static void readSetting()
+ {
+ OMMonitor monitor = MonitorUtil.begin(1);
+ // Read setting
+ monitor.worked("Read setting");
+ }
}
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
index 2b97ebb..6354e6f 100644
--- 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
@@ -10,6 +10,7 @@
**************************************************************************/
package org.eclipse.net4j.internal.util.om.monitor;
+import org.eclipse.net4j.internal.util.bundle.OM;
import org.eclipse.net4j.util.om.monitor.IllegalMonitorNestingException;
import org.eclipse.net4j.util.om.monitor.MonitorAlreadyBegunException;
import org.eclipse.net4j.util.om.monitor.MonitorException;
@@ -25,8 +26,6 @@ public final class MON
private static final ThreadLocal<Monitor> CURRENT = new ThreadLocal();
- private static final NullMonitor NULL_MONITOR = new NullMonitor();
-
private MON()
{
}
@@ -44,19 +43,27 @@ public final class MON
public static void stopMonitoring()
{
- Monitor current = CURRENT.get();
- if (current == null)
+ try
{
- throw new IllegalMonitorNestingException("Monitoring has not been started");
+ Monitor current = CURRENT.get();
+ if (current == null)
+ {
+ OM.LOG.warn("Monitoring has not been started");
+ }
+ else
+ {
+ if (current.getParent() != null)
+ {
+ OM.LOG.warn("Illegal monitor nesting");
+ }
+
+ current.done();
+ }
}
-
- if (current.getParent() != null)
+ finally
{
- throw new IllegalMonitorNestingException("Illegal monitor nesting");
+ CURRENT.set(null);
}
-
- current.done();
- CURRENT.set(null);
}
public static OMMonitor begin(int totalWork, String task)
@@ -64,7 +71,7 @@ public final class MON
Monitor current = CURRENT.get();
if (current == null)
{
- return NULL_MONITOR;
+ return new NullMonitor();
}
if (current.hasBegun())
@@ -78,6 +85,11 @@ public final class MON
static void checkMonitor(Monitor monitor) throws MonitorException
{
+ if (monitor instanceof NullMonitor)
+ {
+ return;
+ }
+
Monitor current = CURRENT.get();
if (current != 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 8f6640f..b657688 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
@@ -252,9 +252,7 @@ public abstract class Monitor implements OMMonitor, OMSubMonitor
}
}
- protected abstract Monitor subMonitor(int workFromParent);
-
- private void checkWork(int work)
+ protected void checkWork(int work)
{
if (totalWork != UNKNOWN && this.work + work > totalWork)
{
@@ -262,7 +260,7 @@ public abstract class Monitor implements OMMonitor, OMSubMonitor
}
}
- private void dump(StringBuilder builder)
+ protected void dump(StringBuilder builder)
{
if (parent != null)
{
@@ -272,4 +270,6 @@ public abstract class Monitor implements OMMonitor, OMSubMonitor
builder.append(task);
}
+
+ protected abstract Monitor subMonitor(int workFromParent);
} \ No newline at end of file
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
index 09867f5..786877b 100644
--- 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
@@ -10,88 +10,29 @@
**************************************************************************/
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 class NullMonitor implements OMMonitor, OMSubMonitor
+public class NullMonitor extends Monitor
{
public NullMonitor()
{
+ super(null, 0);
}
- 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()
+ private NullMonitor(NullMonitor parent, int workFromParent)
{
- return 0;
+ super(parent, workFromParent);
}
- public boolean hasBegun()
+ @Override
+ protected Monitor subMonitor(int workFromParent)
{
- return true;
+ return new NullMonitor(this, workFromParent);
}
- public void message(String msg)
+ @Override
+ protected void checkWork(int work)
{
}
}