summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2008-05-26 05:21:26 (EDT)
committerEike Stepper2008-05-26 05:21:26 (EDT)
commitbef7d41a8456f8885dd1fad53aa7343bc253806f (patch)
treeab85b9adee068f7c9a3cb2b38878452e7232117c
parentcae28450e1c83f9bb36c2a5a0524645145fa8eed (diff)
downloadcdo-bef7d41a8456f8885dd1fad53aa7343bc253806f.zip
cdo-bef7d41a8456f8885dd1fad53aa7343bc253806f.tar.gz
cdo-bef7d41a8456f8885dd1fad53aa7343bc253806f.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/http/IHTTPConnector.java2
-rw-r--r--plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/HTTPClientConnector.java83
2 files changed, 78 insertions, 7 deletions
diff --git a/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/http/IHTTPConnector.java b/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/http/IHTTPConnector.java
index 03d3771..0927c1b 100644
--- a/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/http/IHTTPConnector.java
+++ b/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/http/IHTTPConnector.java
@@ -17,6 +17,8 @@ import org.eclipse.net4j.connector.IConnector;
*/
public interface IHTTPConnector extends IConnector
{
+ public static final int DEFAULT_POLL_INTERVAL = 5 * 1000;// 5 seconds
+
public static final int UNKNOWN_MAX_IDLE_TIME = -1;
public String getConnectorID();
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 9d4e879..b89f2d6 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,6 +10,7 @@
**************************************************************************/
package org.eclipse.net4j.internal.http;
+import org.eclipse.net4j.channel.IChannel;
import org.eclipse.net4j.connector.ConnectorException;
import org.eclipse.net4j.connector.ConnectorLocation;
import org.eclipse.net4j.http.INet4jTransportServlet;
@@ -20,6 +21,7 @@ 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.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
@@ -44,13 +46,19 @@ public class HTTPClientConnector extends HTTPConnector
private int maxIdleTime = UNKNOWN_MAX_IDLE_TIME;
+ private int pollInterval = DEFAULT_POLL_INTERVAL;
+
+ private long lastRequest = System.currentTimeMillis();
+
+ private boolean requesting;
+
private Worker poller = new Worker()
{
@Override
protected void work(WorkContext context) throws Exception
{
- int pause = poll();
- context.nextWork(pause);
+ boolean moreBuffers = tryBuffersRequest();
+ context.nextWork(moreBuffers ? 0 : 100);
}
};
@@ -78,6 +86,23 @@ public class HTTPClientConnector extends HTTPConnector
return maxIdleTime;
}
+ public int getPollInterval()
+ {
+ return pollInterval;
+ }
+
+ public void setPollInterval(int pollInterval)
+ {
+ this.pollInterval = pollInterval;
+ }
+
+ @Override
+ public void multiplexChannel(IChannel channel)
+ {
+ super.multiplexChannel(channel);
+ tryBuffersRequest();
+ }
+
@Override
public String toString()
{
@@ -160,11 +185,6 @@ public class HTTPClientConnector extends HTTPConnector
}
}
- protected int poll()
- {
- return 0;
- }
-
private void connect() throws IOException
{
request(new IOHandler()
@@ -202,4 +222,53 @@ public class HTTPClientConnector extends HTTPConnector
handler.handleIn(in);
method.releaseConnection();
}
+
+ private boolean tryBuffersRequest()
+ {
+ synchronized (poller)
+ {
+ if (requesting)
+ {
+ return false;
+ }
+
+ requesting = true;
+ }
+
+ if (getOutputQueue().isEmpty() || System.currentTimeMillis() - lastRequest < pollInterval)
+ {
+ return false;
+ }
+
+ try
+ {
+ final boolean moreBuffers[] = { false };
+ request(new IOHandler()
+ {
+ public void handleOut(ExtendedDataOutputStream out) throws IOException
+ {
+ moreBuffers[0] = writeOutputBuffers(out);
+ }
+
+ public void handleIn(ExtendedDataInputStream in) throws IOException
+ {
+ readInputBuffers(in);
+ }
+ });
+
+ lastRequest = System.currentTimeMillis();
+ return moreBuffers[0];
+ }
+ catch (IOException ex)
+ {
+ throw new IORuntimeException(ex);
+ }
+ finally
+ {
+ synchronized (poller)
+ {
+ requesting = false;
+ }
+ }
+ }
}