summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-03-23 02:51:34 (EDT)
committerEike Stepper2007-03-23 02:51:34 (EDT)
commit2f54cce679cfd24d270236389902a3adf46a7379 (patch)
tree1d7848cfe23f0f8ce92731b3b180462dc92f13ff
parent3eb59e513278b894153bf601911e788363a39575 (diff)
downloadcdo-2f54cce679cfd24d270236389902a3adf46a7379.zip
cdo-2f54cce679cfd24d270236389902a3adf46a7379.tar.gz
cdo-2f54cce679cfd24d270236389902a3adf46a7379.tar.bz2
*** empty log message ***
-rw-r--r--plugins/org.eclipse.net4j.jvm/src/org/eclipse/net4j/internal/jvm/JVMConnector.java5
-rw-r--r--plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/ControlChannel.java6
-rw-r--r--plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPConnector.java5
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/TestSignalProtocol.java4
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/Connector.java24
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/util/lifecycle/Lifecycle.java8
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/SignalProtocol.java14
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/IConnector.java2
8 files changed, 53 insertions, 15 deletions
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 2a70382..c772734 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
@@ -13,6 +13,7 @@ package org.eclipse.net4j.internal.jvm;
import org.eclipse.net4j.transport.ConnectorException;
import org.eclipse.net4j.transport.IBuffer;
import org.eclipse.net4j.transport.IChannel;
+import org.eclipse.net4j.transport.IProtocol;
import org.eclipse.internal.net4j.transport.Channel;
import org.eclipse.internal.net4j.transport.Connector;
@@ -55,11 +56,11 @@ public abstract class JVMConnector extends Connector
}
@Override
- protected void registerChannelWithPeer(short channelIndex, String protocolID) throws ConnectorException
+ protected void registerChannelWithPeer(short channelIndex, IProtocol protocol) throws ConnectorException
{
try
{
- Channel channel = getPeer().createChannel(channelIndex, protocolID);
+ Channel channel = getPeer().createChannel(channelIndex, protocol);
if (channel == null)
{
throw new ConnectorException("Failed to register channel with peer"); //$NON-NLS-1$
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 f6ebc36..8a8769b 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
@@ -11,6 +11,7 @@
package org.eclipse.net4j.internal.tcp;
import org.eclipse.net4j.transport.IBuffer;
+import org.eclipse.net4j.transport.IProtocol;
import org.eclipse.net4j.util.concurrent.ISynchronizer;
import org.eclipse.net4j.util.om.trace.ContextTracer;
@@ -57,7 +58,7 @@ public final class ControlChannel extends Channel
return true;
}
- public boolean registerChannel(short channelIndex, String protocolID)
+ public boolean registerChannel(short channelIndex, IProtocol protocol)
{
assertValidChannelIndex(channelIndex);
ISynchronizer<Boolean> registration = registrations.correlate(channelIndex);
@@ -66,7 +67,7 @@ public final class ControlChannel extends Channel
ByteBuffer byteBuffer = buffer.startPutting(CONTROL_CHANNEL_ID);
byteBuffer.put(OPCODE_REGISTRATION);
byteBuffer.putShort(channelIndex);
- BufferUtil.putUTF8(byteBuffer, protocolID);
+ BufferUtil.putUTF8(byteBuffer, protocol.getType());
handleBuffer(buffer);
return registration.get(REGISTRATION_TIMEOUT);
@@ -83,6 +84,7 @@ public final class ControlChannel extends Channel
handleBuffer(buffer);
}
+ @Override
public void handleBufferFromMultiplexer(IBuffer buffer)
{
try
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 fb3cd2d..df9e35c 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
@@ -17,6 +17,7 @@ import org.eclipse.net4j.transport.ConnectorException;
import org.eclipse.net4j.transport.ConnectorState;
import org.eclipse.net4j.transport.IBuffer;
import org.eclipse.net4j.transport.IChannel;
+import org.eclipse.net4j.transport.IProtocol;
import org.eclipse.net4j.util.om.trace.ContextTracer;
import org.eclipse.internal.net4j.bundle.Net4j;
@@ -250,11 +251,11 @@ public abstract class TCPConnector extends Connector implements ITCPConnector, I
}
@Override
- protected void registerChannelWithPeer(short channelIndex, String protocolID) throws ConnectorException
+ protected void registerChannelWithPeer(short channelIndex, IProtocol protocol) throws ConnectorException
{
try
{
- if (!controlChannel.registerChannel(channelIndex, protocolID))
+ if (!controlChannel.registerChannel(channelIndex, protocol))
{
throw new ConnectorException("Failed to register channel with peer"); //$NON-NLS-1$
}
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 8749840..88d1e56 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
@@ -34,7 +34,7 @@ public class TestSignalProtocol extends SignalProtocol
}
@Override
- protected SignalReactor createSignalReactor(short signalID)
+ protected SignalReactor doCreateSignalReactor(short signalID)
{
switch (signalID)
{
@@ -44,6 +44,6 @@ public class TestSignalProtocol extends SignalProtocol
return new Indication2();
}
- throw new IllegalArgumentException("Invalid signalID " + signalID);
+ return null;
}
}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/Connector.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/Connector.java
index 5294f8c..ca913e2 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/Connector.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/Connector.java
@@ -322,15 +322,21 @@ public abstract class Connector extends Lifecycle implements IConnector
public IChannel openChannel() throws ConnectorException
{
- return openChannel(null);
+ return openChannel((IProtocol)null);
}
public IChannel openChannel(String protocolID) throws ConnectorException
{
+ IProtocol protocol = createProtocol(protocolID);
+ return openChannel(protocol);
+ }
+
+ public IChannel openChannel(IProtocol protocol) throws ConnectorException
+ {
waitForConnection(Long.MAX_VALUE);
short channelIndex = findFreeChannelIndex();
- Channel channel = createChannel(channelIndex, protocolID);
- registerChannelWithPeer(channelIndex, protocolID);
+ Channel channel = createChannel(channelIndex, protocol);
+ registerChannelWithPeer(channelIndex, protocol);
try
{
@@ -350,14 +356,20 @@ public abstract class Connector extends Lifecycle implements IConnector
public Channel createChannel(short channelIndex, String protocolID)
{
- Channel channel = new Channel(receiveExecutor);
IProtocol protocol = createProtocol(protocolID);
+ return createChannel(channelIndex, protocol);
+ }
+
+ public Channel createChannel(short channelIndex, IProtocol protocol)
+ {
+ Channel channel = new Channel(receiveExecutor);
if (protocol != null)
{
protocol.setChannel(channel);
+ LifecycleUtil.activate(protocol);
if (TRACER.isEnabled())
{
- TRACER.format("Opening channel {0} with protocol {1}", channelIndex, protocolID); //$NON-NLS-1$
+ TRACER.format("Opening channel {0} with protocol {1}", channelIndex, protocol.getType()); //$NON-NLS-1$
}
}
else
@@ -538,7 +550,7 @@ public abstract class Connector extends Lifecycle implements IConnector
super.doDeactivate();
}
- protected abstract void registerChannelWithPeer(short channelIndex, String protocolID) throws ConnectorException;
+ protected abstract void registerChannelWithPeer(short channelIndex, IProtocol protocol) throws ConnectorException;
/**
* @author Eike Stepper
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/util/lifecycle/Lifecycle.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/util/lifecycle/Lifecycle.java
index fac0ed4..8cdd862 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/util/lifecycle/Lifecycle.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/util/lifecycle/Lifecycle.java
@@ -114,6 +114,14 @@ public class Lifecycle extends Notifier implements ILifecycle
}
}
+ protected void checkActive()
+ {
+ if (!active)
+ {
+ throw new IllegalStateException("Not active: " + this);
+ }
+ }
+
protected void doBeforeActivate() throws Exception
{
}
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 0bb9f3a..9fa8d58 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
@@ -134,7 +134,19 @@ public abstract class SignalProtocol extends Protocol
return "SignalProtocol[" + getType() + ", " + getChannel() + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
- protected abstract SignalReactor createSignalReactor(short signalID);
+ protected final SignalReactor createSignalReactor(short signalID)
+ {
+ checkActive();
+ SignalReactor signal = doCreateSignalReactor(signalID);
+ if (signal == null)
+ {
+ throw new IllegalArgumentException("Invalid signalID " + signalID);
+ }
+
+ return signal;
+ }
+
+ protected abstract SignalReactor doCreateSignalReactor(short signalID);
void startSignal(SignalActor signalActor, long timeout) throws Exception
{
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/IConnector.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/IConnector.java
index bc9049d..2a77ff9 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/IConnector.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/IConnector.java
@@ -102,4 +102,6 @@ public interface IConnector extends IContainer<IChannel>
* @see #openChannel()
*/
public IChannel openChannel(String protocolID) throws ConnectorException;
+
+ public IChannel openChannel(IProtocol protocol) throws ConnectorException;
}