summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2008-05-26 16:47:11 (EDT)
committerEike Stepper2008-05-26 16:47:11 (EDT)
commit61066c273ee44e133c2504c07a6b06b50a3b4579 (patch)
treea965e1bc9cd30fdb905117a8d44f1bf27993b85f
parentabddeef026ede357e99c46a4596c541828f1ecf3 (diff)
downloadcdo-61066c273ee44e133c2504c07a6b06b50a3b4579.zip
cdo-61066c273ee44e133c2504c07a6b06b50a3b4579.tar.gz
cdo-61066c273ee44e133c2504c07a6b06b50a3b4579.tar.bz2
[232648] Provide an HTTPConnector
https://bugs.eclipse.org/bugs/show_bug.cgi?id=232648
-rw-r--r--plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/HTTPChannel.java14
-rw-r--r--plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/HTTPConnector.java124
2 files changed, 92 insertions, 46 deletions
diff --git a/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/HTTPChannel.java b/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/HTTPChannel.java
index f845b43..6e5d205 100644
--- a/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/HTTPChannel.java
+++ b/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/HTTPChannel.java
@@ -10,7 +10,7 @@
**************************************************************************/
package org.eclipse.net4j.internal.http;
-import org.eclipse.net4j.buffer.IBuffer;
+import org.eclipse.net4j.internal.http.HTTPConnector.ChannelOperation;
import org.eclipse.internal.net4j.channel.Channel;
@@ -27,7 +27,7 @@ public class HTTPChannel extends Channel
private long inputOperationCount;
- private Map<Long, IBuffer> inputOperationQuarantine = new ConcurrentHashMap<Long, IBuffer>();
+ private Map<Long, ChannelOperation> inputOperationQuarantine = new ConcurrentHashMap<Long, ChannelOperation>();
private CountDownLatch openAck = new CountDownLatch(1);
@@ -55,12 +55,12 @@ public class HTTPChannel extends Channel
++inputOperationCount;
}
- public void quarantineInputOperation(long count, IBuffer buffer)
+ public void quarantineInputOperation(long count, ChannelOperation operation)
{
- inputOperationQuarantine.put(count, buffer);
+ inputOperationQuarantine.put(count, operation);
}
- public IBuffer getQuarantinedInputOperation(long count)
+ public ChannelOperation getQuarantinedInputOperation(long count)
{
return inputOperationQuarantine.remove(count);
}
@@ -84,9 +84,9 @@ public class HTTPChannel extends Channel
@Override
protected void doDeactivate() throws Exception
{
- for (IBuffer buffer : inputOperationQuarantine.values())
+ for (ChannelOperation operation : inputOperationQuarantine.values())
{
- buffer.release();
+ operation.dispose();
}
inputOperationQuarantine.clear();
diff --git a/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/HTTPConnector.java b/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/HTTPConnector.java
index 6e62149..29b6b0e 100644
--- a/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/HTTPConnector.java
+++ b/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/HTTPConnector.java
@@ -23,7 +23,6 @@ import org.eclipse.net4j.util.security.INegotiationContext;
import org.eclipse.internal.net4j.buffer.Buffer;
import org.eclipse.internal.net4j.channel.Channel;
-import org.eclipse.internal.net4j.channel.InternalChannel;
import org.eclipse.internal.net4j.connector.Connector;
import java.io.IOException;
@@ -166,8 +165,8 @@ public abstract class HTTPConnector extends Connector implements IHTTPConnector
throw new IOException("Invalid operation code: " + code);
}
- operation.execute();
markLastTraffic();
+ operation.execute();
}
}
@@ -259,7 +258,60 @@ public abstract class HTTPConnector extends Connector implements IHTTPConnector
return operationCount;
}
- public abstract void execute();
+ public void execute()
+ {
+ HTTPChannel channel = (HTTPChannel)getChannel(getChannelIndex());
+ long operationCount = getOperationCount();
+ synchronized (channel)
+ {
+ // Execute preceding operations if necessary
+ while (operationCount < channel.getInputOperationCount())
+ {
+ ChannelOperation operation = channel.getQuarantinedInputOperation(channel.getInputOperationCount());
+ if (operation != null)
+ {
+ operation.doEexecute(channel);
+ channel.increaseInputOperationCount();
+ }
+ else
+ {
+ break;
+ }
+ }
+
+ if (operationCount == channel.getInputOperationCount())
+ {
+ // Execute operation if possible
+ doEexecute(channel);
+ channel.increaseInputOperationCount();
+
+ // Execute following operations if possible
+ for (;;)
+ {
+ ChannelOperation operation = channel.getQuarantinedInputOperation(++operationCount);
+ if (operation != null)
+ {
+ operation.doEexecute(channel);
+ channel.increaseInputOperationCount();
+ }
+ else
+ {
+ break;
+ }
+ }
+ }
+ else
+ {
+ channel.quarantineInputOperation(operationCount, this);
+ }
+ }
+ }
+
+ public abstract void doEexecute(HTTPChannel channel);
+
+ public void dispose()
+ {
+ }
}
/**
@@ -312,15 +364,22 @@ public abstract class HTTPConnector extends Connector implements IHTTPConnector
@Override
public void execute()
{
+ HTTPChannel channel = (HTTPChannel)createChannel(channelID, getChannelIndex(), protocolID);
+ if (channel == null)
+ {
+ throw new IllegalStateException("Could not open channel");
+ }
+
+ channel.increaseInputOperationCount();
+ doEexecute(channel);
+ }
+
+ @Override
+ public void doEexecute(HTTPChannel channel)
+ {
boolean success = false;
try
{
- InternalChannel channel = createChannel(channelID, getChannelIndex(), protocolID);
- if (channel == null)
- {
- throw new IllegalStateException("Could not open channel");
- }
-
channel.activate();
success = true;
}
@@ -365,9 +424,8 @@ public abstract class HTTPConnector extends Connector implements IHTTPConnector
}
@Override
- public void execute()
+ public void doEexecute(HTTPChannel channel)
{
- HTTPChannel channel = (HTTPChannel)getChannel(getChannelIndex());
channel.openAck();
}
}
@@ -395,7 +453,7 @@ public abstract class HTTPConnector extends Connector implements IHTTPConnector
}
@Override
- public void execute()
+ public void doEexecute(HTTPChannel channel)
{
System.out.println("OPERATION_CLOSE");
throw new UnsupportedOperationException();
@@ -425,6 +483,7 @@ public abstract class HTTPConnector extends Connector implements IHTTPConnector
for (int i = 0; i < length; i++)
{
byte b = in.readByte();
+ System.out.println("READ " + b);
byteBuffer.put(b);
}
@@ -446,6 +505,7 @@ public abstract class HTTPConnector extends Connector implements IHTTPConnector
for (int i = 0; i < length; i++)
{
byte b = byteBuffer.get();
+ System.out.println("WRITE " + b);
out.writeByte(b);
}
@@ -464,36 +524,22 @@ public abstract class HTTPConnector extends Connector implements IHTTPConnector
}
@Override
- public void execute()
+ public void doEexecute(HTTPChannel channel)
{
- HTTPChannel channel = (HTTPChannel)getChannel(getChannelIndex());
- long operationCount = getOperationCount();
- synchronized (channel)
- {
- while (operationCount < channel.getInputOperationCount())
- {
- IBuffer quarantinedBuffer = channel.getQuarantinedInputOperation(channel.getInputOperationCount());
- if (quarantinedBuffer != null)
- {
- channel.handleBufferFromMultiplexer(buffer);
- channel.increaseInputOperationCount();
- }
- else
- {
- break;
- }
- }
+ channel.handleBufferFromMultiplexer(buffer);
+ buffer = null;
+ }
- if (operationCount == channel.getInputOperationCount())
- {
- channel.handleBufferFromMultiplexer(buffer);
- channel.increaseInputOperationCount();
- }
- else
- {
- channel.quarantineInputOperation(operationCount, buffer);
- }
+ @Override
+ public void dispose()
+ {
+ if (buffer != null)
+ {
+ buffer.release();
+ buffer = null;
}
+
+ super.dispose();
}
}
}