Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2011-07-05 06:17:39 -0400
committerEike Stepper2011-07-05 06:17:39 -0400
commit75a2059650beffb52c3707c6299ce88422953868 (patch)
treedce8486fc7678456a5c09323931f45a54f94c2a9 /plugins
parentc1e7e8db43761c649da510e7dc1d208de7b541b0 (diff)
downloadcdo-75a2059650beffb52c3707c6299ce88422953868.tar.gz
cdo-75a2059650beffb52c3707c6299ce88422953868.tar.xz
cdo-75a2059650beffb52c3707c6299ce88422953868.zip
[351160] Automatically send client-side protocol timeouts to server, as well
https://bugs.eclipse.org/bugs/show_bug.cgi?id=351160
Diffstat (limited to 'plugins')
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/SetTimeoutIndication.java48
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/SetTimeoutRequest.java50
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/SignalProtocol.java62
3 files changed, 157 insertions, 3 deletions
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/SetTimeoutIndication.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/SetTimeoutIndication.java
new file mode 100644
index 0000000000..2f8485e0a7
--- /dev/null
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/SetTimeoutIndication.java
@@ -0,0 +1,48 @@
+/**
+ * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
+ * 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.signal;
+
+import org.eclipse.net4j.util.io.ExtendedDataInputStream;
+import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
+import org.eclipse.net4j.util.om.trace.ContextTracer;
+
+import org.eclipse.internal.net4j.bundle.OM;
+
+/**
+ * @author Eike Stepper
+ */
+class SetTimeoutIndication extends IndicationWithResponse
+{
+ private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_SIGNAL, SetTimeoutIndication.class);
+
+ public SetTimeoutIndication(SignalProtocol<?> protocol)
+ {
+ super(protocol, SignalProtocol.SIGNAL_SET_TIMEOUT);
+ }
+
+ @Override
+ protected void indicating(ExtendedDataInputStream in) throws Exception
+ {
+ long timeout = in.readLong();
+ if (TRACER.isEnabled())
+ {
+ TRACER.format("Set timeout: {0}", timeout); //$NON-NLS-1$
+ }
+
+ getProtocol().handleSetTimeOut(timeout);
+ }
+
+ @Override
+ protected void responding(ExtendedDataOutputStream out) throws Exception
+ {
+ out.writeBoolean(true);
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/SetTimeoutRequest.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/SetTimeoutRequest.java
new file mode 100644
index 0000000000..e7daa796ee
--- /dev/null
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/SetTimeoutRequest.java
@@ -0,0 +1,50 @@
+/**
+ * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
+ * 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.signal;
+
+import org.eclipse.net4j.util.io.ExtendedDataInputStream;
+import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
+import org.eclipse.net4j.util.om.trace.ContextTracer;
+
+import org.eclipse.internal.net4j.bundle.OM;
+
+/**
+ * @author Eike Stepper
+ */
+class SetTimeoutRequest extends RequestWithConfirmation<Boolean>
+{
+ private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_SIGNAL, SetTimeoutRequest.class);
+
+ private long timeout;
+
+ public SetTimeoutRequest(SignalProtocol<?> protocol, long timeout)
+ {
+ super(protocol, SignalProtocol.SIGNAL_SET_TIMEOUT);
+ this.timeout = timeout;
+ }
+
+ @Override
+ protected void requesting(ExtendedDataOutputStream out) throws Exception
+ {
+ if (TRACER.isEnabled())
+ {
+ TRACER.format("Set timeout: {0}", timeout); //$NON-NLS-1$
+ }
+
+ out.writeLong(timeout);
+ }
+
+ @Override
+ protected Boolean confirming(ExtendedDataInputStream in) throws Exception
+ {
+ return in.readBoolean();
+ }
+}
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 ab66e4d513..b094cf8fe3 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
@@ -17,6 +17,7 @@ import org.eclipse.net4j.buffer.IBufferProvider;
import org.eclipse.net4j.channel.ChannelOutputStream;
import org.eclipse.net4j.channel.IChannel;
import org.eclipse.net4j.connector.IConnector;
+import org.eclipse.net4j.util.WrappedException;
import org.eclipse.net4j.util.event.Event;
import org.eclipse.net4j.util.event.IListener;
import org.eclipse.net4j.util.io.IORuntimeException;
@@ -59,6 +60,11 @@ public class SignalProtocol<INFRA_STRUCTURE> extends Protocol<INFRA_STRUCTURE> i
*/
public static final short SIGNAL_MONITOR_PROGRESS = -3;
+ /**
+ * @since 4.1
+ */
+ public static final short SIGNAL_SET_TIMEOUT = -4;
+
private static final int MIN_CORRELATION_ID = 1;
private static final int MAX_CORRELATION_ID = Integer.MAX_VALUE;
@@ -99,10 +105,11 @@ public class SignalProtocol<INFRA_STRUCTURE> extends Protocol<INFRA_STRUCTURE> i
public void setTimeout(long timeout)
{
long oldTimeout = this.timeout;
- if (oldTimeout != timeout)
+ handleSetTimeOut(timeout);
+
+ if (oldTimeout != this.timeout && isActive())
{
- this.timeout = timeout;
- fireEvent(new TimeoutChangedEvent(this, oldTimeout, timeout));
+ sendSetTimeout();
}
}
@@ -246,6 +253,17 @@ public class SignalProtocol<INFRA_STRUCTURE> extends Protocol<INFRA_STRUCTURE> i
}
@Override
+ protected void doAfterActivate() throws Exception
+ {
+ super.doAfterActivate();
+
+ if (timeout != DEFAULT_TIMEOUT)
+ {
+ sendSetTimeout();
+ }
+ }
+
+ @Override
protected void doBeforeDeactivate() throws Exception
{
synchronized (signals)
@@ -301,6 +319,9 @@ public class SignalProtocol<INFRA_STRUCTURE> extends Protocol<INFRA_STRUCTURE> i
case SIGNAL_MONITOR_PROGRESS:
return new MonitorProgressIndication(this);
+ case SIGNAL_SET_TIMEOUT:
+ return new SetTimeoutIndication(this);
+
default:
SignalReactor signal = createSignalReactor(signalID);
if (signal == null)
@@ -321,6 +342,16 @@ public class SignalProtocol<INFRA_STRUCTURE> extends Protocol<INFRA_STRUCTURE> i
return null;
}
+ /**
+ * Returns <code>true</code> by default, override to change this behaviour.
+ *
+ * @since 4.1
+ */
+ protected boolean isSendingTimeoutChanges()
+ {
+ return true;
+ }
+
synchronized int getNextCorrelationID()
{
int correlationID = nextCorrelationID;
@@ -459,6 +490,31 @@ public class SignalProtocol<INFRA_STRUCTURE> extends Protocol<INFRA_STRUCTURE> i
}
}
+ void handleSetTimeOut(long timeout)
+ {
+ long oldTimeout = this.timeout;
+ if (oldTimeout != timeout)
+ {
+ this.timeout = timeout;
+ fireEvent(new TimeoutChangedEvent(this, oldTimeout, timeout));
+ }
+ }
+
+ void sendSetTimeout()
+ {
+ if (isSendingTimeoutChanges())
+ {
+ try
+ {
+ new SetTimeoutRequest(this, this.timeout).send();
+ }
+ catch (Exception ex)
+ {
+ throw WrappedException.wrap(ex);
+ }
+ }
+ }
+
/**
* @author Eike Stepper
* @since 4.1

Back to the top