summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-10-05 08:47:06 (EDT)
committerEike Stepper2007-10-05 08:47:06 (EDT)
commitc40df69c69f0bea41af2c962de289a1a943872eb (patch)
tree8bb73908eba87f8bf89526c7c87e422becb897b9
parentee762ffbc53b26009923bef2864936063cf27c56 (diff)
downloadcdo-c40df69c69f0bea41af2c962de289a1a943872eb.zip
cdo-c40df69c69f0bea41af2c962de289a1a943872eb.tar.gz
cdo-c40df69c69f0bea41af2c962de289a1a943872eb.tar.bz2
[205027] Implement challenge/response based negotiator
https://bugs.eclipse.org/bugs/show_bug.cgi?id=205027
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/net4j/org/eclipse/net4j/tests/AbstractOMTest.java8
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/net4j/org/eclipse/net4j/tests/AbstractTransportTest.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AbstractCDOTest.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/InvalidationTest.java2
-rw-r--r--plugins/org.eclipse.net4j.jms.tests/src/org/eclipse/net4j/jms/tests/JMSSeparatedTest.java3
-rw-r--r--plugins/org.eclipse.net4j.jms.tests/src/org/eclipse/net4j/jms/tests/JMSTest.java3
-rw-r--r--plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/ControlChannel.java43
-rw-r--r--plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPConnector.java49
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/AbstractTransportTest.java2
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/TCPTransportTest.java2
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/TestBufferPool.java2
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/AbstractOMTest.java8
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/SecurityTest.java8
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/SynchronizingCorrelatorTest.java2
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/cache/CacheTest.java4
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/concurrent/AsynchronousWorkSerializer.java9
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/lifecycle/Worker.java17
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/ChallengeNegotiator.java1
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/ChallengeResponseNegotiator.java4
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/Negotiator.java12
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/ResponseNegotiator.java1
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/concurrent/ConcurrencyUtil.java47
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/GZIPStreamWrapper.java8
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/security/INegotiator.java2
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/Acceptor.java14
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/Connector.java34
26 files changed, 240 insertions, 49 deletions
diff --git a/plugins/org.eclipse.emf.cdo.tests/net4j/org/eclipse/net4j/tests/AbstractOMTest.java b/plugins/org.eclipse.emf.cdo.tests/net4j/org/eclipse/net4j/tests/AbstractOMTest.java
index 33b6a6b..d3603a4 100644
--- a/plugins/org.eclipse.emf.cdo.tests/net4j/org/eclipse/net4j/tests/AbstractOMTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/net4j/org/eclipse/net4j/tests/AbstractOMTest.java
@@ -12,6 +12,7 @@ package org.eclipse.net4j.tests;
import org.eclipse.net4j.internal.util.om.log.PrintLogHandler;
import org.eclipse.net4j.internal.util.om.trace.PrintTraceHandler;
+import org.eclipse.net4j.util.concurrent.ConcurrencyUtil;
import org.eclipse.net4j.util.om.OMPlatform;
import junit.framework.TestCase;
@@ -48,7 +49,7 @@ public abstract class AbstractOMTest extends TestCase
@Override
public final void tearDown() throws Exception
{
- Thread.sleep(200);
+ sleep(200);
System.out.println("------------------------ END --------------------------");
System.out.println();
@@ -112,4 +113,9 @@ public abstract class AbstractOMTest extends TestCase
System.out.println("--> " + m);
}
}
+
+ protected static void sleep(long millis)
+ {
+ ConcurrencyUtil.sleep(millis);
+ }
} \ No newline at end of file
diff --git a/plugins/org.eclipse.emf.cdo.tests/net4j/org/eclipse/net4j/tests/AbstractTransportTest.java b/plugins/org.eclipse.emf.cdo.tests/net4j/org/eclipse/net4j/tests/AbstractTransportTest.java
index bddd9f1..4c9919c 100644
--- a/plugins/org.eclipse.emf.cdo.tests/net4j/org/eclipse/net4j/tests/AbstractTransportTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/net4j/org/eclipse/net4j/tests/AbstractTransportTest.java
@@ -45,7 +45,7 @@ public abstract class AbstractTransportTest extends AbstractOMTest
{
try
{
- Thread.sleep(20);
+ sleep(20);
LifecycleUtil.deactivate(container);
}
finally
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AbstractCDOTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AbstractCDOTest.java
index 5415ec1..cc4a37d 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AbstractCDOTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AbstractCDOTest.java
@@ -210,7 +210,7 @@ public abstract class AbstractCDOTest extends AbstractTransportTest
return false;
}
- Thread.sleep(interval);
+ sleep(interval);
}
return true;
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/InvalidationTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/InvalidationTest.java
index 6f6e555..7e89056 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/InvalidationTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/InvalidationTest.java
@@ -108,7 +108,7 @@ public class InvalidationTest extends AbstractCDOTest
msg("Changing name");
category1A.setName("CHANGED NAME");
- Thread.sleep(500);
+ sleep(500);
msg("Checking before commit");
assertEquals("category1", category1B.getName());
diff --git a/plugins/org.eclipse.net4j.jms.tests/src/org/eclipse/net4j/jms/tests/JMSSeparatedTest.java b/plugins/org.eclipse.net4j.jms.tests/src/org/eclipse/net4j/jms/tests/JMSSeparatedTest.java
index 3ffb954..fa9ba96 100644
--- a/plugins/org.eclipse.net4j.jms.tests/src/org/eclipse/net4j/jms/tests/JMSSeparatedTest.java
+++ b/plugins/org.eclipse.net4j.jms.tests/src/org/eclipse/net4j/jms/tests/JMSSeparatedTest.java
@@ -26,6 +26,7 @@ import org.eclipse.net4j.jms.server.IStore;
import org.eclipse.net4j.jms.server.JMSServerUtil;
import org.eclipse.net4j.jms.server.jdbc.JDBCUtil;
import org.eclipse.net4j.tcp.TCPUtil;
+import org.eclipse.net4j.util.concurrent.ConcurrencyUtil;
import org.eclipse.net4j.util.container.IManagedContainer;
import org.eclipse.net4j.util.om.OMPlatform;
@@ -72,7 +73,7 @@ public class JMSSeparatedTest
}
finally
{
- Thread.sleep(500);
+ ConcurrencyUtil.sleep(500);
Server.INSTANCE.deactivate();
}
}
diff --git a/plugins/org.eclipse.net4j.jms.tests/src/org/eclipse/net4j/jms/tests/JMSTest.java b/plugins/org.eclipse.net4j.jms.tests/src/org/eclipse/net4j/jms/tests/JMSTest.java
index 0dc2e48..2d34756 100644
--- a/plugins/org.eclipse.net4j.jms.tests/src/org/eclipse/net4j/jms/tests/JMSTest.java
+++ b/plugins/org.eclipse.net4j.jms.tests/src/org/eclipse/net4j/jms/tests/JMSTest.java
@@ -26,6 +26,7 @@ import org.eclipse.net4j.jms.server.IStore;
import org.eclipse.net4j.jms.server.JMSServerUtil;
import org.eclipse.net4j.jms.server.jdbc.JDBCUtil;
import org.eclipse.net4j.tcp.TCPUtil;
+import org.eclipse.net4j.util.concurrent.ConcurrencyUtil;
import org.eclipse.net4j.util.container.IManagedContainer;
import org.eclipse.net4j.util.om.OMPlatform;
@@ -71,7 +72,7 @@ public class JMSTest
}
finally
{
- Thread.sleep(500);
+ ConcurrencyUtil.sleep(500);
Server.INSTANCE.deactivate();
}
}
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 e4252cd..7e3cf8e 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,12 +10,15 @@
**************************************************************************/
package org.eclipse.net4j.internal.tcp;
+import org.eclipse.net4j.ConnectorState;
import org.eclipse.net4j.IBuffer;
import org.eclipse.net4j.IProtocol;
import org.eclipse.net4j.internal.tcp.bundle.OM;
import org.eclipse.net4j.internal.util.concurrent.SynchronizingCorrelator;
import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
+import org.eclipse.net4j.util.concurrent.ConcurrencyUtil;
import org.eclipse.net4j.util.concurrent.ISynchronizer;
+import org.eclipse.net4j.util.security.INegotiationContext;
import org.eclipse.internal.net4j.BufferUtil;
import org.eclipse.internal.net4j.Channel;
@@ -31,11 +34,13 @@ public final class ControlChannel extends Channel
public static final long REGISTRATION_TIMEOUT = 500000;
- public static final byte OPCODE_REGISTRATION = 1;
+ public static final byte OPCODE_NEGOTIATION = 1;
- public static final byte OPCODE_REGISTRATION_ACK = 2;
+ public static final byte OPCODE_REGISTRATION = 2;
- public static final byte OPCODE_DEREGISTRATION = 3;
+ public static final byte OPCODE_REGISTRATION_ACK = 3;
+
+ public static final byte OPCODE_DEREGISTRATION = 4;
public static final byte SUCCESS = 1;
@@ -111,8 +116,22 @@ public final class ControlChannel extends Channel
byte opcode = byteBuffer.get();
switch (opcode)
{
+ case OPCODE_NEGOTIATION:
+ {
+ assertNegotiating();
+ INegotiationContext negotiationContext = getConnector().getNegotiationContext();
+ while (negotiationContext == null)
+ {
+ ConcurrencyUtil.sleep(20);
+ negotiationContext = getConnector().getNegotiationContext();
+ }
+ negotiationContext.getBuffer();
+ break;
+ }
+
case OPCODE_REGISTRATION:
{
+ assertConnected();
int channelID = byteBuffer.getInt();
short channelIndex = byteBuffer.getShort();
assertValidChannelIndex(channelIndex);
@@ -144,6 +163,7 @@ public final class ControlChannel extends Channel
case OPCODE_REGISTRATION_ACK:
{
+ assertConnected();
short channelIndex = byteBuffer.getShort();
boolean success = byteBuffer.get() == SUCCESS;
registrations.put(channelIndex, success);
@@ -152,6 +172,7 @@ public final class ControlChannel extends Channel
case OPCODE_DEREGISTRATION:
{
+ assertConnected();
int channelID = byteBuffer.getInt();
short channelIndex = byteBuffer.getShort();
if (channelIndex != CONTROL_CHANNEL_INDEX)
@@ -196,6 +217,22 @@ public final class ControlChannel extends Channel
handleBuffer(buffer);
}
+ private void assertNegotiating()
+ {
+ if (getConnector().getState() != ConnectorState.NEGOTIATING)
+ {
+ throw new IllegalStateException("Connector is not negotiating");
+ }
+ }
+
+ private void assertConnected()
+ {
+ if (!getConnector().isConnected())
+ {
+ throw new IllegalStateException("Connector is not connected");
+ }
+ }
+
private void assertValidChannelIndex(short channelIndex)
{
if (channelIndex <= CONTROL_CHANNEL_INDEX)
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 20ad03e..31646ca 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,11 +17,13 @@ import org.eclipse.net4j.IChannel;
import org.eclipse.net4j.IProtocol;
import org.eclipse.net4j.internal.tcp.bundle.OM;
import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
+import org.eclipse.net4j.internal.util.security.NegotiationContext;
import org.eclipse.net4j.tcp.ITCPConnector;
import org.eclipse.net4j.tcp.ITCPSelector;
import org.eclipse.net4j.tcp.ITCPSelectorListener;
import org.eclipse.net4j.util.io.IOUtil;
import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
+import org.eclipse.net4j.util.security.INegotiationContext;
import org.eclipse.internal.net4j.Channel;
import org.eclipse.internal.net4j.Connector;
@@ -30,7 +32,9 @@ import java.nio.ByteBuffer;
import java.nio.channels.ClosedChannelException;
import java.nio.channels.SelectionKey;
import java.nio.channels.SocketChannel;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import java.util.Queue;
/**
@@ -323,6 +327,12 @@ public abstract class TCPConnector extends Connector implements ITCPConnector, I
}
@Override
+ protected INegotiationContext createNegotiationContext()
+ {
+ return new TCPNegotiationContext();
+ }
+
+ @Override
protected void doBeforeActivate() throws Exception
{
super.doBeforeActivate();
@@ -365,4 +375,43 @@ public abstract class TCPConnector extends Connector implements ITCPConnector, I
throw new IllegalStateException("selectionKey == null");
}
}
+
+ /**
+ * @author Eike Stepper
+ */
+ private final class TCPNegotiationContext extends NegotiationContext
+ {
+ private Map<ByteBuffer, IBuffer> buffers = new HashMap<ByteBuffer, IBuffer>();
+
+ public TCPNegotiationContext()
+ {
+ }
+
+ public ByteBuffer getBuffer()
+ {
+ IBuffer buffer = getBufferProvider().provideBuffer();
+ ByteBuffer byteBuffer = buffer.startPutting(ControlChannel.CONTROL_CHANNEL_INDEX);
+ buffers.put(byteBuffer, buffer);
+ return byteBuffer;
+ }
+
+ public void transmitBuffer(ByteBuffer byteBuffer)
+ {
+ IBuffer buffer = buffers.remove(byteBuffer);
+ controlChannel.sendBuffer(buffer);
+ }
+
+ @Override
+ public void setFinished(boolean success)
+ {
+ if (success)
+ {
+ }
+ else
+ {
+ }
+
+ super.setFinished(success);
+ }
+ }
}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/AbstractTransportTest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/AbstractTransportTest.java
index c965af2..7fc795a 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/AbstractTransportTest.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/AbstractTransportTest.java
@@ -46,7 +46,7 @@ public abstract class AbstractTransportTest extends AbstractOMTest
{
try
{
- Thread.sleep(20);
+ sleep(20);
LifecycleUtil.deactivate(container);
}
finally
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/TCPTransportTest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/TCPTransportTest.java
index 7d6fab8..3108f94 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/TCPTransportTest.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/TCPTransportTest.java
@@ -89,7 +89,7 @@ public class TCPTransportTest extends AbstractTransportTest
ByteBuffer byteBuffer = buffer.startPutting(channel.getChannelIndex());
byteBuffer.putInt(1970);
channel.sendBuffer(buffer);
- Thread.sleep(50);
+ sleep(50);
}
assertTrue(counter.await(2, TimeUnit.SECONDS));
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/TestBufferPool.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/TestBufferPool.java
index 3091873..9021a99 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/TestBufferPool.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/TestBufferPool.java
@@ -47,7 +47,7 @@ public class TestBufferPool extends AbstractOMTest
while (Net4jUtil.getPooledBuffers(bufferPool) > 0 && allocate())
{
- Thread.sleep(200);
+ sleep(200);
ReflectUtil.dump(bufferPool);
}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/AbstractOMTest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/AbstractOMTest.java
index 9ff7037..c37b2bf 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/AbstractOMTest.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/AbstractOMTest.java
@@ -12,6 +12,7 @@ package org.eclipse.net4j.util.tests;
import org.eclipse.net4j.internal.util.om.log.PrintLogHandler;
import org.eclipse.net4j.internal.util.om.trace.PrintTraceHandler;
+import org.eclipse.net4j.util.concurrent.ConcurrencyUtil;
import org.eclipse.net4j.util.om.OMPlatform;
import junit.framework.TestCase;
@@ -48,7 +49,7 @@ public abstract class AbstractOMTest extends TestCase
@Override
public final void tearDown() throws Exception
{
- Thread.sleep(200);
+ sleep(200);
System.out.println("------------------------ END --------------------------");
System.out.println();
@@ -112,4 +113,9 @@ public abstract class AbstractOMTest extends TestCase
System.out.println("--> " + m);
}
}
+
+ protected static void sleep(long millis)
+ {
+ ConcurrencyUtil.sleep(millis);
+ }
} \ No newline at end of file
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/SecurityTest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/SecurityTest.java
index 350a352..1bccea5 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/SecurityTest.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/SecurityTest.java
@@ -78,14 +78,14 @@ public class SecurityTest extends AbstractOMTest
ResponseNegotiator responseNegotiator = new ResponseNegotiator();
responseNegotiator.setCredentialsProvider(credentialsProvider);
responseNegotiator.activate();
- responseNegotiator.negotiate(responseContext, false);
+ responseNegotiator.negotiate(responseContext);
// Prepare challenge negotiator
ChallengeNegotiator challengeNegotiator = new ChallengeNegotiator();
challengeNegotiator.setRandomizer(randomizer);
challengeNegotiator.setUserManager(userManager);
challengeNegotiator.activate();
- challengeNegotiator.negotiate(challengeContext, true);
+ challengeNegotiator.negotiate(challengeContext);
Enum<?> responseState = responseContext.waitUntilFinished(TIMEOUT);
assertEquals(IChallengeResponse.State.SUCCESS, responseState);
@@ -130,14 +130,14 @@ public class SecurityTest extends AbstractOMTest
ResponseNegotiator responseNegotiator = new ResponseNegotiator();
responseNegotiator.setCredentialsProvider(credentialsProvider);
responseNegotiator.activate();
- responseNegotiator.negotiate(responseContext, false);
+ responseNegotiator.negotiate(responseContext);
// Prepare challenge negotiator
ChallengeNegotiator challengeNegotiator = new ChallengeNegotiator();
challengeNegotiator.setRandomizer(randomizer);
challengeNegotiator.setUserManager(userManager);
challengeNegotiator.activate();
- challengeNegotiator.negotiate(challengeContext, true);
+ challengeNegotiator.negotiate(challengeContext);
Enum<?> responseState = responseContext.waitUntilFinished(TIMEOUT);
assertEquals(IChallengeResponse.State.FAILURE, responseState);
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/SynchronizingCorrelatorTest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/SynchronizingCorrelatorTest.java
index 229dabd..2158ffb 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/SynchronizingCorrelatorTest.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/SynchronizingCorrelatorTest.java
@@ -34,7 +34,7 @@ public class SynchronizingCorrelatorTest extends AbstractOMTest
};
consumer.start();
- Thread.sleep(50);
+ sleep(50);
correlator.put("eike", true);
consumer.join(100);
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/cache/CacheTest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/cache/CacheTest.java
index f068b83..4b17ff4 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/cache/CacheTest.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/cache/CacheTest.java
@@ -41,11 +41,11 @@ public class CacheTest extends AbstractOMTest
for (int id = 1; id <= 100; id++)
{
revisionManager.getRevision(id, version);
- Thread.sleep(200);
+ sleep(200);
}
System.gc();
- Thread.sleep(1000);
+ sleep(1000);
}
revisionManager.deactivate();
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/concurrent/AsynchronousWorkSerializer.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/concurrent/AsynchronousWorkSerializer.java
index a29d51a..fcaa578 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/concurrent/AsynchronousWorkSerializer.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/concurrent/AsynchronousWorkSerializer.java
@@ -107,14 +107,7 @@ public class AsynchronousWorkSerializer implements IWorkSerializer, Runnable
}
}
- // try
- // {
- // Thread.sleep(500);
- // }
- // catch (InterruptedException ex)
- // {
- // throw WrappedException.wrap(ex);
- // }
+ // ConcurrencyUtil.sleep(500);
// Could put the sync in the while loop... but not efficient.
// Doing a last check to make sure that no one added something in the
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/lifecycle/Worker.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/lifecycle/Worker.java
index a9503d3..06b3b0f 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/lifecycle/Worker.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/lifecycle/Worker.java
@@ -11,6 +11,7 @@
package org.eclipse.net4j.internal.util.lifecycle;
import org.eclipse.net4j.internal.util.bundle.OM;
+import org.eclipse.net4j.util.concurrent.ConcurrencyUtil;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
@@ -226,21 +227,11 @@ public abstract class Worker extends Lifecycle
this.pauseMillis = pauseMillis;
}
- public boolean pause()
+ public void pause()
{
- if (pauseMillis <= 0)
+ if (pauseMillis > 0)
{
- return true;
- }
-
- try
- {
- Thread.sleep(pauseMillis);
- return true;
- }
- catch (InterruptedException ex)
- {
- return false;
+ ConcurrencyUtil.sleep(pauseMillis);
}
}
}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/ChallengeNegotiator.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/ChallengeNegotiator.java
index f999b87..d2d4d09 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/ChallengeNegotiator.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/ChallengeNegotiator.java
@@ -32,6 +32,7 @@ public class ChallengeNegotiator extends ChallengeResponseNegotiator
public ChallengeNegotiator()
{
+ super(true);
}
public int getTokenLength()
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/ChallengeResponseNegotiator.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/ChallengeResponseNegotiator.java
index 16c2ad5..1a1b98f 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/ChallengeResponseNegotiator.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/ChallengeResponseNegotiator.java
@@ -27,9 +27,9 @@ public abstract class ChallengeResponseNegotiator extends
private String algorithmName = DEFAULT_ALGORITHM_NAME;
- public ChallengeResponseNegotiator()
+ public ChallengeResponseNegotiator(boolean initiator)
{
- super(State.class, Event.class, State.INITIAL, State.SUCCESS, State.FAILURE, Event.START, Event.BUFFER);
+ super(State.class, Event.class, State.INITIAL, State.SUCCESS, State.FAILURE, Event.START, Event.BUFFER, initiator);
init(State.INITIAL, Event.START, new Transition()
{
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/Negotiator.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/Negotiator.java
index e1c99ae..9085189 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/Negotiator.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/Negotiator.java
@@ -32,8 +32,10 @@ public abstract class Negotiator<STATE extends Enum<?>, EVENT extends Enum<?>> e
private EVENT bufferEvent;
+ private boolean initiator;
+
public Negotiator(Class<STATE> stateEnum, Class<EVENT> eventEnum, STATE initialState, STATE successState,
- STATE failureState, EVENT startEvent, EVENT bufferEvent)
+ STATE failureState, EVENT startEvent, EVENT bufferEvent, boolean initiator)
{
super(stateEnum, eventEnum);
@@ -48,6 +50,7 @@ public abstract class Negotiator<STATE extends Enum<?>, EVENT extends Enum<?>> e
this.failureState = failureState;
this.startEvent = startEvent;
this.bufferEvent = bufferEvent;
+ this.initiator = initiator;
}
@@ -76,7 +79,12 @@ public abstract class Negotiator<STATE extends Enum<?>, EVENT extends Enum<?>> e
return startEvent;
}
- public void negotiate(INegotiationContext context, boolean initiator)
+ public boolean isInitiator()
+ {
+ return initiator;
+ }
+
+ public void negotiate(INegotiationContext context)
{
context.setReceiver(this);
context.setState(initialState);
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/ResponseNegotiator.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/ResponseNegotiator.java
index 053d09c..b4ef934 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/ResponseNegotiator.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/security/ResponseNegotiator.java
@@ -26,6 +26,7 @@ public class ResponseNegotiator extends ChallengeResponseNegotiator
public ResponseNegotiator()
{
+ super(false);
}
public IPasswordCredentialsProvider getCredentialsProvider()
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/concurrent/ConcurrencyUtil.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/concurrent/ConcurrencyUtil.java
new file mode 100644
index 0000000..72a427c
--- /dev/null
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/concurrent/ConcurrencyUtil.java
@@ -0,0 +1,47 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2007 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.concurrent;
+
+import org.eclipse.net4j.util.WrappedException;
+
+/**
+ * @author Eike Stepper
+ */
+public final class ConcurrencyUtil
+{
+ private ConcurrencyUtil()
+ {
+ }
+
+ public static void sleep(long millis)
+ {
+ try
+ {
+ Thread.sleep(millis);
+ }
+ catch (InterruptedException ex)
+ {
+ throw WrappedException.wrap(ex);
+ }
+ }
+
+ public static void sleep(long millis, int nanos)
+ {
+ try
+ {
+ Thread.sleep(millis, nanos);
+ }
+ catch (InterruptedException ex)
+ {
+ throw WrappedException.wrap(ex);
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/GZIPStreamWrapper.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/GZIPStreamWrapper.java
index 3be4cda..b3ad602 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/GZIPStreamWrapper.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/GZIPStreamWrapper.java
@@ -11,6 +11,7 @@
package org.eclipse.net4j.util.io;
import org.eclipse.net4j.util.HexUtil;
+import org.eclipse.net4j.util.concurrent.ConcurrencyUtil;
import java.io.IOException;
import java.io.InputStream;
@@ -58,6 +59,9 @@ public class GZIPStreamWrapper implements IStreamWrapper
((GZIPOutputStream)out).finish();
}
+ /**
+ * TODO Move or remove me
+ */
public static void main(String[] args) throws Exception
{
final PipedOutputStream pos = new PipedOutputStream();
@@ -88,12 +92,12 @@ public class GZIPStreamWrapper implements IStreamWrapper
};
thread.start();
- Thread.sleep(1000);
+ ConcurrencyUtil.sleep(1000);
gos.write(out);
gos.close();
System.out.println("Written: " + HexUtil.bytesToHex(out));
- Thread.sleep(2000);
+ ConcurrencyUtil.sleep(2000);
}
}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/security/INegotiator.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/security/INegotiator.java
index 1b81cdf..21e98fb 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/security/INegotiator.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/security/INegotiator.java
@@ -15,5 +15,5 @@ package org.eclipse.net4j.util.security;
*/
public interface INegotiator
{
- public void negotiate(INegotiationContext context, boolean initiator);
+ public void negotiate(INegotiationContext context);
}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/Acceptor.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/Acceptor.java
index 52261e5..1f358f9 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/Acceptor.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/Acceptor.java
@@ -25,6 +25,7 @@ import org.eclipse.net4j.util.factory.IFactory;
import org.eclipse.net4j.util.factory.IFactoryKey;
import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
import org.eclipse.net4j.util.registry.IRegistry;
+import org.eclipse.net4j.util.security.INegotiator;
import org.eclipse.internal.net4j.bundle.OM;
@@ -40,6 +41,8 @@ public abstract class Acceptor extends Container<IConnector> implements IAccepto
{
private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_ACCEPTOR, Acceptor.class);
+ private INegotiator negotiator;
+
private IBufferProvider bufferProvider;
private IRegistry<IFactoryKey, IFactory> protocolFactoryRegistry;
@@ -67,6 +70,16 @@ public abstract class Acceptor extends Container<IConnector> implements IAccepto
{
}
+ public INegotiator getNegotiator()
+ {
+ return negotiator;
+ }
+
+ public void setNegotiator(INegotiator negotiator)
+ {
+ this.negotiator = negotiator;
+ }
+
public IBufferProvider getBufferProvider()
{
return bufferProvider;
@@ -130,6 +143,7 @@ public abstract class Acceptor extends Container<IConnector> implements IAccepto
{
try
{
+ connector.setNegotiator(negotiator);
connector.setBufferProvider(bufferProvider);
connector.setReceiveExecutor(receiveExecutor);
connector.setProtocolFactoryRegistry(protocolFactoryRegistry);
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 c31ed6c..e673c4e 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
@@ -37,6 +37,8 @@ import org.eclipse.net4j.util.factory.IFactory;
import org.eclipse.net4j.util.factory.IFactoryKey;
import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
import org.eclipse.net4j.util.registry.IRegistry;
+import org.eclipse.net4j.util.security.INegotiationContext;
+import org.eclipse.net4j.util.security.INegotiator;
import org.eclipse.internal.net4j.bundle.OM;
@@ -62,6 +64,10 @@ public abstract class Connector extends Container<IChannel> implements IConnecto
private List<IElementProcessor> protocolPostProcessors;
+ private INegotiator negotiator;
+
+ private INegotiationContext negotiationContext;
+
private IBufferProvider bufferProvider;
/**
@@ -136,6 +142,21 @@ public abstract class Connector extends Container<IChannel> implements IConnecto
return bufferProvider;
}
+ public INegotiator getNegotiator()
+ {
+ return negotiator;
+ }
+
+ public void setNegotiator(INegotiator negotiator)
+ {
+ this.negotiator = negotiator;
+ }
+
+ public INegotiationContext getNegotiationContext()
+ {
+ return negotiationContext;
+ }
+
public void setBufferProvider(IBufferProvider bufferProvider)
{
this.bufferProvider = bufferProvider;
@@ -206,10 +227,19 @@ public abstract class Connector extends Container<IChannel> implements IConnecto
case NEGOTIATING:
finishedConnecting.countDown();
- setState(ConnectorState.CONNECTED); // TODO Implement negotiation
+ if (negotiator != null)
+ {
+ negotiationContext = createNegotiationContext();
+ negotiator.negotiate(negotiationContext);
+ }
+ else
+ {
+ setState(ConnectorState.CONNECTED);
+ }
break;
case CONNECTED:
+ negotiationContext = null;
finishedConnecting.countDown(); // Just in case of suspicion
finishedNegotiating.countDown();
break;
@@ -561,6 +591,8 @@ public abstract class Connector extends Container<IChannel> implements IConnecto
}
}
+ protected abstract INegotiationContext createNegotiationContext();
+
/**
* TODO Use IProtocolProvider and make the protocols real container elements, so that the post processors can reach
* them. The protocol description can be used to store unique protocol IDs so that always new protocols are created in