Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2006-10-23 14:18:58 -0400
committerEike Stepper2006-10-23 14:18:58 -0400
commit13984aa28c8f87088022a0557cc858a10c433a0a (patch)
treee11f16355dd42377970dc745caa9d4376c5734f6 /plugins/org.eclipse.net4j
parenta95acf5fcc86191fe51a7e0c8e899bd4614462df (diff)
downloadcdo-13984aa28c8f87088022a0557cc858a10c433a0a.tar.gz
cdo-13984aa28c8f87088022a0557cc858a10c433a0a.tar.xz
cdo-13984aa28c8f87088022a0557cc858a10c433a0a.zip
Signal protocol
Diffstat (limited to 'plugins/org.eclipse.net4j')
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/Indication.java10
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/IndicationWithResponse.java18
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/Request.java10
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/RequestWithConfirmation.java18
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/Signal.java46
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/StrictSignalActor.java53
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/StrictSignalReactor.java50
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/stream/ExtendedDataInput.java22
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/stream/ExtendedDataInputStream.java34
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/stream/ExtendedDataOutput.java22
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/stream/ExtendedDataOutputStream.java32
11 files changed, 134 insertions, 181 deletions
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/Indication.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/Indication.java
index fb7931fd15..4eb729a78d 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/Indication.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/Indication.java
@@ -12,14 +12,14 @@ package org.eclipse.net4j.signal;
import org.eclipse.net4j.util.stream.BufferInputStream;
import org.eclipse.net4j.util.stream.BufferOutputStream;
+import org.eclipse.net4j.util.stream.ExtendedDataInputStream;
-import java.io.DataInputStream;
import java.io.IOException;
/**
* @author Eike Stepper
*/
-public abstract class Indication extends StrictSignalReactor
+public abstract class Indication extends SignalReactor
{
protected Indication()
{
@@ -29,10 +29,8 @@ public abstract class Indication extends StrictSignalReactor
protected final void execute(BufferInputStream in, BufferOutputStream out) throws Exception
{
System.out.println("================ Indicating " + this);
- inputAllowed = true;
- indicating(getDataInputStream());
- inputAllowed = false;
+ indicating(new ExtendedDataInputStream(in));
}
- protected abstract void indicating(DataInputStream in) throws IOException;
+ protected abstract void indicating(ExtendedDataInputStream in) throws IOException;
}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/IndicationWithResponse.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/IndicationWithResponse.java
index 5c1da7e1f3..2ba29d2710 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/IndicationWithResponse.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/IndicationWithResponse.java
@@ -12,15 +12,15 @@ package org.eclipse.net4j.signal;
import org.eclipse.net4j.util.stream.BufferInputStream;
import org.eclipse.net4j.util.stream.BufferOutputStream;
+import org.eclipse.net4j.util.stream.ExtendedDataInputStream;
+import org.eclipse.net4j.util.stream.ExtendedDataOutputStream;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
import java.io.IOException;
/**
* @author Eike Stepper
*/
-public abstract class IndicationWithResponse extends StrictSignalReactor
+public abstract class IndicationWithResponse extends SignalReactor
{
protected IndicationWithResponse()
{
@@ -30,18 +30,14 @@ public abstract class IndicationWithResponse extends StrictSignalReactor
protected final void execute(BufferInputStream in, BufferOutputStream out) throws Exception
{
System.out.println("================ Indicating " + this);
- inputAllowed = true;
- indicating(getDataInputStream());
- inputAllowed = false;
+ indicating(new ExtendedDataInputStream(in));
System.out.println("================ Responding " + this);
- outputAllowed = true;
- responding(getDataOutputStream());
- outputAllowed = false;
+ responding(new ExtendedDataOutputStream(out));
out.flush();
}
- protected abstract void indicating(DataInputStream in) throws IOException;
+ protected abstract void indicating(ExtendedDataInputStream in) throws IOException;
- protected abstract void responding(DataOutputStream out) throws IOException;
+ protected abstract void responding(ExtendedDataOutputStream out) throws IOException;
}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/Request.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/Request.java
index 6e0dc19ce5..e56affa5cd 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/Request.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/Request.java
@@ -13,14 +13,14 @@ package org.eclipse.net4j.signal;
import org.eclipse.net4j.transport.Channel;
import org.eclipse.net4j.util.stream.BufferInputStream;
import org.eclipse.net4j.util.stream.BufferOutputStream;
+import org.eclipse.net4j.util.stream.ExtendedDataOutputStream;
-import java.io.DataOutputStream;
import java.io.IOException;
/**
* @author Eike Stepper
*/
-public abstract class Request<RESULT> extends StrictSignalActor<RESULT>
+public abstract class Request<RESULT> extends SignalActor<RESULT>
{
protected Request(Channel channel)
{
@@ -31,11 +31,9 @@ public abstract class Request<RESULT> extends StrictSignalActor<RESULT>
protected final void execute(BufferInputStream in, BufferOutputStream out) throws Exception
{
System.out.println("================ Requesting " + this);
- outputAllowed = true;
- requesting(getDataOutputStream());
- outputAllowed = false;
+ requesting(new ExtendedDataOutputStream(out));
out.flush();
}
- protected abstract void requesting(DataOutputStream out) throws IOException;
+ protected abstract void requesting(ExtendedDataOutputStream out) throws IOException;
}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/RequestWithConfirmation.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/RequestWithConfirmation.java
index 281bb368be..cbc9a6afea 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/RequestWithConfirmation.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/RequestWithConfirmation.java
@@ -13,15 +13,15 @@ package org.eclipse.net4j.signal;
import org.eclipse.net4j.transport.Channel;
import org.eclipse.net4j.util.stream.BufferInputStream;
import org.eclipse.net4j.util.stream.BufferOutputStream;
+import org.eclipse.net4j.util.stream.ExtendedDataInputStream;
+import org.eclipse.net4j.util.stream.ExtendedDataOutputStream;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
import java.io.IOException;
/**
* @author Eike Stepper
*/
-public abstract class RequestWithConfirmation<RESULT> extends StrictSignalActor<RESULT>
+public abstract class RequestWithConfirmation<RESULT> extends SignalActor<RESULT>
{
protected RequestWithConfirmation(Channel channel)
{
@@ -32,18 +32,14 @@ public abstract class RequestWithConfirmation<RESULT> extends StrictSignalActor<
protected final void execute(BufferInputStream in, BufferOutputStream out) throws Exception
{
System.out.println("================ Requesting " + this);
- outputAllowed = true;
- requesting(getDataOutputStream());
- outputAllowed = false;
+ requesting(new ExtendedDataOutputStream(out));
out.flush();
System.out.println("================ Confirming " + this);
- inputAllowed = true;
- setResult(confirming(getDataInputStream()));
- inputAllowed = false;
+ setResult(confirming(new ExtendedDataInputStream(in)));
}
- protected abstract void requesting(DataOutputStream out) throws IOException;
+ protected abstract void requesting(ExtendedDataOutputStream out) throws IOException;
- protected abstract RESULT confirming(DataInputStream in) throws IOException;
+ protected abstract RESULT confirming(ExtendedDataInputStream in) throws IOException;
}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/Signal.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/Signal.java
index 7bc430518e..35f181b732 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/Signal.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/Signal.java
@@ -13,10 +13,6 @@ package org.eclipse.net4j.signal;
import org.eclipse.net4j.util.stream.BufferInputStream;
import org.eclipse.net4j.util.stream.BufferOutputStream;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-
/**
* @author Eike Stepper
*/
@@ -30,10 +26,6 @@ public abstract class Signal implements Runnable
private BufferOutputStream outputStream;
- private DataInputStream dataInputStream;
-
- private DataOutputStream dataOutputStream;
-
protected Signal()
{
}
@@ -58,40 +50,6 @@ public abstract class Signal implements Runnable
return outputStream;
}
- protected DataInputStream getDataInputStream()
- {
- if (dataInputStream == null)
- {
- dataInputStream = new DataInputStream(inputStream);
- }
-
- return dataInputStream;
- }
-
- protected DataOutputStream getDataOutputStream()
- {
- if (dataOutputStream == null)
- {
- dataOutputStream = new DataOutputStream(outputStream);
- }
-
- return dataOutputStream;
- }
-
- protected void writeByteArray(byte[] bytes) throws IOException
- {
- getDataOutputStream().writeInt(bytes.length);
- getDataOutputStream().write(bytes);
- }
-
- protected byte[] readByteArray() throws IOException
- {
- int length = getDataInputStream().readInt();
- byte[] bytes = new byte[length];
- getDataInputStream().read(bytes);
- return bytes;
- }
-
public final void run()
{
try
@@ -108,10 +66,10 @@ public abstract class Signal implements Runnable
}
}
- protected abstract void execute(BufferInputStream in, BufferOutputStream out) throws Exception;
-
protected abstract short getSignalID();
+ protected abstract void execute(BufferInputStream in, BufferOutputStream out) throws Exception;
+
void setProtocol(SignalProtocol protocol)
{
this.protocol = protocol;
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/StrictSignalActor.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/StrictSignalActor.java
deleted file mode 100644
index 1e764f1f17..0000000000
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/StrictSignalActor.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/***************************************************************************
- * Copyright (c) 2004, 2005, 2006 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.signal;
-
-import org.eclipse.net4j.transport.Channel;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-
-/**
- * @author Eike Stepper
- */
-abstract class StrictSignalActor<RESULT> extends SignalActor<RESULT>
-{
- boolean inputAllowed;
-
- boolean outputAllowed;
-
- protected StrictSignalActor(Channel channel)
- {
- super(channel);
- }
-
- @Override
- protected final DataInputStream getDataInputStream()
- {
- if (!inputAllowed)
- {
- throw new IllegalStateException("Input not allowed");
- }
-
- return super.getDataInputStream();
- }
-
- @Override
- protected final DataOutputStream getDataOutputStream()
- {
- if (!outputAllowed)
- {
- throw new IllegalStateException("Output not allowed");
- }
-
- return super.getDataOutputStream();
- }
-}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/StrictSignalReactor.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/StrictSignalReactor.java
deleted file mode 100644
index 04d5b9e7a5..0000000000
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/StrictSignalReactor.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/***************************************************************************
- * Copyright (c) 2004, 2005, 2006 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.signal;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-
-/**
- * @author Eike Stepper
- */
-abstract class StrictSignalReactor extends SignalReactor
-{
- boolean inputAllowed;
-
- boolean outputAllowed;
-
- protected StrictSignalReactor()
- {
- }
-
- @Override
- protected final DataInputStream getDataInputStream()
- {
- if (!inputAllowed)
- {
- throw new IllegalStateException("Input not allowed");
- }
-
- return super.getDataInputStream();
- }
-
- @Override
- protected final DataOutputStream getDataOutputStream()
- {
- if (!outputAllowed)
- {
- throw new IllegalStateException("Output not allowed");
- }
-
- return super.getDataOutputStream();
- }
-}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/stream/ExtendedDataInput.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/stream/ExtendedDataInput.java
new file mode 100644
index 0000000000..6039d8cda4
--- /dev/null
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/stream/ExtendedDataInput.java
@@ -0,0 +1,22 @@
+/***************************************************************************
+ * Copyright (c) 2004, 2005, 2006 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.stream;
+
+import java.io.DataInput;
+import java.io.IOException;
+
+/**
+ * @author Eike Stepper
+ */
+public interface ExtendedDataInput extends DataInput
+{
+ public byte[] readByteArray() throws IOException;
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/stream/ExtendedDataInputStream.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/stream/ExtendedDataInputStream.java
new file mode 100644
index 0000000000..cf5870c62c
--- /dev/null
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/stream/ExtendedDataInputStream.java
@@ -0,0 +1,34 @@
+/***************************************************************************
+ * Copyright (c) 2004, 2005, 2006 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.stream;
+
+import java.io.DataInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * @author Eike Stepper
+ */
+public class ExtendedDataInputStream extends DataInputStream implements ExtendedDataInput
+{
+ public ExtendedDataInputStream(InputStream in)
+ {
+ super(in);
+ }
+
+ public byte[] readByteArray() throws IOException
+ {
+ int length = readInt();
+ byte[] b = new byte[length];
+ read(b);
+ return b;
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/stream/ExtendedDataOutput.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/stream/ExtendedDataOutput.java
new file mode 100644
index 0000000000..b57284991e
--- /dev/null
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/stream/ExtendedDataOutput.java
@@ -0,0 +1,22 @@
+/***************************************************************************
+ * Copyright (c) 2004, 2005, 2006 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.stream;
+
+import java.io.DataOutput;
+import java.io.IOException;
+
+/**
+ * @author Eike Stepper
+ */
+public interface ExtendedDataOutput extends DataOutput
+{
+ public void writeByteArray(byte[] b) throws IOException;
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/stream/ExtendedDataOutputStream.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/stream/ExtendedDataOutputStream.java
new file mode 100644
index 0000000000..ea6e276e71
--- /dev/null
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/stream/ExtendedDataOutputStream.java
@@ -0,0 +1,32 @@
+/***************************************************************************
+ * Copyright (c) 2004, 2005, 2006 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.stream;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+
+/**
+ * @author Eike Stepper
+ */
+public class ExtendedDataOutputStream extends DataOutputStream implements ExtendedDataOutput
+{
+ public ExtendedDataOutputStream(OutputStream out)
+ {
+ super(out);
+ }
+
+ public void writeByteArray(byte[] b) throws IOException
+ {
+ writeInt(b.length);
+ write(b);
+ }
+}

Back to the top