diff options
author | Eike Stepper | 2008-12-15 13:26:53 +0000 |
---|---|---|
committer | Eike Stepper | 2008-12-15 13:26:53 +0000 |
commit | 8bda5817bf1f5c35889cd11fda3bae0dd5437545 (patch) | |
tree | 031627be7ab47b4883e438bea596b68089c8fa83 /plugins/org.eclipse.net4j | |
parent | 90c7723450e4c41811e4a4c1d16d01825f9c9d05 (diff) | |
download | cdo-8bda5817bf1f5c35889cd11fda3bae0dd5437545.tar.gz cdo-8bda5817bf1f5c35889cd11fda3bae0dd5437545.tar.xz cdo-8bda5817bf1f5c35889cd11fda3bae0dd5437545.zip |
[258067] Provide RequestWithMonitoring example
https://bugs.eclipse.org/bugs/show_bug.cgi?id=258067
Diffstat (limited to 'plugins/org.eclipse.net4j')
3 files changed, 37 insertions, 11 deletions
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/IndicationWithMonitoring.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/IndicationWithMonitoring.java index cc1b3fe368..ed83e5f5c8 100644 --- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/IndicationWithMonitoring.java +++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/IndicationWithMonitoring.java @@ -31,7 +31,7 @@ import java.util.concurrent.Future; */ public abstract class IndicationWithMonitoring extends IndicationWithResponse { - private Monitor monitor; + private LastAccessMonitor monitor; private Object monitorLock = new Object(); @@ -102,9 +102,10 @@ public abstract class IndicationWithMonitoring extends IndicationWithResponse { while (monitor != null) { - if (System.currentTimeMillis() - lastMonitorAccess > monitorProgressInterval) + long passedMillis = System.currentTimeMillis() - lastMonitorAccess; + if (passedMillis > monitorProgressInterval) { - setMonitorCanceled(); + setMonitorCanceled("Timeout after " + passedMillis + " millis"); break; } @@ -168,12 +169,13 @@ public abstract class IndicationWithMonitoring extends IndicationWithResponse return 100; } - void setMonitorCanceled() + void setMonitorCanceled(String message) { synchronized (monitorLock) { if (monitor != null) { + monitor.setCancelationMessage(message); monitor.cancel(); } } @@ -189,6 +191,8 @@ public abstract class IndicationWithMonitoring extends IndicationWithResponse */ private final class LastAccessMonitor extends Monitor { + private String cancelationMessage; + public LastAccessMonitor() { } @@ -201,10 +205,15 @@ public abstract class IndicationWithMonitoring extends IndicationWithResponse } @Override - public synchronized void checkCanceled() throws MonitorCanceledException + public synchronized void worked(double work) { setLastMonitorAccess(); - super.checkCanceled(); + super.worked(work); + } + + public void setCancelationMessage(String message) + { + cancelationMessage = message; } @Override @@ -215,10 +224,22 @@ public abstract class IndicationWithMonitoring extends IndicationWithResponse } @Override - public synchronized void worked(double work) + public synchronized void checkCanceled() throws MonitorCanceledException { - setLastMonitorAccess(); - super.worked(work); + try + { + setLastMonitorAccess(); + super.checkCanceled(); + } + catch (MonitorCanceledException ex) + { + if (cancelationMessage != null) + { + throw new MonitorCanceledException(cancelationMessage); + } + + throw ex; + } } } } diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/SignalProtocol.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/SignalProtocol.java index 968c35c82a..62753b9d14 100644 --- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/SignalProtocol.java +++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/SignalProtocol.java @@ -491,7 +491,7 @@ public class SignalProtocol<INFRA_STRUCTURE> extends Protocol<INFRA_STRUCTURE> i if (signal instanceof IndicationWithMonitoring) { IndicationWithMonitoring indication = (IndicationWithMonitoring)signal; - indication.setMonitorCanceled(); + indication.setMonitorCanceled(null); } } } diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/Channel.java b/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/Channel.java index d102bef6f7..2fa4a2a490 100644 --- a/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/Channel.java +++ b/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/Channel.java @@ -247,7 +247,7 @@ public class Channel extends Lifecycle implements InternalChannel @Override protected void doDeactivate() throws Exception { - channelMultiplexer.closeChannel(this); + unregisterFromMultiplexer(); if (receiveSerializer != null) { receiveSerializer.dispose(); @@ -263,6 +263,11 @@ public class Channel extends Lifecycle implements InternalChannel super.doDeactivate(); } + protected void unregisterFromMultiplexer() + { + channelMultiplexer.closeChannel(this); + } + public void close() { Exception exception = deactivate(); |