summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2008-05-26 04:48:21 (EDT)
committerEike Stepper2008-05-26 04:48:21 (EDT)
commitcae28450e1c83f9bb36c2a5a0524645145fa8eed (patch)
tree9af20d2c4367c9fc4a5ce2bfeb09a8007c1a4ea1
parent44e6dc9c8ebac4806fa479a4b2828c70d1b88c5a (diff)
downloadcdo-cae28450e1c83f9bb36c2a5a0524645145fa8eed.zip
cdo-cae28450e1c83f9bb36c2a5a0524645145fa8eed.tar.gz
cdo-cae28450e1c83f9bb36c2a5a0524645145fa8eed.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/HTTPClientConnector.java26
-rw-r--r--plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/HTTPConnector.java9
2 files changed, 26 insertions, 9 deletions
diff --git a/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/HTTPClientConnector.java b/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/HTTPClientConnector.java
index 1736fa1..9d4e879 100644
--- a/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/HTTPClientConnector.java
+++ b/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/HTTPClientConnector.java
@@ -10,21 +10,16 @@
**************************************************************************/
package org.eclipse.net4j.internal.http;
-import org.eclipse.net4j.buffer.IBuffer;
-import org.eclipse.net4j.channel.IChannel;
import org.eclipse.net4j.connector.ConnectorException;
import org.eclipse.net4j.connector.ConnectorLocation;
import org.eclipse.net4j.http.INet4jTransportServlet;
import org.eclipse.net4j.internal.http.bundle.OM;
+import org.eclipse.net4j.internal.util.lifecycle.Worker;
import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
import org.eclipse.net4j.protocol.IProtocol;
import org.eclipse.net4j.util.io.ExtendedDataInputStream;
import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
import org.eclipse.net4j.util.io.IOHandler;
-import org.eclipse.net4j.util.io.IORuntimeException;
-
-import org.eclipse.internal.net4j.buffer.Buffer;
-import org.eclipse.internal.net4j.channel.InternalChannel;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
@@ -34,9 +29,7 @@ import org.apache.commons.httpclient.methods.PostMethod;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.nio.ByteBuffer;
import java.text.MessageFormat;
-import java.util.Queue;
/**
* @author Eike Stepper
@@ -51,6 +44,16 @@ public class HTTPClientConnector extends HTTPConnector
private int maxIdleTime = UNKNOWN_MAX_IDLE_TIME;
+ private Worker poller = new Worker()
+ {
+ @Override
+ protected void work(WorkContext context) throws Exception
+ {
+ int pause = poll();
+ context.nextWork(pause);
+ }
+ };
+
public HTTPClientConnector()
{
}
@@ -97,6 +100,7 @@ public class HTTPClientConnector extends HTTPConnector
protected void doActivate() throws Exception
{
super.doActivate();
+ poller.activate();
httpClient = createHTTPClient();
connect();
}
@@ -104,6 +108,7 @@ public class HTTPClientConnector extends HTTPConnector
@Override
protected void doDeactivate() throws Exception
{
+ poller.deactivate();
httpClient = null;
super.doDeactivate();
}
@@ -155,6 +160,11 @@ public class HTTPClientConnector extends HTTPConnector
}
}
+ protected int poll()
+ {
+ return 0;
+ }
+
private void connect() throws IOException
{
request(new IOHandler()
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 548a79a..917fe51 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
@@ -95,7 +95,13 @@ public abstract class HTTPConnector extends Connector implements IHTTPConnector
outputQueue.add(new QueuedBuffer(buffer, outputBufferCount));
}
- public void writeOutputBuffers(ExtendedDataOutputStream out) throws IOException
+ /**
+ * Writes buffers from the {@link #outputQueue} to the passed stream. After each written buffer
+ * {@link #writeMoreBuffers()} is asked whether to send more buffers.
+ *
+ * @return <code>true</code> if more buffers are in the {@link #outputQueue}, <code>false</code> otherwise.
+ */
+ public boolean writeOutputBuffers(ExtendedDataOutputStream out) throws IOException
{
do
{
@@ -129,6 +135,7 @@ public abstract class HTTPConnector extends Connector implements IHTTPConnector
} while (writeMoreBuffers());
out.writeShort(NO_MORE_BUFFERS);
+ return !outputQueue.isEmpty();
}
public void readInputBuffers(ExtendedDataInputStream in) throws IOException