summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-10-10 02:30:32 (EDT)
committerEike Stepper2007-10-10 02:30:32 (EDT)
commitddca7620af9ed7eeefc0cddffe7b25224e75f72f (patch)
tree944d8acaa4edc08c8c78042bf986a2f9846fbaa7
parentc18b3bf7f4e67c9115eb55f84b932e48a6496b00 (diff)
downloadcdo-ddca7620af9ed7eeefc0cddffe7b25224e75f72f.zip
cdo-ddca7620af9ed7eeefc0cddffe7b25224e75f72f.tar.gz
cdo-ddca7620af9ed7eeefc0cddffe7b25224e75f72f.tar.bz2
[205877] NoConnectionPendingException in ConnectorTest
https://bugs.eclipse.org/bugs/show_bug.cgi?id=205877
-rw-r--r--plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPClientConnector.java20
-rw-r--r--plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPConnector.java10
-rw-r--r--plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPSelector.java86
-rw-r--r--plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/tcp/ITCPSelector.java8
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/ConnectorTest.java15
5 files changed, 80 insertions, 59 deletions
diff --git a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPClientConnector.java b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPClientConnector.java
index d1ad989..17ebd14 100644
--- a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPClientConnector.java
+++ b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPClientConnector.java
@@ -16,6 +16,7 @@ import org.eclipse.net4j.internal.tcp.bundle.OM;
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
+import java.nio.channels.SelectionKey;
import java.nio.channels.SocketChannel;
import java.text.MessageFormat;
@@ -84,11 +85,20 @@ public class TCPClientConnector extends TCPConnector
}
@Override
- protected void doActivate() throws Exception
+ public void handleRegistration(SelectionKey selectionKey)
{
- super.doActivate();
- InetAddress addr = InetAddress.getByName(getHost());
- InetSocketAddress sAddr = new InetSocketAddress(addr, getPort());
- getSocketChannel().connect(sAddr);
+ super.handleRegistration(selectionKey);
+
+ try
+ {
+ InetAddress addr = InetAddress.getByName(getHost());
+ InetSocketAddress sAddr = new InetSocketAddress(addr, getPort());
+ getSocketChannel().connect(sAddr);
+ }
+ catch (Exception ex)
+ {
+ OM.LOG.error(ex);
+ deactivate();
+ }
}
}
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 e937f7a..3c3ec31 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
@@ -117,7 +117,7 @@ public abstract class TCPConnector extends Connector implements ITCPConnector, I
public void multiplexBuffer(IChannel channel)
{
checkSelectionKey();
- selector.setWriteInterest(selectionKey, true);
+ selector.setWriteInterest(selectionKey, isClient(), true);
}
public void handleRegistration(SelectionKey selectionKey)
@@ -135,8 +135,8 @@ public abstract class TCPConnector extends Connector implements ITCPConnector, I
{
if (channel.finishConnect())
{
- selector.setConnectInterest(selectionKey, false);
- selector.setReadInterest(selectionKey, true);
+ selector.setConnectInterest(selectionKey, true, false);
+ selector.setReadInterest(selectionKey, true, true);
leaveConnecting();
}
}
@@ -236,7 +236,7 @@ public abstract class TCPConnector extends Connector implements ITCPConnector, I
if (!moreToWrite)
{
checkSelectionKey();
- selector.setWriteInterest(selectionKey, false);
+ selector.setWriteInterest(selectionKey, isClient(), false);
}
}
catch (NullPointerException ignore)
@@ -358,7 +358,7 @@ public abstract class TCPConnector extends Connector implements ITCPConnector, I
super.doActivate();
controlChannel = new ControlChannel(getNextChannelID(), this);
controlChannel.activate();
- selector.register(socketChannel, this, isClient());
+ selector.register(socketChannel, isClient(), this);
}
@Override
diff --git a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPSelector.java b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPSelector.java
index 68d5435..5e7e6ce 100644
--- a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPSelector.java
+++ b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPSelector.java
@@ -40,7 +40,9 @@ public class TCPSelector extends Lifecycle implements ITCPSelector, Runnable
private Selector selector;
- private transient Queue<Runnable> pendingOperations = new ConcurrentLinkedQueue<Runnable>();
+ private transient Queue<Runnable> clientOperations = new ConcurrentLinkedQueue<Runnable>();
+
+ private transient Queue<Runnable> serverOperations = new ConcurrentLinkedQueue<Runnable>();
private transient Thread thread;
@@ -53,11 +55,11 @@ public class TCPSelector extends Lifecycle implements ITCPSelector, Runnable
public void register(final ServerSocketChannel channel, final Passive listener)
{
assertValidListener(listener);
- invokeAsync(new Runnable()
+ order(false, new Runnable()
{
public void run()
{
- doRegister(channel, listener);
+ registerAcceptor(channel, listener);
}
@Override
@@ -68,14 +70,14 @@ public class TCPSelector extends Lifecycle implements ITCPSelector, Runnable
});
}
- public void register(final SocketChannel channel, final Active listener, final boolean connect)
+ public void register(final SocketChannel channel, final boolean client, final Active listener)
{
assertValidListener(listener);
- invokeAsync(new Runnable()
+ order(client, new Runnable()
{
public void run()
{
- doRegister(channel, listener, connect);
+ registerConnector(channel, listener, client);
}
@Override
@@ -86,53 +88,53 @@ public class TCPSelector extends Lifecycle implements ITCPSelector, Runnable
});
}
- public void setConnectInterest(final SelectionKey selectionKey, final boolean connect)
+ public void setConnectInterest(final SelectionKey selectionKey, boolean client, final boolean on)
{
- invokeAsync(new Runnable()
+ order(client, new Runnable()
{
public void run()
{
- SelectorUtil.setConnectInterest(selectionKey, connect);
+ SelectorUtil.setConnectInterest(selectionKey, on);
}
@Override
public String toString()
{
- return "INTEREST CONNECT " + selectionKey.channel() + " = " + connect;
+ return "INTEREST CONNECT " + selectionKey.channel() + " = " + on;
}
});
}
- public void setReadInterest(final SelectionKey selectionKey, final boolean read)
+ public void setReadInterest(final SelectionKey selectionKey, boolean client, final boolean on)
{
- invokeAsync(new Runnable()
+ order(client, new Runnable()
{
public void run()
{
- SelectorUtil.setReadInterest(selectionKey, read);
+ SelectorUtil.setReadInterest(selectionKey, on);
}
@Override
public String toString()
{
- return "INTEREST READ " + selectionKey.channel() + " = " + read;
+ return "INTEREST READ " + selectionKey.channel() + " = " + on;
}
});
}
- public void setWriteInterest(final SelectionKey selectionKey, final boolean write)
+ public void setWriteInterest(final SelectionKey selectionKey, boolean client, final boolean on)
{
- invokeAsync(new Runnable()
+ order(client, new Runnable()
{
public void run()
{
- SelectorUtil.setWriteInterest(selectionKey, write);
+ SelectorUtil.setWriteInterest(selectionKey, on);
}
@Override
public String toString()
{
- return "INTEREST WRITE " + selectionKey.channel() + " = " + write;
+ return "INTEREST WRITE " + selectionKey.channel() + " = " + on;
}
});
@@ -140,22 +142,12 @@ public class TCPSelector extends Lifecycle implements ITCPSelector, Runnable
public void run()
{
- selector.wakeup();
while (running && !Thread.interrupted())
{
try
{
- Runnable operation;
- while ((operation = pendingOperations.poll()) != null)
- {
- if (TRACER.isEnabled())
- {
- TRACER.trace("Executing operation " + operation);
- }
-
- operation.run();
- }
-
+ execute(clientOperations);
+ execute(serverOperations);
if (selector != null && selector.select() > 0)
{
Iterator<SelectionKey> it = selector.selectedKeys().iterator();
@@ -331,21 +323,43 @@ public class TCPSelector extends Lifecycle implements ITCPSelector, Runnable
}
}
- private void invokeAsync(final Runnable operation)
+ private void order(boolean client, Runnable operation)
{
if (TRACER.isEnabled())
{
- TRACER.trace("Pending operation " + operation);
+ TRACER.trace("Ordering operation " + operation);
+ }
+
+ if (client)
+ {
+ clientOperations.add(operation);
+ }
+ else
+ {
+ serverOperations.add(operation);
}
- pendingOperations.add(operation);
if (selector != null)
{
selector.wakeup();
}
}
- private void doRegister(final ServerSocketChannel channel, final ITCPSelectorListener.Passive listener)
+ private void execute(Queue<Runnable> operations)
+ {
+ Runnable operation;
+ while ((operation = operations.poll()) != null)
+ {
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace("Executing operation " + operation);
+ }
+
+ operation.run();
+ }
+ }
+
+ private void registerAcceptor(final ServerSocketChannel channel, final ITCPSelectorListener.Passive listener)
{
if (TRACER.isEnabled())
{
@@ -363,7 +377,7 @@ public class TCPSelector extends Lifecycle implements ITCPSelector, Runnable
}
}
- private void doRegister(final SocketChannel channel, final ITCPSelectorListener.Active listener, boolean connect)
+ private void registerConnector(final SocketChannel channel, final ITCPSelectorListener.Active listener, boolean client)
{
if (TRACER.isEnabled())
{
@@ -378,7 +392,7 @@ public class TCPSelector extends Lifecycle implements ITCPSelector, Runnable
// interest |= SelectionKey.OP_CONNECT;
// }
- int interest = connect ? SelectionKey.OP_CONNECT : SelectionKey.OP_READ;
+ int interest = client ? SelectionKey.OP_CONNECT : SelectionKey.OP_READ;
SelectionKey selectionKey = channel.register(selector, interest, listener);
listener.handleRegistration(selectionKey);
}
diff --git a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/tcp/ITCPSelector.java b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/tcp/ITCPSelector.java
index 0a8d263..7aa0a3e 100644
--- a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/tcp/ITCPSelector.java
+++ b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/tcp/ITCPSelector.java
@@ -24,11 +24,11 @@ public interface ITCPSelector
{
public void register(ServerSocketChannel channel, Passive listener);
- public void register(SocketChannel channel, Active listener, boolean connect);
+ public void register(SocketChannel channel, boolean client, Active listener);
- public void setConnectInterest(SelectionKey selectionKey, boolean connect);
+ public void setConnectInterest(SelectionKey selectionKey, boolean client, boolean on);
- public void setReadInterest(SelectionKey selectionKey, boolean read);
+ public void setReadInterest(SelectionKey selectionKey, boolean client, boolean on);
- public void setWriteInterest(SelectionKey selectionKey, boolean write);
+ public void setWriteInterest(SelectionKey selectionKey, boolean client, boolean on);
}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/ConnectorTest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/ConnectorTest.java
index 0981dd4..8ddcecd 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/ConnectorTest.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/ConnectorTest.java
@@ -71,25 +71,22 @@ public class ConnectorTest extends AbstractOMTest
LifecycleUtil.deactivate(responseNegotiator);
LifecycleUtil.deactivate(credentialsProvider);
LifecycleUtil.deactivate(connector);
+ responseNegotiator = null;
+ credentialsProvider = null;
+ connector = null;
LifecycleUtil.deactivate(challengeNegotiator);
LifecycleUtil.deactivate(userManager);
LifecycleUtil.deactivate(randomizer);
LifecycleUtil.deactivate(acceptor);
-
- LifecycleUtil.deactivate(selector);
- LifecycleUtil.deactivate(bufferPool);
- LifecycleUtil.deactivate(threadPool);
-
- responseNegotiator = null;
- credentialsProvider = null;
- connector = null;
-
challengeNegotiator = null;
userManager = null;
randomizer = null;
acceptor = null;
+ LifecycleUtil.deactivate(selector);
+ LifecycleUtil.deactivate(bufferPool);
+ LifecycleUtil.deactivate(threadPool);
selector = null;
bufferPool = null;
threadPool = null;