summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2008-05-26 06:04:53 (EDT)
committerEike Stepper2008-05-26 06:04:53 (EDT)
commitec0e4577efead95f52911f43e064a5045816720d (patch)
treea3dcefcf1790b67c6756b7fdab96947cac524759
parentc6d6a06170d48db469844e09519d67e8634cabdf (diff)
downloadcdo-ec0e4577efead95f52911f43e064a5045816720d.zip
cdo-ec0e4577efead95f52911f43e064a5045816720d.tar.gz
cdo-ec0e4577efead95f52911f43e064a5045816720d.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/INet4jTransportServlet.java10
-rw-r--r--plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/HTTPAcceptor.java11
-rw-r--r--plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/HTTPClientConnector.java19
-rw-r--r--plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/HTTPConnector.java6
-rw-r--r--plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/Net4jTransportServlet.java18
5 files changed, 59 insertions, 5 deletions
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 14e3347..8b6ece3 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
@@ -24,11 +24,13 @@ public interface INet4jTransportServlet extends Servlet
{
public static final int OPCODE_CONNECT = 1;
- public static final int OPCODE_OPEN_CHANNEL = 2;
+ public static final int OPCODE_DISCONNECT = 2;
- public static final int OPCODE_CLOSE_CHANNEL = 3;
+ public static final int OPCODE_OPEN_CHANNEL = 3;
- public static final int OPCODE_BUFFERS = 4;
+ public static final int OPCODE_CLOSE_CHANNEL = 4;
+
+ public static final int OPCODE_BUFFERS = 5;
public RequestHandler getRequestHandler();
@@ -43,6 +45,8 @@ public interface INet4jTransportServlet extends Servlet
public IHTTPConnector handleConnect(String userID);
+ public void handleDisonnect(String connectorID);
+
public void handleOpenChannel(String connectorID, short channelIndex, int channelID, String protocolType);
public void handleCloseChannel(String connectorID, short channelIndex);
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 c8467f0..1ef0f7a 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
@@ -149,6 +149,17 @@ public class HTTPAcceptor extends Acceptor implements IHTTPAcceptor, INet4jTrans
return connector;
}
+ public void handleDisonnect(String connectorID)
+ {
+ HTTPConnector connector = httpConnectors.get(connectorID);
+ if (connector == null)
+ {
+ throw new IllegalArgumentException("Invalid connectorID: " + connectorID);
+ }
+
+ connector.deactivate();
+ }
+
public void handleOpenChannel(String connectorID, short channelIndex, int channelID, String protocolType)
{
HTTPConnector connector = httpConnectors.get(connectorID);
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 8cf016a..df2b077 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
@@ -18,6 +18,7 @@ import org.eclipse.net4j.internal.util.lifecycle.Worker;
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.IOAdapter;
import org.eclipse.net4j.util.io.IOHandler;
import org.eclipse.net4j.util.io.IORuntimeException;
@@ -123,12 +124,13 @@ public class HTTPClientConnector extends HTTPConnector
super.doActivate();
poller.activate();
httpClient = createHTTPClient();
- connect();
+ doConnect();
}
@Override
protected void doDeactivate() throws Exception
{
+ doDisconnect();
poller.deactivate();
httpClient = null;
super.doDeactivate();
@@ -181,7 +183,7 @@ public class HTTPClientConnector extends HTTPConnector
}
}
- private void connect() throws IOException
+ private void doConnect() throws IOException
{
request(new IOHandler()
{
@@ -202,6 +204,19 @@ public class HTTPClientConnector extends HTTPConnector
});
}
+ private void doDisconnect() throws IOException
+ {
+ request(new IOAdapter()
+ {
+ @Override
+ public void handleOut(ExtendedDataOutputStream out) throws IOException
+ {
+ out.writeByte(INet4jTransportServlet.OPCODE_DISCONNECT);
+ out.writeString(getConnectorID());
+ }
+ });
+ }
+
private void request(IOHandler handler) throws IOException, HttpException
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
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 31c8837..c8d7d3a 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
@@ -217,6 +217,12 @@ public abstract class HTTPConnector extends Connector implements IHTTPConnector
return new HTTPChannel();
}
+ @Override
+ public void inverseRemoveChannel(int channelID, short channelIndex)
+ {
+ super.inverseRemoveChannel(channelID, channelIndex);
+ }
+
protected boolean pollAgain()
{
return false;
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 c2e97b6..278eb44 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
@@ -94,6 +94,10 @@ public class Net4jTransportServlet extends HttpServlet implements INet4jTranspor
doConnect(in, out);
break;
+ case OPCODE_DISCONNECT:
+ doDisconnect(in, out);
+ break;
+
case OPCODE_OPEN_CHANNEL:
doOpenChannel(in, out);
break;
@@ -178,6 +182,20 @@ public class Net4jTransportServlet extends HttpServlet implements INet4jTranspor
}
}
+ protected void doDisconnect(ExtendedDataInputStream in, ExtendedDataOutputStream out) throws ServletException,
+ IOException
+ {
+ try
+ {
+ String connectorID = in.readString();
+ requestHandler.handleDisonnect(connectorID);
+ }
+ catch (Exception ex)
+ {
+ OM.LOG.error(ex);
+ }
+ }
+
protected void doOpenChannel(ExtendedDataInputStream in, ExtendedDataOutputStream out) throws ServletException,
IOException
{