Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2012-08-15 07:06:35 +0000
committerEike Stepper2012-08-15 07:06:35 +0000
commit7eb4acd2f91f852946fb40ad647740dc69e8b69b (patch)
treec41bce7ac0ad531ecd3b8fa77420b8ae88f03deb /plugins
parent7cc89ae0efe2ab1fd6d4ed071b4a6f96852ff336 (diff)
downloadcdo-7eb4acd2f91f852946fb40ad647740dc69e8b69b.tar.gz
cdo-7eb4acd2f91f852946fb40ad647740dc69e8b69b.tar.xz
cdo-7eb4acd2f91f852946fb40ad647740dc69e8b69b.zip
[259086] Protocol versions should be checked
https://bugs.eclipse.org/bugs/show_bug.cgi?id=259086
Diffstat (limited to 'plugins')
-rw-r--r--plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/protocol/CDOProtocol.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/protocol/CDOProtocolConstants.java7
-rw-r--r--plugins/org.eclipse.emf.cdo.net4j/src/org/eclipse/emf/cdo/internal/net4j/protocol/CDOClientProtocol.java6
-rw-r--r--plugins/org.eclipse.emf.cdo.server.net4j/src/org/eclipse/emf/cdo/server/internal/net4j/protocol/CDOServerProtocol.java6
-rw-r--r--plugins/org.eclipse.net4j.http.common/META-INF/MANIFEST.MF10
-rw-r--r--plugins/org.eclipse.net4j.http.common/src/org/eclipse/net4j/http/internal/common/HTTPConnector.java17
-rw-r--r--plugins/org.eclipse.net4j.jvm/META-INF/MANIFEST.MF10
-rw-r--r--plugins/org.eclipse.net4j.jvm/src/org/eclipse/net4j/internal/jvm/JVMConnector.java7
-rw-r--r--plugins/org.eclipse.net4j.tcp/META-INF/MANIFEST.MF14
-rw-r--r--plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/ControlChannel.java64
-rw-r--r--plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPConnector.java17
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/AllTests.java11
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/bugzilla/Bugzilla_241463_Test.java116
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/bugzilla/Bugzilla_259086_Test.java141
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/TestSignalProtocol.java33
-rw-r--r--plugins/org.eclipse.net4j/META-INF/MANIFEST.MF28
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/BufferUtil.java133
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/Net4jUtil.java30
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/protocol/IProtocol2.java24
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/protocol/ProtocolVersionException.java53
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/ChannelMultiplexer.java15
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/Protocol.java12
22 files changed, 607 insertions, 149 deletions
diff --git a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/protocol/CDOProtocol.java b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/protocol/CDOProtocol.java
index 211b423604..6b80c18e9f 100644
--- a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/protocol/CDOProtocol.java
+++ b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/protocol/CDOProtocol.java
@@ -14,7 +14,7 @@ import org.eclipse.emf.cdo.common.CDOCommonSession;
/**
* The communications protocol associated with a CDO {@link CDOCommonSession session}.
- *
+ *
* @author Eike Stepper
* @since 2.0
* @noextend This interface is not intended to be extended by clients.
diff --git a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/protocol/CDOProtocolConstants.java b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/protocol/CDOProtocolConstants.java
index 5d2b64b780..9435f8c57a 100644
--- a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/protocol/CDOProtocolConstants.java
+++ b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/protocol/CDOProtocolConstants.java
@@ -15,7 +15,7 @@ package org.eclipse.emf.cdo.common.protocol;
/**
* Symbolic protocol constants commonly used in CDO.
- *
+ *
* @author Eike Stepper
* @since 2.0
* @noextend This interface is not intended to be extended by clients.
@@ -25,6 +25,11 @@ public interface CDOProtocolConstants
{
public static final String PROTOCOL_NAME = "cdo"; //$NON-NLS-1$
+ /**
+ * @since 4.2
+ */
+ public static final int PROTOCOL_VERSION = 9;
+
// //////////////////////////////////////////////////////////////////////
// Signal IDs
diff --git a/plugins/org.eclipse.emf.cdo.net4j/src/org/eclipse/emf/cdo/internal/net4j/protocol/CDOClientProtocol.java b/plugins/org.eclipse.emf.cdo.net4j/src/org/eclipse/emf/cdo/internal/net4j/protocol/CDOClientProtocol.java
index 55ee5d22e3..6d073bdf6e 100644
--- a/plugins/org.eclipse.emf.cdo.net4j/src/org/eclipse/emf/cdo/internal/net4j/protocol/CDOClientProtocol.java
+++ b/plugins/org.eclipse.emf.cdo.net4j/src/org/eclipse/emf/cdo/internal/net4j/protocol/CDOClientProtocol.java
@@ -87,6 +87,12 @@ public class CDOClientProtocol extends SignalProtocol<CDOSession> implements CDO
super(CDOProtocolConstants.PROTOCOL_NAME);
}
+ @Override
+ public int getVersion()
+ {
+ return CDOProtocolConstants.PROTOCOL_VERSION;
+ }
+
public CDOSession getSession()
{
return getInfraStructure();
diff --git a/plugins/org.eclipse.emf.cdo.server.net4j/src/org/eclipse/emf/cdo/server/internal/net4j/protocol/CDOServerProtocol.java b/plugins/org.eclipse.emf.cdo.server.net4j/src/org/eclipse/emf/cdo/server/internal/net4j/protocol/CDOServerProtocol.java
index 93472dfad4..91fb1cdd66 100644
--- a/plugins/org.eclipse.emf.cdo.server.net4j/src/org/eclipse/emf/cdo/server/internal/net4j/protocol/CDOServerProtocol.java
+++ b/plugins/org.eclipse.emf.cdo.server.net4j/src/org/eclipse/emf/cdo/server/internal/net4j/protocol/CDOServerProtocol.java
@@ -52,6 +52,12 @@ public class CDOServerProtocol extends SignalProtocol<InternalSession> implement
this.repositoryProvider = repositoryProvider;
}
+ @Override
+ public int getVersion()
+ {
+ return CDOProtocolConstants.PROTOCOL_VERSION;
+ }
+
public InternalSession getSession()
{
return getInfraStructure();
diff --git a/plugins/org.eclipse.net4j.http.common/META-INF/MANIFEST.MF b/plugins/org.eclipse.net4j.http.common/META-INF/MANIFEST.MF
index f70b5ff6b3..56ff33a571 100644
--- a/plugins/org.eclipse.net4j.http.common/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.net4j.http.common/META-INF/MANIFEST.MF
@@ -1,7 +1,7 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-SymbolicName: org.eclipse.net4j.http.common
-Bundle-Version: 4.0.100.qualifier
+Bundle-Version: 4.0.200.qualifier
Bundle-Name: %pluginName
Bundle-Vendor: %providerName
Bundle-Localization: plugin
@@ -11,11 +11,11 @@ Bundle-RequiredExecutionEnvironment: J2SE-1.5
Bundle-ClassPath: .
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.4.0,4.0.0)";resolution:=optional,
org.eclipse.net4j;bundle-version="[4.0.0,5.0.0)";visibility:=reexport
-Export-Package: org.eclipse.net4j.http.common;version="4.0.100";uses:="org.eclipse.net4j.connector",
- org.eclipse.net4j.http.internal.common;version="4.0.100";
+Export-Package: org.eclipse.net4j.http.common;version="4.0.200";uses:="org.eclipse.net4j.connector",
+ org.eclipse.net4j.http.internal.common;version="4.0.200";
x-friends:="org.eclipse.net4j.http,
org.eclipse.net4j.http.server,
org.eclipse.net4j.http.tests,
org.eclipse.net4j.defs",
- org.eclipse.net4j.http.internal.common.bundle;version="4.0.100";x-friends:="org.eclipse.net4j.http,org.eclipse.net4j.http.server,org.eclipse.net4j.http.tests",
- org.eclipse.net4j.http.internal.common.messages;version="4.0.100";x-internal:=true
+ org.eclipse.net4j.http.internal.common.bundle;version="4.0.200";x-friends:="org.eclipse.net4j.http,org.eclipse.net4j.http.server,org.eclipse.net4j.http.tests",
+ org.eclipse.net4j.http.internal.common.messages;version="4.0.200";x-internal:=true
diff --git a/plugins/org.eclipse.net4j.http.common/src/org/eclipse/net4j/http/internal/common/HTTPConnector.java b/plugins/org.eclipse.net4j.http.common/src/org/eclipse/net4j/http/internal/common/HTTPConnector.java
index ce521cd7de..c0ab99e630 100644
--- a/plugins/org.eclipse.net4j.http.common/src/org/eclipse/net4j/http/internal/common/HTTPConnector.java
+++ b/plugins/org.eclipse.net4j.http.common/src/org/eclipse/net4j/http/internal/common/HTTPConnector.java
@@ -10,6 +10,7 @@
*/
package org.eclipse.net4j.http.internal.common;
+import org.eclipse.net4j.Net4jUtil;
import org.eclipse.net4j.buffer.IBuffer;
import org.eclipse.net4j.channel.ChannelException;
import org.eclipse.net4j.connector.ConnectorException;
@@ -114,7 +115,7 @@ public abstract class HTTPConnector extends Connector implements IHTTPConnector
/**
* Writes operations from the {@link #outputOperations} to the passed stream. After each written operation
* {@link #writeMoreOperations()} is asked whether to send more operations.
- *
+ *
* @return <code>true</code> if more operations are in the {@link #outputOperations}, <code>false</code> otherwise.
*/
public boolean writeOutputOperations(ExtendedDataOutputStream out) throws IOException
@@ -191,7 +192,10 @@ public abstract class HTTPConnector extends Connector implements IHTTPConnector
@Override
protected void registerChannelWithPeer(short channelID, long timeout, IProtocol<?> protocol) throws ChannelException
{
- ChannelOperation operation = new OpenChannelOperation(channelID, protocol.getType());
+ String protocolID = Net4jUtil.getProtocolID(protocol);
+ int protocolVersion = Net4jUtil.getProtocolVersion(protocol);
+
+ ChannelOperation operation = new OpenChannelOperation(channelID, protocolID, protocolVersion);
outputOperations.add(operation);
HTTPChannel channel = (HTTPChannel)getChannel(channelID);
@@ -322,16 +326,20 @@ public abstract class HTTPConnector extends Connector implements IHTTPConnector
{
private String protocolID;
- public OpenChannelOperation(short channelID, String protocolID)
+ private int protocolVersion;
+
+ public OpenChannelOperation(short channelID, String protocolID, int protocolVersion)
{
super(channelID, 0);
this.protocolID = protocolID;
+ this.protocolVersion = protocolVersion;
}
public OpenChannelOperation(ExtendedDataInputStream in) throws IOException
{
super(in);
protocolID = in.readString();
+ protocolVersion = in.readInt();
}
@Override
@@ -339,6 +347,7 @@ public abstract class HTTPConnector extends Connector implements IHTTPConnector
{
super.write(out);
out.writeString(protocolID);
+ out.writeInt(protocolVersion);
}
@Override
@@ -350,7 +359,7 @@ public abstract class HTTPConnector extends Connector implements IHTTPConnector
@Override
public void execute()
{
- HTTPChannel channel = (HTTPChannel)inverseOpenChannel(getChannelID(), protocolID);
+ HTTPChannel channel = (HTTPChannel)inverseOpenChannel(getChannelID(), protocolID, protocolVersion);
if (channel == null)
{
throw new ConnectorException(Messages.getString("HTTPConnector.0")); //$NON-NLS-1$
diff --git a/plugins/org.eclipse.net4j.jvm/META-INF/MANIFEST.MF b/plugins/org.eclipse.net4j.jvm/META-INF/MANIFEST.MF
index de25a752a7..3a6bc8ddbc 100644
--- a/plugins/org.eclipse.net4j.jvm/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.net4j.jvm/META-INF/MANIFEST.MF
@@ -1,7 +1,7 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-SymbolicName: org.eclipse.net4j.jvm;singleton:=true
-Bundle-Version: 4.1.0.qualifier
+Bundle-Version: 4.1.100.qualifier
Bundle-Name: %pluginName
Bundle-Vendor: %providerName
Bundle-Localization: plugin
@@ -12,7 +12,7 @@ Bundle-ClassPath: .
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.4.0,4.0.0)";resolution:=optional,
org.eclipse.net4j;bundle-version="[4.0.0,5.0.0)";visibility:=reexport
Import-Package: org.osgi.framework;version="[1.3.0,2.0.0)";resolution:=optional
-Export-Package: org.eclipse.net4j.internal.jvm;version="4.1.0";x-friends:="org.eclipse.net4j.defs,org.eclipse.net4j.tests,org.eclipse.net4j.ui",
- org.eclipse.net4j.internal.jvm.bundle;version="4.1.0";x-internal:=true,
- org.eclipse.net4j.internal.jvm.messages;version="4.1.0";x-internal:=true,
- org.eclipse.net4j.jvm;version="4.1.0"
+Export-Package: org.eclipse.net4j.internal.jvm;version="4.1.100";x-friends:="org.eclipse.net4j.defs,org.eclipse.net4j.tests,org.eclipse.net4j.ui",
+ org.eclipse.net4j.internal.jvm.bundle;version="4.1.100";x-internal:=true,
+ org.eclipse.net4j.internal.jvm.messages;version="4.1.100";x-internal:=true,
+ org.eclipse.net4j.jvm;version="4.1.100"
diff --git a/plugins/org.eclipse.net4j.jvm/src/org/eclipse/net4j/internal/jvm/JVMConnector.java b/plugins/org.eclipse.net4j.jvm/src/org/eclipse/net4j/internal/jvm/JVMConnector.java
index 837f33869a..5b710183f1 100644
--- a/plugins/org.eclipse.net4j.jvm/src/org/eclipse/net4j/internal/jvm/JVMConnector.java
+++ b/plugins/org.eclipse.net4j.jvm/src/org/eclipse/net4j/internal/jvm/JVMConnector.java
@@ -10,6 +10,7 @@
*/
package org.eclipse.net4j.internal.jvm;
+import org.eclipse.net4j.Net4jUtil;
import org.eclipse.net4j.buffer.IBuffer;
import org.eclipse.net4j.channel.ChannelException;
import org.eclipse.net4j.internal.jvm.bundle.OM;
@@ -115,8 +116,10 @@ public abstract class JVMConnector extends Connector implements IJVMConnector
{
try
{
- String protocolID = protocol == null ? null : protocol.getType();
- JVMChannel peerChannel = (JVMChannel)peer.inverseOpenChannel(channelID, protocolID);
+ String protocolID = Net4jUtil.getProtocolID(protocol);
+ int protocolVersion = Net4jUtil.getProtocolVersion(protocol);
+
+ JVMChannel peerChannel = (JVMChannel)peer.inverseOpenChannel(channelID, protocolID, protocolVersion);
if (peerChannel == null)
{
throw new ChannelException(Messages.getString("JVMConnector.2")); //$NON-NLS-1$
diff --git a/plugins/org.eclipse.net4j.tcp/META-INF/MANIFEST.MF b/plugins/org.eclipse.net4j.tcp/META-INF/MANIFEST.MF
index bf671b597f..95cdf1a28e 100644
--- a/plugins/org.eclipse.net4j.tcp/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.net4j.tcp/META-INF/MANIFEST.MF
@@ -1,7 +1,7 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-SymbolicName: org.eclipse.net4j.tcp;singleton:=true
-Bundle-Version: 4.1.0.qualifier
+Bundle-Version: 4.1.100.qualifier
Bundle-Name: %pluginName
Bundle-Vendor: %providerName
Bundle-Localization: plugin
@@ -12,13 +12,13 @@ Bundle-ClassPath: .
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.4.0,4.0.0)";resolution:=optional,
org.eclipse.net4j;bundle-version="[4.0.0,5.0.0)";visibility:=reexport
Import-Package: org.osgi.framework;version="[1.3.0,2.0.0)";resolution:=optional
-Export-Package: org.eclipse.net4j.internal.tcp;version="4.1.0";
+Export-Package: org.eclipse.net4j.internal.tcp;version="4.1.100";
x-friends:="org.eclipse.net4j.tests,
org.eclipse.net4j.defs,
org.eclipse.emf.cdo.examples,
org.eclipse.net4j.ui",
- org.eclipse.net4j.internal.tcp.bundle;version="4.1.0";x-internal:=true,
- org.eclipse.net4j.internal.tcp.messages;version="4.1.0";x-internal:=true,
- org.eclipse.net4j.internal.tcp.ssl;version="4.1.0";x-friends:="org.eclipse.net4j.tests,org.eclipse.net4j.defs,org.eclipse.emf.cdo.examples",
- org.eclipse.net4j.tcp;version="4.1.0",
- org.eclipse.net4j.tcp.ssl;version="4.1.0"
+ org.eclipse.net4j.internal.tcp.bundle;version="4.1.100";x-internal:=true,
+ org.eclipse.net4j.internal.tcp.messages;version="4.1.100";x-internal:=true,
+ org.eclipse.net4j.internal.tcp.ssl;version="4.1.100";x-friends:="org.eclipse.net4j.tests,org.eclipse.net4j.defs,org.eclipse.emf.cdo.examples",
+ org.eclipse.net4j.tcp;version="4.1.100",
+ org.eclipse.net4j.tcp.ssl;version="4.1.100"
diff --git a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/ControlChannel.java b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/ControlChannel.java
index 18ac3648ea..1fc1e7ac90 100644
--- a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/ControlChannel.java
+++ b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/ControlChannel.java
@@ -10,7 +10,9 @@
*/
package org.eclipse.net4j.internal.tcp;
+import org.eclipse.net4j.Net4jUtil;
import org.eclipse.net4j.buffer.IBuffer;
+import org.eclipse.net4j.channel.ChannelException;
import org.eclipse.net4j.connector.ConnectorException;
import org.eclipse.net4j.internal.tcp.bundle.OM;
import org.eclipse.net4j.internal.tcp.messages.Messages;
@@ -42,19 +44,23 @@ public class ControlChannel extends Channel
public static final byte OPCODE_NEGOTIATION = 1;
+ /**
+ * @deprecated Indicates Net4j version before 4.2. As of 4.2 Net4j uses {@link #OPCODE_REGISTRATION_VERSIONED}.
+ */
+ @Deprecated
public static final byte OPCODE_REGISTRATION = 2;
public static final byte OPCODE_REGISTRATION_ACK = 3;
public static final byte OPCODE_DEREGISTRATION = 4;
- public static final byte SUCCESS = 1;
+ public static final byte OPCODE_REGISTRATION_VERSIONED = 5;
- public static final byte FAILURE = 0;
+ private static final String SUCCESS = "Success";
private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, ControlChannel.class);
- private SynchronizingCorrelator<Short, Boolean> acknowledgements = new SynchronizingCorrelator<Short, Boolean>();
+ private SynchronizingCorrelator<Short, String> acknowledgements = new SynchronizingCorrelator<Short, String>();
public ControlChannel(TCPConnector connector)
{
@@ -69,7 +75,7 @@ public class ControlChannel extends Channel
return (TCPConnector)getMultiplexer();
}
- public boolean registerChannel(short channelID, long timeout, IProtocol<?> protocol)
+ public void registerChannel(short channelID, long timeout, IProtocol<?> protocol)
{
if (TRACER.isEnabled())
{
@@ -77,22 +83,29 @@ public class ControlChannel extends Channel
}
assertValidChannelID(channelID);
- ISynchronizer<Boolean> acknowledgement = acknowledgements.correlate(channelID);
+ ISynchronizer<String> acknowledgement = acknowledgements.correlate(channelID);
+
+ int protocolVersion = Net4jUtil.getProtocolVersion(protocol);
+ String protocolID = Net4jUtil.getProtocolID(protocol);
IBuffer buffer = provideBuffer();
ByteBuffer byteBuffer = buffer.startPutting(CONTROL_CHANNEL_INDEX);
- byteBuffer.put(OPCODE_REGISTRATION);
+ byteBuffer.put(OPCODE_REGISTRATION_VERSIONED);
byteBuffer.putShort(channelID);
- BufferUtil.putUTF8(byteBuffer, protocol == null ? null : protocol.getType());
+ byteBuffer.putInt(protocolVersion);
+ BufferUtil.putString(byteBuffer, protocolID, false);
handleBuffer(buffer);
- Boolean acknowledged = acknowledgement.get(timeout);
- if (acknowledged == null)
+ String error = acknowledgement.get(timeout);
+ if (error == null)
{
throw new TimeoutRuntimeException(MessageFormat.format(Messages.getString("ControlChannel_0"), timeout)); //$NON-NLS-1$
}
- return acknowledged;
+ if (error != SUCCESS)
+ {
+ throw new ChannelException("Failed to register channel with peer: " + error); //$NON-NLS-1$
+ }
}
public void deregisterChannel(short channelID)
@@ -135,17 +148,23 @@ public class ControlChannel extends Channel
}
case OPCODE_REGISTRATION:
+ OM.LOG.error("Deprecated opcode: Client should use newer Net4j version"); //$NON-NLS-1$
+ getConnector().deactivate();
+ break;
+
+ case OPCODE_REGISTRATION_VERSIONED:
{
assertConnected();
short channelID = byteBuffer.getShort();
assertValidChannelID(channelID);
- boolean success = true;
+ String error = null;
try
{
- byte[] handlerFactoryUTF8 = BufferUtil.getByteArray(byteBuffer);
- String protocolID = BufferUtil.fromUTF8(handlerFactoryUTF8);
- InternalChannel channel = getConnector().inverseOpenChannel(channelID, protocolID);
+ int protocolVersion = byteBuffer.getInt();
+ String protocolID = BufferUtil.getString(byteBuffer);
+
+ InternalChannel channel = getConnector().inverseOpenChannel(channelID, protocolID, protocolVersion);
if (channel == null)
{
throw new ConnectorException(Messages.getString("ControlChannel_4")); //$NON-NLS-1$
@@ -153,14 +172,14 @@ public class ControlChannel extends Channel
}
catch (Exception ex)
{
- success = false;
+ error = ex.getMessage();
if (TRACER.isEnabled())
{
TRACER.trace("Problem during channel registration", ex); //$NON-NLS-1$
}
}
- sendStatus(OPCODE_REGISTRATION_ACK, channelID, success);
+ sendStatus(OPCODE_REGISTRATION_ACK, channelID, error);
break;
}
@@ -192,8 +211,13 @@ public class ControlChannel extends Channel
{
assertConnected();
short channelID = byteBuffer.getShort();
- boolean success = byteBuffer.get() == SUCCESS;
- acknowledgements.put(channelID, success);
+ String error = BufferUtil.getString(byteBuffer);
+ if (error == null)
+ {
+ error = SUCCESS;
+ }
+
+ acknowledgements.put(channelID, error);
break;
}
@@ -220,13 +244,13 @@ public class ControlChannel extends Channel
// Do nothing
}
- private void sendStatus(byte opcode, short channelID, boolean status)
+ private void sendStatus(byte opcode, short channelID, String error)
{
IBuffer buffer = provideBuffer();
ByteBuffer byteBuffer = buffer.startPutting(CONTROL_CHANNEL_INDEX);
byteBuffer.put(opcode);
byteBuffer.putShort(channelID);
- byteBuffer.put(status ? SUCCESS : FAILURE);
+ BufferUtil.putString(byteBuffer, error, true);
handleBuffer(buffer);
}
diff --git a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPConnector.java b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPConnector.java
index 388d3ad635..c0d55561e5 100644
--- a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPConnector.java
+++ b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPConnector.java
@@ -14,7 +14,6 @@ package org.eclipse.net4j.internal.tcp;
import org.eclipse.net4j.buffer.IBuffer;
import org.eclipse.net4j.channel.ChannelException;
import org.eclipse.net4j.channel.IChannel;
-import org.eclipse.net4j.connector.ConnectorException;
import org.eclipse.net4j.connector.ConnectorState;
import org.eclipse.net4j.internal.tcp.bundle.OM;
import org.eclipse.net4j.internal.tcp.messages.Messages;
@@ -358,21 +357,7 @@ public abstract class TCPConnector extends Connector implements ITCPConnector, I
@Override
protected void registerChannelWithPeer(short channelID, long timeout, IProtocol<?> protocol) throws ChannelException
{
- try
- {
- if (!controlChannel.registerChannel(channelID, timeout, protocol))
- {
- throw new ChannelException("Failed to register channel with peer"); //$NON-NLS-1$
- }
- }
- catch (RuntimeException ex)
- {
- throw ex;
- }
- catch (Exception ex)
- {
- throw new ConnectorException(ex);
- }
+ controlChannel.registerChannel(channelID, timeout, protocol);
}
@Override
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/AllTests.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/AllTests.java
index 6543c4dc52..6044b890f8 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/AllTests.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/AllTests.java
@@ -11,6 +11,7 @@
package org.eclipse.net4j.tests;
import org.eclipse.net4j.tests.bugzilla.Bugzilla_241463_Test;
+import org.eclipse.net4j.tests.bugzilla.Bugzilla_259086_Test;
import org.eclipse.net4j.tests.bugzilla.Bugzilla_262875_Test;
import org.eclipse.net4j.util.tests.ExpectedIOTest;
import org.eclipse.net4j.util.tests.ExtendedIOTest;
@@ -44,26 +45,22 @@ public class AllTests
suite.addTestSuite(StringCompressorTest.class);
suite.addTestSuite(ChannelTest.JVM.class);
suite.addTestSuite(ChannelTest.TCP.class);
- // suite.addTestSuite(ChannelTest.SSL.class);
suite.addTestSuite(TCPConnectorTest.TCP.class);
- // suite.addTestSuite(TCPConnectorTest.SSL.class);
suite.addTestSuite(TransportTest.JVM.class);
suite.addTestSuite(TransportTest.TCP.class);
- // suite.addTestSuite(TransportTest.SSL.class);
suite.addTestSuite(SignalTest.TCP.class);
- // suite.addTestSuite(SignalTest.SSL.class);
suite.addTestSuite(SignalMonitorTest.TCP.class);
- // suite.addTestSuite(SignalMonitorTest.SSL.class);
suite.addTestSuite(ExceptionTest.TCP.class);
- // suite.addTestSuite(ExceptionTest.SSL.class);
suite.addTestSuite(SecurityTest.class);
suite.addTestSuite(QueueWorkerWorkSerializerTest.class);
suite.addTestSuite(ExpectedIOTest.class);
// Bugzillas
+ suite.addTestSuite(Bugzilla_241463_Test.JVM.class);
suite.addTestSuite(Bugzilla_241463_Test.TCP.class);
- // suite.addTestSuite(Bugzilla_241463_Test.SSL.class);
suite.addTestSuite(Bugzilla_262875_Test.class);
+ suite.addTestSuite(Bugzilla_259086_Test.JVM.class);
+ suite.addTestSuite(Bugzilla_259086_Test.TCP.class);
// Defs
// suite.addTestSuite(TestDefTest.class);
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/bugzilla/Bugzilla_241463_Test.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/bugzilla/Bugzilla_241463_Test.java
index 95d46d8b6e..2b31b8c758 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/bugzilla/Bugzilla_241463_Test.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/bugzilla/Bugzilla_241463_Test.java
@@ -7,32 +7,30 @@
*
* Contributors:
* Eike Stepper - initial API and implementation
- * Teerawat Chaiyakijpichet (No Magic Asia Ltd.) - maintenance (SSL)
+ * Teerawat Chaiyakijpichet (No Magic Asia Ltd.) - maintenance (SSL)
*/
package org.eclipse.net4j.tests.bugzilla;
-import org.eclipse.net4j.TransportInjector;
+import org.eclipse.net4j.Net4jUtil;
+import org.eclipse.net4j.internal.jvm.JVMAcceptor;
+import org.eclipse.net4j.internal.jvm.JVMAcceptorFactory;
+import org.eclipse.net4j.internal.jvm.JVMClientConnector;
+import org.eclipse.net4j.internal.jvm.JVMServerConnector;
import org.eclipse.net4j.internal.tcp.TCPAcceptor;
import org.eclipse.net4j.internal.tcp.TCPAcceptorFactory;
-import org.eclipse.net4j.internal.tcp.TCPConnectorFactory;
-import org.eclipse.net4j.internal.tcp.TCPSelectorFactory;
-import org.eclipse.net4j.internal.tcp.TCPSelectorInjector;
import org.eclipse.net4j.internal.tcp.TCPServerConnector;
import org.eclipse.net4j.internal.tcp.ssl.SSLAcceptor;
import org.eclipse.net4j.internal.tcp.ssl.SSLAcceptorFactory;
-import org.eclipse.net4j.internal.tcp.ssl.SSLConnectorFactory;
import org.eclipse.net4j.internal.tcp.ssl.SSLServerConnector;
+import org.eclipse.net4j.jvm.JVMUtil;
import org.eclipse.net4j.tcp.ITCPAcceptor;
import org.eclipse.net4j.tcp.ITCPSelector;
+import org.eclipse.net4j.tcp.TCPUtil;
+import org.eclipse.net4j.tcp.ssl.SSLUtil;
import org.eclipse.net4j.tests.AbstractTransportTest;
-import org.eclipse.net4j.tests.ChannelTest;
import org.eclipse.net4j.tests.signal.TestSignalProtocol;
-import org.eclipse.net4j.util.concurrent.ExecutorServiceFactory;
import org.eclipse.net4j.util.container.IManagedContainer;
import org.eclipse.net4j.util.container.ManagedContainer;
-import org.eclipse.net4j.util.security.RandomizerFactory;
-
-import org.eclipse.internal.net4j.buffer.BufferProviderFactory;
import org.eclipse.spi.net4j.InternalChannel;
@@ -41,6 +39,8 @@ import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
/**
+ * See bug 241463.
+ *
* @author Eike Stepper
*/
public class Bugzilla_241463_Test extends AbstractTransportTest
@@ -49,30 +49,15 @@ public class Bugzilla_241463_Test extends AbstractTransportTest
protected IManagedContainer createContainer()
{
IManagedContainer container = new ManagedContainer();
+ Net4jUtil.prepareContainer(container);
+ JVMUtil.prepareContainer(container);
+ TCPUtil.prepareContainer(container);
+ SSLUtil.prepareContainer(container);
- // Net4j
- container.registerFactory(new ExecutorServiceFactory());
- container.registerFactory(new BufferProviderFactory());
- container.registerFactory(new RandomizerFactory());
- container.addPostProcessor(new TransportInjector());
+ container.registerFactory(new FakeJVMAcceptorFactory());
+ container.registerFactory(new FakeTCPAcceptorFactory());
+ container.registerFactory(new FakeSSLAcceptorFactory());
- container.registerFactory(new TCPSelectorFactory());
- container.addPostProcessor(new TCPSelectorInjector());
-
- if (useSSLTransport())
- {
- // SSL
- container.registerFactory(new FakeSSLAcceptorFactory());
- container.registerFactory(new SSLConnectorFactory());
- }
- else
- {
- // TCP
- container.registerFactory(new FakeAcceptorFactory());
- container.registerFactory(new TCPConnectorFactory());
- }
-
- // Test
container.registerFactory(new TestSignalProtocol.Factory());
return container;
}
@@ -95,7 +80,42 @@ public class Bugzilla_241463_Test extends AbstractTransportTest
/**
* @author Eike Stepper
*/
- private static final class FakeAcceptorFactory extends TCPAcceptorFactory
+ private static final class FakeJVMAcceptorFactory extends JVMAcceptorFactory
+ {
+ @Override
+ public JVMAcceptor create(String description)
+ {
+ JVMAcceptor acceptor = new JVMAcceptor()
+ {
+ @Override
+ public JVMServerConnector handleAccept(JVMClientConnector client)
+ {
+ JVMServerConnector connector = new JVMServerConnector(client)
+ {
+ @Override
+ public InternalChannel inverseOpenChannel(short channelID, String protocolID, int protocolVersion)
+ {
+ throw new RuntimeException("Simulated problem"); //$NON-NLS-1$
+ }
+ };
+
+ connector.setName(client.getName());
+ connector.setConfig(getConfig());
+ connector.activate();
+ addConnector(connector);
+ return connector;
+ }
+ };
+
+ acceptor.setName(description);
+ return acceptor;
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ private static final class FakeTCPAcceptorFactory extends TCPAcceptorFactory
{
@Override
public TCPAcceptor create(String description)
@@ -108,7 +128,7 @@ public class Bugzilla_241463_Test extends AbstractTransportTest
return new TCPServerConnector(this)
{
@Override
- public InternalChannel inverseOpenChannel(short channelIndex, String protocolID)
+ public InternalChannel inverseOpenChannel(short channelID, String protocolID, int protocolVersion)
{
throw new RuntimeException("Simulated problem"); //$NON-NLS-1$
}
@@ -132,7 +152,6 @@ public class Bugzilla_241463_Test extends AbstractTransportTest
{
SSLAcceptor acceptor = new SSLAcceptor()
{
-
@Override
public void handleAccept(ITCPSelector selector, ServerSocketChannel serverSocketChannel)
{
@@ -146,11 +165,12 @@ public class Bugzilla_241463_Test extends AbstractTransportTest
SSLServerConnector connector = new SSLServerConnector(this)
{
@Override
- public InternalChannel inverseOpenChannel(short channelID, String protocolID)
+ public InternalChannel inverseOpenChannel(short channelID, String protocolID, int protocolVersion)
{
throw new RuntimeException("Simulated problem"); //$NON-NLS-1$
}
};
+
prepareConnector(connector);
connector.setSocketChannel(socketChannel);
connector.setSelector(selector);
@@ -177,7 +197,25 @@ public class Bugzilla_241463_Test extends AbstractTransportTest
/**
* @author Eike Stepper
*/
- public static final class TCP extends ChannelTest
+ public static final class JVM extends Bugzilla_241463_Test
+ {
+ @Override
+ protected boolean useJVMTransport()
+ {
+ return true;
+ }
+
+ @Override
+ protected boolean useSSLTransport()
+ {
+ return false;
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static final class TCP extends Bugzilla_241463_Test
{
@Override
protected boolean useJVMTransport()
@@ -195,7 +233,7 @@ public class Bugzilla_241463_Test extends AbstractTransportTest
/**
* @author Teerawat Chaiyakijpichet (No Magic Asia Ltd.)
*/
- public static final class SSL extends ChannelTest
+ public static final class SSL extends Bugzilla_241463_Test
{
@Override
protected boolean useJVMTransport()
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/bugzilla/Bugzilla_259086_Test.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/bugzilla/Bugzilla_259086_Test.java
new file mode 100644
index 0000000000..b842f0abd8
--- /dev/null
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/bugzilla/Bugzilla_259086_Test.java
@@ -0,0 +1,141 @@
+/*
+ * Copyright (c) 2004 - 2012 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.tests.bugzilla;
+
+import org.eclipse.net4j.Net4jUtil;
+import org.eclipse.net4j.connector.IConnector;
+import org.eclipse.net4j.jvm.JVMUtil;
+import org.eclipse.net4j.tcp.TCPUtil;
+import org.eclipse.net4j.tcp.ssl.SSLUtil;
+import org.eclipse.net4j.tests.AbstractTransportTest;
+import org.eclipse.net4j.tests.signal.TestSignalProtocol;
+import org.eclipse.net4j.util.container.IManagedContainer;
+import org.eclipse.net4j.util.container.ManagedContainer;
+
+/**
+ * @author Eike Stepper
+ */
+public class Bugzilla_259086_Test extends AbstractTransportTest
+{
+ private static final int SERVER_PROTOCOL_VERSION = 4711;
+
+ @Override
+ protected IManagedContainer createContainer()
+ {
+ IManagedContainer container = new ManagedContainer();
+ Net4jUtil.prepareContainer(container);
+ JVMUtil.prepareContainer(container);
+ TCPUtil.prepareContainer(container);
+ SSLUtil.prepareContainer(container);
+ container.registerFactory(new TestSignalProtocol.Factory(SERVER_PROTOCOL_VERSION));
+ return container;
+ }
+
+ public void testVersionMatch() throws Exception
+ {
+ startTransport();
+
+ IConnector connector = getConnector();
+ connector.setOpenChannelTimeout(2000L);
+
+ new TestSignalProtocol(connector, SERVER_PROTOCOL_VERSION);
+ }
+
+ public void testVersionMissing() throws Exception
+ {
+ startTransport();
+
+ IConnector connector = getConnector();
+ connector.setOpenChannelTimeout(2000L);
+
+ try
+ {
+ new TestSignalProtocol(connector);
+ fail("Exception expected"); //$NON-NLS-1$
+ }
+ catch (Exception expected)
+ {
+ expected.printStackTrace();
+ }
+ }
+
+ public void testVersionMismatch() throws Exception
+ {
+ startTransport();
+
+ IConnector connector = getConnector();
+ connector.setOpenChannelTimeout(2000L);
+
+ try
+ {
+ new TestSignalProtocol(connector, SERVER_PROTOCOL_VERSION - 1);
+ fail("Exception expected"); //$NON-NLS-1$
+ }
+ catch (Exception expected)
+ {
+ expected.printStackTrace();
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static final class JVM extends Bugzilla_259086_Test
+ {
+ @Override
+ protected boolean useJVMTransport()
+ {
+ return true;
+ }
+
+ @Override
+ protected boolean useSSLTransport()
+ {
+ return false;
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static final class TCP extends Bugzilla_259086_Test
+ {
+ @Override
+ protected boolean useJVMTransport()
+ {
+ return false;
+ }
+
+ @Override
+ protected boolean useSSLTransport()
+ {
+ return false;
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static final class SSL extends Bugzilla_259086_Test
+ {
+ @Override
+ protected boolean useJVMTransport()
+ {
+ return false;
+ }
+
+ @Override
+ protected boolean useSSLTransport()
+ {
+ return true;
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/TestSignalProtocol.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/TestSignalProtocol.java
index 88f2a1265d..f8f3ebb74c 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/TestSignalProtocol.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/TestSignalProtocol.java
@@ -11,6 +11,7 @@
package org.eclipse.net4j.tests.signal;
import org.eclipse.net4j.connector.IConnector;
+import org.eclipse.net4j.protocol.IProtocol2;
import org.eclipse.net4j.signal.SignalProtocol;
import org.eclipse.net4j.signal.SignalReactor;
import org.eclipse.net4j.util.factory.ProductCreationException;
@@ -41,6 +42,15 @@ public class TestSignalProtocol extends SignalProtocol<Object>
public static final String SIMULATED_EXCEPTION = "Simulated exception"; //$NON-NLS-1$
+ private int version = super.getVersion();
+
+ public TestSignalProtocol(IConnector connector, int version)
+ {
+ this();
+ this.version = version;
+ open(connector);
+ }
+
public TestSignalProtocol(IConnector connector)
{
this();
@@ -53,6 +63,17 @@ public class TestSignalProtocol extends SignalProtocol<Object>
}
@Override
+ public int getVersion()
+ {
+ return version;
+ }
+
+ public void setVersion(int version)
+ {
+ this.version = version;
+ }
+
+ @Override
protected SignalReactor createSignalReactor(short signalID)
{
switch (signalID)
@@ -107,6 +128,14 @@ public class TestSignalProtocol extends SignalProtocol<Object>
*/
public static class Factory extends ServerProtocolFactory
{
+ private int version = IProtocol2.UNSPECIFIED_VERSION;
+
+ public Factory(int version)
+ {
+ this();
+ this.version = version;
+ }
+
public Factory()
{
super(PROTOCOL_NAME);
@@ -114,7 +143,9 @@ public class TestSignalProtocol extends SignalProtocol<Object>
public TestSignalProtocol create(String description) throws ProductCreationException
{
- return new TestSignalProtocol();
+ TestSignalProtocol protocol = new TestSignalProtocol();
+ protocol.setVersion(version);
+ return protocol;
}
}
}
diff --git a/plugins/org.eclipse.net4j/META-INF/MANIFEST.MF b/plugins/org.eclipse.net4j/META-INF/MANIFEST.MF
index 743b1e2dbb..d48344c42a 100644
--- a/plugins/org.eclipse.net4j/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.net4j/META-INF/MANIFEST.MF
@@ -1,7 +1,7 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-SymbolicName: org.eclipse.net4j;singleton:=true
-Bundle-Version: 4.1.100.qualifier
+Bundle-Version: 4.2.0.qualifier
Bundle-Name: %pluginName
Bundle-Vendor: %providerName
Bundle-Localization: plugin
@@ -11,7 +11,7 @@ Bundle-RequiredExecutionEnvironment: J2SE-1.5
Bundle-ClassPath: .
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.4.0,4.0.0)";resolution:=optional,
org.eclipse.net4j.util;bundle-version="[3.0.0,4.0.0)";visibility:=reexport
-Export-Package: org.eclipse.internal.net4j;version="4.1.100";
+Export-Package: org.eclipse.internal.net4j;version="4.2.0";
x-friends:="org.eclipse.net4j.http.server,
org.eclipse.net4j.jvm,
org.eclipse.net4j.tcp,
@@ -20,7 +20,7 @@ Export-Package: org.eclipse.internal.net4j;version="4.1.100";
org.eclipse.net4j.http.tests,
org.eclipse.net4j.tests,
org.eclipse.net4j.defs",
- org.eclipse.internal.net4j.buffer;version="4.1.100";
+ org.eclipse.internal.net4j.buffer;version="4.2.0";
x-friends:="org.eclipse.net4j.http.server,
org.eclipse.net4j.jvm,
org.eclipse.net4j.tcp,
@@ -29,15 +29,15 @@ Export-Package: org.eclipse.internal.net4j;version="4.1.100";
org.eclipse.net4j.http.tests,
org.eclipse.net4j.tests,
org.eclipse.net4j.defs",
- org.eclipse.internal.net4j.bundle;version="4.1.100";x-internal:=true,
- org.eclipse.net4j;version="4.1.100",
- org.eclipse.net4j.acceptor;version="4.1.100",
- org.eclipse.net4j.buffer;version="4.1.100",
- org.eclipse.net4j.channel;version="4.1.100",
- org.eclipse.net4j.connector;version="4.1.100",
- org.eclipse.net4j.protocol;version="4.1.100",
- org.eclipse.net4j.signal;version="4.1.100",
- org.eclipse.net4j.signal.heartbeat;version="4.1.100",
- org.eclipse.net4j.signal.wrapping;version="4.1.100",
- org.eclipse.spi.net4j;version="4.1.100"
+ org.eclipse.internal.net4j.bundle;version="4.2.0";x-internal:=true,
+ org.eclipse.net4j;version="4.2.0",
+ org.eclipse.net4j.acceptor;version="4.2.0",
+ org.eclipse.net4j.buffer;version="4.2.0",
+ org.eclipse.net4j.channel;version="4.2.0",
+ org.eclipse.net4j.connector;version="4.2.0",
+ org.eclipse.net4j.protocol;version="4.2.0",
+ org.eclipse.net4j.signal;version="4.2.0",
+ org.eclipse.net4j.signal.heartbeat;version="4.2.0",
+ org.eclipse.net4j.signal.wrapping;version="4.2.0",
+ org.eclipse.spi.net4j;version="4.2.0"
Eclipse-BuddyPolicy: registered
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/BufferUtil.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/BufferUtil.java
index 22a9de5035..f4993d4960 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/BufferUtil.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/BufferUtil.java
@@ -4,12 +4,14 @@
* 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.internal.net4j.buffer;
+import org.eclipse.net4j.util.WrappedException;
+
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@@ -17,22 +19,32 @@ import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
+import java.nio.charset.Charset;
+import java.nio.charset.CharsetEncoder;
+import java.nio.charset.CoderResult;
/**
* @author Eike Stepper
*/
public final class BufferUtil
{
+ public static final String UTF8_CHAR_SET_NAME = "UTF-8"; //$NON-NLS-1$
+
+ private static final Charset CHARSET = Charset.forName(UTF8_CHAR_SET_NAME);
+
private static final byte FALSE = (byte)0;
private static final byte TRUE = (byte)1;
- public static final String UTF8_CHAR_SET_NAME = "UTF-8"; //$NON-NLS-1$
-
private BufferUtil()
{
}
+ /**
+ * @deprecated Use {@link #putString(ByteBuffer, String, boolean)}
+ */
+ @Deprecated
public static byte[] toUTF8(String str)
{
if (str == null)
@@ -40,24 +52,20 @@ public final class BufferUtil
return new byte[0];
}
- try
+ byte[] bytes = str.getBytes(CHARSET);
+ String test = new String(bytes, CHARSET);
+ if (!test.equals(str))
{
- byte[] bytes = str.getBytes(UTF8_CHAR_SET_NAME);
- String test = new String(bytes, UTF8_CHAR_SET_NAME);
- if (!str.equals(test))
- {
- throw new IllegalArgumentException("String not encodable: " + str); //$NON-NLS-1$
- }
-
- return bytes;
- }
- catch (UnsupportedEncodingException ex)
- {
- // This should really not happen
- throw new RuntimeException(ex);
+ throw new IllegalArgumentException("String not encodable: " + str); //$NON-NLS-1$
}
+
+ return bytes;
}
+ /**
+ * @deprecated Use {@link #getString(ByteBuffer)}
+ */
+ @Deprecated
public static String fromUTF8(byte[] bytes)
{
try
@@ -71,6 +79,15 @@ public final class BufferUtil
}
}
+ /**
+ * @deprecated Use {@link #putString(ByteBuffer, String, boolean)}
+ */
+ @Deprecated
+ public static void putUTF8(ByteBuffer byteBuffer, String str)
+ {
+ putString(byteBuffer, str, false);
+ }
+
public static void putObject(ByteBuffer byteBuffer, Object object) throws IOException
{
if (object != null)
@@ -105,8 +122,9 @@ public final class BufferUtil
public static void putByteArray(ByteBuffer byteBuffer, byte[] array)
{
- byteBuffer.putShort((short)array.length);
- if (array.length != 0)
+ short length = array == null ? 0 : (short)array.length;
+ byteBuffer.putShort(length); // BYTE_ARRAY_PREFIX
+ if (length != 0)
{
byteBuffer.put(array);
}
@@ -124,14 +142,81 @@ public final class BufferUtil
return array;
}
- public static void putUTF8(ByteBuffer byteBuffer, String str)
+ public static void putString(ByteBuffer byteBuffer, String str, boolean bestEffort)
{
- byte[] bytes = BufferUtil.toUTF8(str);
- if (bytes.length > byteBuffer.remaining())
+ int sizePosition = byteBuffer.position();
+ byteBuffer.putShort((short)-1); // Placeholder for size
+
+ if (str != null)
{
- throw new IllegalArgumentException("String too long: " + str); //$NON-NLS-1$
+ CharsetEncoder encoder = CHARSET.newEncoder();
+ CharBuffer input = CharBuffer.wrap(str);
+
+ int start = byteBuffer.position();
+ int max = -1;
+
+ for (;;)
+ {
+ CoderResult result = encoder.encode(input, byteBuffer, true);
+ if (result.isError())
+ {
+ if (result.isOverflow() && bestEffort)
+ {
+ if (max == -1)
+ {
+ max = (int)(byteBuffer.remaining() / encoder.maxBytesPerChar());
+ }
+ else
+ {
+ --max;
+ }
+
+ if (max > 0)
+ {
+ str = str.substring(0, max);
+ byteBuffer.position(start);
+ continue;
+ }
+ }
+
+ try
+ {
+ result.throwException();
+ }
+ catch (Exception ex)
+ {
+ throw WrappedException.wrap(ex);
+ }
+ }
+
+ break;
+ }
+
+ int end = byteBuffer.position();
+ short size = (short)Math.abs(end - start);
+
+ byteBuffer.position(sizePosition);
+ byteBuffer.putShort(size);
+ byteBuffer.position(end);
}
+ }
+
+ public static String getString(ByteBuffer byteBuffer)
+ {
+ short size = byteBuffer.getShort();
+ if (size == -1)
+ {
+ return null;
+ }
+
+ if (size == 0)
+ {
+ return "";
+ }
+
+ byte[] bytes = new byte[size];
+ byteBuffer.get(bytes);
- putByteArray(byteBuffer, bytes);
+ return new String(bytes, CHARSET);
}
}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/Net4jUtil.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/Net4jUtil.java
index 23ed503f45..78d62f525e 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/Net4jUtil.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/Net4jUtil.java
@@ -15,6 +15,8 @@ import org.eclipse.net4j.buffer.IBufferPool;
import org.eclipse.net4j.buffer.IBufferProvider;
import org.eclipse.net4j.connector.ConnectorException;
import org.eclipse.net4j.connector.IConnector;
+import org.eclipse.net4j.protocol.IProtocol;
+import org.eclipse.net4j.protocol.IProtocol2;
import org.eclipse.net4j.signal.heartbeat.HeartBeatProtocol;
import org.eclipse.net4j.util.StringUtil;
import org.eclipse.net4j.util.concurrent.ExecutorServiceFactory;
@@ -34,7 +36,7 @@ import java.util.concurrent.ExecutorService;
/**
* A utility class with various static factory and convenience methods.
- *
+ *
* @author Eike Stepper
*/
public final class Net4jUtil
@@ -178,4 +180,30 @@ public final class Net4jUtil
return new TransportConfig(lifecycle, source.getReceiveExecutor(), source.getBufferProvider(),
source.getProtocolProvider(), source.getNegotiator());
}
+
+ /**
+ * @since 4.2
+ */
+ public static String getProtocolID(IProtocol<?> protocol)
+ {
+ if (protocol != null)
+ {
+ return protocol.getType();
+ }
+
+ return null;
+ }
+
+ /**
+ * @since 4.2
+ */
+ public static int getProtocolVersion(IProtocol<?> protocol)
+ {
+ if (protocol instanceof IProtocol2)
+ {
+ return ((IProtocol2<?>)protocol).getVersion();
+ }
+
+ return IProtocol2.UNSPECIFIED_VERSION;
+ }
}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/protocol/IProtocol2.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/protocol/IProtocol2.java
new file mode 100644
index 0000000000..dd3cb4fba6
--- /dev/null
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/protocol/IProtocol2.java
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2004 - 2012 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.protocol;
+
+/**
+ * A {@link #getVersion() versioned} {@link IProtocol protocol}.
+ *
+ * @author Eike Stepper
+ * @since 4.2
+ */
+public interface IProtocol2<INFRA_STRUCTURE> extends IProtocol<INFRA_STRUCTURE>
+{
+ public static final int UNSPECIFIED_VERSION = 0;
+
+ public int getVersion();
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/protocol/ProtocolVersionException.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/protocol/ProtocolVersionException.java
new file mode 100644
index 0000000000..bd2e759c9f
--- /dev/null
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/protocol/ProtocolVersionException.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2004 - 2012 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.protocol;
+
+import org.eclipse.net4j.Net4jUtil;
+
+/**
+ * An exception that indicates mismatch between the versions of two protocol peer implementations.
+ *
+ * @author Eike Stepper
+ * @since 4.2
+ */
+public class ProtocolVersionException extends IllegalStateException
+{
+ private static final long serialVersionUID = 1L;
+
+ public ProtocolVersionException()
+ {
+ }
+
+ public ProtocolVersionException(String s)
+ {
+ super(s);
+ }
+
+ public ProtocolVersionException(Throwable cause)
+ {
+ super(cause);
+ }
+
+ public ProtocolVersionException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+
+ public static void checkVersion(IProtocol<?> protocol, int expectedVersion) throws ProtocolVersionException
+ {
+ int actualVersion = Net4jUtil.getProtocolVersion(protocol);
+ if (actualVersion != expectedVersion)
+ {
+ throw new ProtocolVersionException("Protocol version " + actualVersion + " does not match expected version "
+ + expectedVersion);
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/ChannelMultiplexer.java b/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/ChannelMultiplexer.java
index b3f0341f55..8631ab70a1 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/ChannelMultiplexer.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/ChannelMultiplexer.java
@@ -17,7 +17,9 @@ import org.eclipse.net4j.channel.ChannelException;
import org.eclipse.net4j.channel.IChannel;
import org.eclipse.net4j.channel.IChannelMultiplexer;
import org.eclipse.net4j.protocol.IProtocol;
+import org.eclipse.net4j.protocol.IProtocol2;
import org.eclipse.net4j.protocol.IProtocolProvider;
+import org.eclipse.net4j.protocol.ProtocolVersionException;
import org.eclipse.net4j.util.ReflectUtil.ExcludeFromDump;
import org.eclipse.net4j.util.StringUtil;
import org.eclipse.net4j.util.concurrent.TimeoutRuntimeException;
@@ -173,9 +175,22 @@ public abstract class ChannelMultiplexer extends Container<IChannel> implements
return channel;
}
+ /**
+ * @deprecated Use {@link #inverseOpenChannel(short, String, int)}.
+ */
+ @Deprecated
public InternalChannel inverseOpenChannel(short channelID, String protocolID)
{
+ return inverseOpenChannel(channelID, protocolID, IProtocol2.UNSPECIFIED_VERSION);
+ }
+
+ /**
+ * @since 4.2
+ */
+ public InternalChannel inverseOpenChannel(short channelID, String protocolID, int protocolVersion)
+ {
IProtocol<?> protocol = createProtocol(protocolID, null);
+ ProtocolVersionException.checkVersion(protocol, protocolVersion);
InternalChannel channel = createChannel();
initChannel(channel, protocol);
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/Protocol.java b/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/Protocol.java
index 46fde5dd08..b2b5740446 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/Protocol.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/Protocol.java
@@ -12,7 +12,7 @@ package org.eclipse.spi.net4j;
import org.eclipse.net4j.buffer.IBufferProvider;
import org.eclipse.net4j.channel.IChannel;
-import org.eclipse.net4j.protocol.IProtocol;
+import org.eclipse.net4j.protocol.IProtocol2;
import org.eclipse.net4j.util.ReflectUtil.ExcludeFromDump;
import org.eclipse.net4j.util.event.IListener;
import org.eclipse.net4j.util.lifecycle.ILifecycle;
@@ -27,7 +27,7 @@ import java.util.concurrent.ExecutorService;
* @author Eike Stepper
* @since 2.0
*/
-public abstract class Protocol<INFRA_STRUCTURE> extends Lifecycle implements IProtocol<INFRA_STRUCTURE>
+public abstract class Protocol<INFRA_STRUCTURE> extends Lifecycle implements IProtocol2<INFRA_STRUCTURE>
{
private String type;
@@ -61,6 +61,14 @@ public abstract class Protocol<INFRA_STRUCTURE> extends Lifecycle implements IPr
return type;
}
+ /**
+ * @since 4.2
+ */
+ public int getVersion()
+ {
+ return UNSPECIFIED_VERSION;
+ }
+
public ExecutorService getExecutorService()
{
return executorService;

Back to the top