summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2008-05-24 04:54:40 (EDT)
committerEike Stepper2008-05-24 04:54:40 (EDT)
commit72c22256b9c14272547b4bbb83af0e9b6be10e47 (patch)
tree66f5f4627a1b9193f6a621224bd7017b55208cb2
parent08918c89d3ed23e2c45362617268162e4dc3002b (diff)
downloadcdo-72c22256b9c14272547b4bbb83af0e9b6be10e47.zip
cdo-72c22256b9c14272547b4bbb83af0e9b6be10e47.tar.gz
cdo-72c22256b9c14272547b4bbb83af0e9b6be10e47.tar.bz2
[232648] Provide an HTTPConnector
https://bugs.eclipse.org/bugs/show_bug.cgi?id=232648
-rw-r--r--plugins/org.eclipse.net4j.http/META-INF/MANIFEST.MF3
-rw-r--r--plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/http/IHTTPConnector.java1
-rw-r--r--plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/http/INet4jTransportServlet.java2
-rw-r--r--plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/HTTPAcceptor.java15
-rw-r--r--plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/HTTPClientConnector.java7
-rw-r--r--plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/HTTPConnector.java26
-rw-r--r--plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/HTTPServerConnector.java21
-rw-r--r--plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/Net4jTransportServlet.java15
-rw-r--r--plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPAcceptor.java1
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/channel/IChannelMultiplexer.java4
10 files changed, 51 insertions, 44 deletions
diff --git a/plugins/org.eclipse.net4j.http/META-INF/MANIFEST.MF b/plugins/org.eclipse.net4j.http/META-INF/MANIFEST.MF
index e1c5121..40694d6 100644
--- a/plugins/org.eclipse.net4j.http/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.net4j.http/META-INF/MANIFEST.MF
@@ -12,6 +12,7 @@ Bundle-ClassPath: .
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.3.0,4.0.0)";resolution:=optional,
org.eclipse.net4j;bundle-version="[0.8.0,0.9.0)";visibility:=reexport
Import-Package: javax.servlet;version="2.4.0";resolution:=optional,
- javax.servlet.http;version="2.4.0";resolution:=optional
+ javax.servlet.http;version="2.4.0";resolution:=optional,
+ org.apache.commons.httpclient;version="3.0.1";resolution:=optional
Export-Package: org.eclipse.net4j.http;version="0.8.0",
org.eclipse.net4j.internal.http;version="0.8.0"
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 08f6fd6..393bb0a 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,5 +17,4 @@ import org.eclipse.net4j.connector.IConnector;
*/
public interface IHTTPConnector extends IConnector
{
- public String getURL();
}
diff --git a/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/http/INet4jTransportServlet.java b/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/http/INet4jTransportServlet.java
index e05fe29..3b7e317 100644
--- a/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/http/INet4jTransportServlet.java
+++ b/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/http/INet4jTransportServlet.java
@@ -28,6 +28,6 @@ public interface INet4jTransportServlet extends Servlet
*/
public interface RequestHandler
{
- public void connectRequested(String userID);
+ public int connectRequested(String userID);
}
}
diff --git a/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/HTTPAcceptor.java b/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/HTTPAcceptor.java
index 7aa544a..e61cb26 100644
--- a/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/HTTPAcceptor.java
+++ b/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/HTTPAcceptor.java
@@ -14,6 +14,7 @@ import org.eclipse.net4j.http.IHTTPAcceptor;
import org.eclipse.net4j.http.INet4jTransportServlet;
import org.eclipse.net4j.internal.http.bundle.OM;
import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
+import org.eclipse.net4j.util.concurrent.NonBlockingIntCounter;
import org.eclipse.internal.net4j.acceptor.Acceptor;
@@ -26,6 +27,8 @@ public class HTTPAcceptor extends Acceptor implements IHTTPAcceptor, INet4jTrans
private INet4jTransportServlet servlet;
+ private transient NonBlockingIntCounter lastConnectorID = new NonBlockingIntCounter();
+
public HTTPAcceptor()
{
}
@@ -40,9 +43,17 @@ public class HTTPAcceptor extends Acceptor implements IHTTPAcceptor, INet4jTrans
this.servlet = servlet;
}
- public void connectRequested(String userID)
+ public int connectRequested(String userID)
{
- System.out.println("HELLO " + userID);
+ int connectorID = lastConnectorID.getValue() + 1;
+ System.out.println("HELLO " + userID + " (" + connectorID + ")");
+
+ HTTPServerConnector connector = new HTTPServerConnector(this, connectorID);
+ prepareConnector(connector);
+ connector.setUserID(userID);
+ addConnector(connector);
+
+ return connectorID;
}
@Override
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 e35f226..6dafdfd 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
@@ -31,13 +31,11 @@ public class HTTPClientConnector extends HTTPConnector implements IHTTPConnector
return ConnectorLocation.CLIENT;
}
- @Override
public String getURL()
{
return url;
}
- @Override
public void setURL(String url)
{
this.url = url;
@@ -58,9 +56,6 @@ public class HTTPClientConnector extends HTTPConnector implements IHTTPConnector
protected void doBeforeActivate() throws Exception
{
super.doBeforeActivate();
- if (url == null)
- {
- throw new IllegalStateException("url == null");
- }
+ checkArg(url, "url == null");
}
}
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 e2b9a6c..bb699f6 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
@@ -26,26 +26,10 @@ public abstract class HTTPConnector extends Connector
{
private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, HTTPConnector.class);
- private String url;
-
public HTTPConnector()
{
}
- public String getURL()
- {
- return url;
- }
-
- public void setURL(String url)
- {
- this.url = url;
- }
-
- /**
- * Called by an {@link IChannel} each time a new buffer is available for multiplexing. This or another buffer can be
- * dequeued from the outputQueue of the {@link IChannel}.
- */
public void multiplexChannel(IChannel channel)
{
}
@@ -61,14 +45,4 @@ public abstract class HTTPConnector extends Connector
{
throw new UnsupportedOperationException();
}
-
- @Override
- protected void doBeforeActivate() throws Exception
- {
- super.doBeforeActivate();
- if (url == null)
- {
- throw new IllegalStateException("url == null");
- }
- }
}
diff --git a/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/HTTPServerConnector.java b/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/HTTPServerConnector.java
index fa7d710..e1c7139 100644
--- a/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/HTTPServerConnector.java
+++ b/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/HTTPServerConnector.java
@@ -21,9 +21,14 @@ public class HTTPServerConnector extends HTTPConnector
{
private HTTPAcceptor acceptor;
- public HTTPServerConnector(HTTPAcceptor acceptor)
+ private int connectorID;
+
+ private long lastTraffic = System.currentTimeMillis();
+
+ public HTTPServerConnector(HTTPAcceptor acceptor, int connectorID)
{
this.acceptor = acceptor;
+ this.connectorID = connectorID;
}
public HTTPAcceptor getAcceptor()
@@ -36,14 +41,24 @@ public class HTTPServerConnector extends HTTPConnector
return ConnectorLocation.SERVER;
}
+ public String getURL()
+ {
+ return "agent://connector:" + connectorID;
+ }
+
+ public long getLastTraffic()
+ {
+ return lastTraffic;
+ }
+
@Override
public String toString()
{
if (getUserID() == null)
{
- return MessageFormat.format("HTTPServerConnector[{0}]", acceptor); //$NON-NLS-1$
+ return MessageFormat.format("HTTPServerConnector[{0}]", connectorID); //$NON-NLS-1$
}
- return MessageFormat.format("HTTPServerConnector[{1}@{0}]", acceptor, getUserID()); //$NON-NLS-1$
+ return MessageFormat.format("HTTPServerConnector[{1}@{0}]", connectorID, getUserID()); //$NON-NLS-1$
}
}
diff --git a/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/Net4jTransportServlet.java b/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/Net4jTransportServlet.java
index c68b55b..59a967d 100644
--- a/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/Net4jTransportServlet.java
+++ b/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/Net4jTransportServlet.java
@@ -12,9 +12,11 @@ package org.eclipse.net4j.internal.http;
import org.eclipse.net4j.http.INet4jTransportServlet;
import org.eclipse.net4j.util.io.ExtendedDataInputStream;
+import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
import javax.servlet.ServletException;
import javax.servlet.ServletInputStream;
+import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -60,11 +62,15 @@ public class Net4jTransportServlet extends HttpServlet implements INet4jTranspor
{
ServletInputStream servletInputStream = req.getInputStream();
ExtendedDataInputStream in = new ExtendedDataInputStream(servletInputStream);
+
+ ServletOutputStream servletOutputStream = resp.getOutputStream();
+ ExtendedDataOutputStream out = new ExtendedDataOutputStream(servletOutputStream);
+
int opcode = servletInputStream.read();
switch (opcode)
{
case OPCODE_CONNECT:
- handleConnect(in, req, resp);
+ handleConnect(in, out);
break;
@@ -73,10 +79,11 @@ public class Net4jTransportServlet extends HttpServlet implements INet4jTranspor
}
}
- protected void handleConnect(ExtendedDataInputStream in, HttpServletRequest req, HttpServletResponse resp)
- throws ServletException, IOException
+ protected void handleConnect(ExtendedDataInputStream in, ExtendedDataOutputStream out) throws ServletException,
+ IOException
{
String userID = in.readString();
- requestHandler.connectRequested(userID);
+ int connectorID = requestHandler.connectRequested(userID);
+ out.writeInt(connectorID);
}
}
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 1960e01..62438f7 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
@@ -197,6 +197,7 @@ public class TCPAcceptor extends Acceptor implements ITCPAcceptor, ITCPPassiveSe
{
OM.LOG.error(ex);
}
+
deactivate();
}
}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/channel/IChannelMultiplexer.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/channel/IChannelMultiplexer.java
index f6c30fc..ecc6ce1 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/channel/IChannelMultiplexer.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/channel/IChannelMultiplexer.java
@@ -15,6 +15,10 @@ package org.eclipse.net4j.channel;
*/
public interface IChannelMultiplexer
{
+ /**
+ * Called by an {@link IChannel} each time a new buffer is available for multiplexing. This or another buffer can be
+ * dequeued from the outputQueue of the {@link IChannel}.
+ */
public void multiplexChannel(IChannel channel);
public boolean removeChannel(IChannel channel);