summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-10-10 03:02:20 (EDT)
committerEike Stepper2007-10-10 03:02:20 (EDT)
commit31888087817220d210d69f065908747a1099f530 (patch)
tree3103230f6c9fbdc4a8c2994e1d85f15cf6ad037f
parentddca7620af9ed7eeefc0cddffe7b25224e75f72f (diff)
downloadcdo-31888087817220d210d69f065908747a1099f530.zip
cdo-31888087817220d210d69f065908747a1099f530.tar.gz
cdo-31888087817220d210d69f065908747a1099f530.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/SelectorUtil.java3
-rw-r--r--plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPAcceptor.java69
-rw-r--r--plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPSelector.java11
-rw-r--r--plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPServerConnector.java6
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/ConnectorTest.java7
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/Connector.java6
6 files changed, 52 insertions, 50 deletions
diff --git a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/SelectorUtil.java b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/SelectorUtil.java
index 7da878e..cd233fa 100644
--- a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/SelectorUtil.java
+++ b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/SelectorUtil.java
@@ -78,7 +78,8 @@ public final class SelectorUtil
if (TRACER.isEnabled())
{
TRACER.trace("Setting interest " //$NON-NLS-1$
- + formatInterestOps(newOps) + " (was " + formatInterestOps(oldOps).toLowerCase() + ")"); //$NON-NLS-1$ //$NON-NLS-2$
+ + formatInterestOps(newOps)
+ + (oldOps == 0 ? "" : " (was " + formatInterestOps(oldOps).toLowerCase() + ")")); //$NON-NLS-1$ //$NON-NLS-2$
}
selectionKey.interestOps(newOps);
diff --git a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPAcceptor.java b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPAcceptor.java
index 637c680..7afa077 100644
--- a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPAcceptor.java
+++ b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPAcceptor.java
@@ -122,9 +122,45 @@ public class TCPAcceptor extends Acceptor implements ITCPAcceptor, ITCPSelectorL
public void handleRegistration(SelectionKey selectionKey)
{
this.selectionKey = selectionKey;
- if (startSynchronously)
+
+ try
{
- startLatch.countDown();
+ InetSocketAddress addr = null;
+ if (address != null)
+ {
+ addr = new InetSocketAddress(InetAddress.getByName(address), port);
+ }
+
+ ServerSocket socket = serverSocketChannel.socket();
+ socket.bind(addr);
+
+ if (address == null)
+ {
+ address = socket.getInetAddress().toString();
+ if (address.startsWith("/"))
+ {
+ address = address.substring(1);
+ }
+
+ int colon = address.indexOf(':');
+ if (colon != -1)
+ {
+ port = Integer.parseInt(address.substring(colon + 1));
+ address = address.substring(0, colon);
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ OM.LOG.error(ex);
+ deactivate();
+ }
+ finally
+ {
+ if (startLatch != null)
+ {
+ startLatch.countDown();
+ }
}
}
@@ -198,35 +234,10 @@ public class TCPAcceptor extends Acceptor implements ITCPAcceptor, ITCPSelectorL
protected void doActivate() throws Exception
{
super.doActivate();
- InetSocketAddress addr = null;
- if (address != null)
- {
- addr = new InetSocketAddress(InetAddress.getByName(address), port);
- }
-
serverSocketChannel = ServerSocketChannel.open();
serverSocketChannel.configureBlocking(false);
-
- ServerSocket socket = serverSocketChannel.socket();
- socket.bind(addr);
-
- if (address == null)
- {
- address = socket.getInetAddress().toString();
- if (address.startsWith("/"))
- {
- address = address.substring(1);
- }
-
- int colon = address.indexOf(':');
- if (colon != -1)
- {
- port = Integer.parseInt(address.substring(colon + 1));
- address = address.substring(0, colon);
- }
- }
-
selector.register(serverSocketChannel, this);
+
if (startSynchronously)
{
if (!startLatch.await(synchronousStartTimeout, TimeUnit.MILLISECONDS))
@@ -235,8 +246,6 @@ public class TCPAcceptor extends Acceptor implements ITCPAcceptor, ITCPSelectorL
IOUtil.closeSilent(serverSocketChannel);
throw new IOException("Registration with selector timed out after " + synchronousStartTimeout + " millis");
}
-
- startLatch = null;
}
}
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 5e7e6ce..4c98995 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
@@ -146,8 +146,8 @@ public class TCPSelector extends Lifecycle implements ITCPSelector, Runnable
{
try
{
- execute(clientOperations);
- execute(serverOperations);
+ execute(true);
+ execute(false);
if (selector != null && selector.select() > 0)
{
Iterator<SelectionKey> it = selector.selectedKeys().iterator();
@@ -327,7 +327,7 @@ public class TCPSelector extends Lifecycle implements ITCPSelector, Runnable
{
if (TRACER.isEnabled())
{
- TRACER.trace("Ordering operation " + operation);
+ TRACER.format("Ordering {0} operation {1}", client, operation);
}
if (client)
@@ -345,14 +345,15 @@ public class TCPSelector extends Lifecycle implements ITCPSelector, Runnable
}
}
- private void execute(Queue<Runnable> operations)
+ private void execute(boolean client)
{
Runnable operation;
+ Queue<Runnable> operations = client ? clientOperations : serverOperations;
while ((operation = operations.poll()) != null)
{
if (TRACER.isEnabled())
{
- TRACER.trace("Executing operation " + operation);
+ TRACER.format("Ordering {0} operation {1}", client, operation);
}
operation.run();
diff --git a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPServerConnector.java b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPServerConnector.java
index 53348c3..3e7b0d3 100644
--- a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPServerConnector.java
+++ b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPServerConnector.java
@@ -74,10 +74,4 @@ public class TCPServerConnector extends TCPConnector
return MessageFormat.format("ServerTCPConnector[{3}@{0}:{1}]", getHost(), getPort(), getUserID()); //$NON-NLS-1$
}
}
-
- @Override
- protected void doDeactivate() throws Exception
- {
- super.doDeactivate();
- }
}
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 8ddcecd..f654978 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
@@ -35,7 +35,7 @@ import java.util.concurrent.Executors;
*/
public class ConnectorTest extends AbstractOMTest
{
- private static final int TIMEOUT = 2000;
+ private static final int TIMEOUT = 10000;
private static final String USER_ID = "stepper";
@@ -96,6 +96,7 @@ public class ConnectorTest extends AbstractOMTest
public void testDeferredActivation() throws Exception
{
+ final long DELAY = 1000L;
threadPool = Executors.newCachedThreadPool();
LifecycleUtil.activate(threadPool);
@@ -110,7 +111,7 @@ public class ConnectorTest extends AbstractOMTest
@Override
protected TCPServerConnector createConnector(SocketChannel socketChannel)
{
- ConcurrencyUtil.sleep(1000);
+ ConcurrencyUtil.sleep(DELAY);
return super.createConnector(socketChannel);
}
};
@@ -133,7 +134,7 @@ public class ConnectorTest extends AbstractOMTest
connector.activate();
assertEquals(false, connector.isActive());
- boolean connected = connector.waitForConnection(10 * TIMEOUT);
+ boolean connected = connector.waitForConnection(DELAY + TIMEOUT);
assertEquals(true, connected);
assertEquals(true, connector.isActive());
}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/Connector.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/Connector.java
index 8f91523..e30da43 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/Connector.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/Connector.java
@@ -26,7 +26,6 @@ import org.eclipse.net4j.internal.util.factory.FactoryKey;
import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
import org.eclipse.net4j.util.StringUtil;
import org.eclipse.net4j.util.WrappedException;
-import org.eclipse.net4j.util.concurrent.ConcurrencyUtil;
import org.eclipse.net4j.util.concurrent.RWLock;
import org.eclipse.net4j.util.container.IContainer;
import org.eclipse.net4j.util.container.IContainerEvent;
@@ -297,7 +296,7 @@ public abstract class Connector extends Container<IChannel> implements IConnecto
break;
}
- if (finishedNegotiating.await(Math.min(99L, timeout), TimeUnit.MILLISECONDS))
+ if (finishedNegotiating.await(Math.min(100L, timeout), TimeUnit.MILLISECONDS))
{
break;
}
@@ -307,9 +306,6 @@ public abstract class Connector extends Container<IChannel> implements IConnecto
break;
}
- // Enable thread switch
- // TODO Clarify why this is needed
- ConcurrencyUtil.sleep(1L);
timeout -= 100L;
} while (timeout > 0);