Merge branch 'master' of github.com:intalio/jetty-fcgi

This commit is contained in:
Greg Wilkins 2013-10-03 09:25:52 +10:00
commit e00f5c4056
3 changed files with 40 additions and 29 deletions

View File

@ -36,7 +36,6 @@ public class Flusher
private final Queue<Generator.Result> queue = new ConcurrentArrayQueue<>(); private final Queue<Generator.Result> queue = new ConcurrentArrayQueue<>();
private final Callback flushCallback = new FlushCallback(); private final Callback flushCallback = new FlushCallback();
private final EndPoint endPoint; private final EndPoint endPoint;
private boolean flushing;
public Flusher(EndPoint endPoint) public Flusher(EndPoint endPoint)
{ {
@ -48,10 +47,9 @@ public class Flusher
synchronized (queue) synchronized (queue)
{ {
for (Generator.Result result : results) for (Generator.Result result : results)
{
queue.offer(result); queue.offer(result);
if (flushing) }
return;
flushing = true;
} }
endPoint.write(flushCallback); endPoint.write(flushCallback);
} }
@ -68,27 +66,15 @@ public class Flusher
@Override @Override
protected boolean process() throws Exception protected boolean process() throws Exception
{ {
// We are flushing, we completed a write, notify
if (active != null)
{
active.succeeded();
active = null;
}
// Look if other writes are needed. // Look if other writes are needed.
Generator.Result result; Generator.Result result;
synchronized (queue) synchronized (queue)
{ {
if (queue.isEmpty()) if (queue.isEmpty())
{
// No more writes to do, switch to non-flushing
flushing = false;
return false; return false;
}
// TODO: here is where we want to gather more results to perform gathered writes // TODO: here is where we want to gather more results to perform gathered writes
result = queue.poll(); result = queue.poll();
} }
active = result; active = result;
List<ByteBuffer> buffers = result.getByteBuffers(); List<ByteBuffer> buffers = result.getByteBuffers();
endPoint.write(this, buffers.toArray(new ByteBuffer[buffers.size()])); endPoint.write(this, buffers.toArray(new ByteBuffer[buffers.size()]));
@ -101,18 +87,22 @@ public class Flusher
// Nothing to do, we always return false from process(). // Nothing to do, we always return false from process().
} }
@Override
public void succeeded()
{
if (active != null)
active.succeeded();
active = null;
super.succeeded();
}
@Override @Override
public void failed(Throwable x) public void failed(Throwable x)
{ {
super.failed(x);
// TODO: set flushing=false ?
if (active != null) if (active != null)
{
active.failed(x); active.failed(x);
active = null; active = null;
} super.failed(x);
} }
} }

View File

@ -18,6 +18,8 @@
package org.eclipse.jetty.fcgi.client.http; package org.eclipse.jetty.fcgi.client.http;
import java.util.regex.Pattern;
import org.eclipse.jetty.client.AbstractHttpClientTransport; import org.eclipse.jetty.client.AbstractHttpClientTransport;
import org.eclipse.jetty.client.HttpDestination; import org.eclipse.jetty.client.HttpDestination;
import org.eclipse.jetty.client.api.Connection; import org.eclipse.jetty.client.api.Connection;
@ -26,14 +28,22 @@ import org.eclipse.jetty.io.EndPoint;
// TODO: add parameter to tell whether use multiplex destinations or not // TODO: add parameter to tell whether use multiplex destinations or not
public class HttpClientTransportOverFCGI extends AbstractHttpClientTransport public class HttpClientTransportOverFCGI extends AbstractHttpClientTransport
{ {
public HttpClientTransportOverFCGI() private final Pattern uriPattern;
public HttpClientTransportOverFCGI(Pattern uriPattern)
{ {
this(1); this(1, uriPattern);
} }
public HttpClientTransportOverFCGI(int selectors) public HttpClientTransportOverFCGI(int selectors, Pattern uriPattern)
{ {
super(selectors); super(selectors);
this.uriPattern = uriPattern;
}
public Pattern getURIPattern()
{
return uriPattern;
} }
@Override @Override

View File

@ -1,6 +1,8 @@
package org.eclipse.jetty.fcgi.client.http; package org.eclipse.jetty.fcgi.client.http;
import java.net.URI; import java.net.URI;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.eclipse.jetty.client.HttpChannel; import org.eclipse.jetty.client.HttpChannel;
import org.eclipse.jetty.client.HttpContent; import org.eclipse.jetty.client.HttpContent;
@ -52,11 +54,20 @@ public class HttpSenderOverFCGI extends HttpSender
headers.put(FCGI.Headers.GATEWAY_INTERFACE, "CGI/1.1"); headers.put(FCGI.Headers.GATEWAY_INTERFACE, "CGI/1.1");
HttpClientTransportOverFCGI transport = (HttpClientTransportOverFCGI)getHttpChannel().getHttpDestination().getHttpClient().getTransport();
Pattern uriPattern = transport.getURIPattern();
Matcher matcher = uriPattern.matcher(uri.toString());
// TODO: what if the URI does not match ? Here is kinda too late to abort the request ?
// TODO: perhaps this works in conjuntion with the ProxyServlet, which is mapped to the same URI regexp
// TODO: so that if the call arrives here, we are sure it matches.
// headers.put(Headers.PATH_INFO, ???); // headers.put(Headers.PATH_INFO, ???);
// headers.put(Headers.PATH_TRANSLATED, ???); // headers.put(Headers.PATH_TRANSLATED, ???);
headers.put(FCGI.Headers.QUERY_STRING, uri.getQuery()); headers.put(FCGI.Headers.QUERY_STRING, uri.getQuery());
// TODO: the fields below are probably provided by ProxyServlet as X-Forwarded-*
// headers.put(Headers.REMOTE_ADDR, ???); // headers.put(Headers.REMOTE_ADDR, ???);
// headers.put(Headers.REMOTE_HOST, ???); // headers.put(Headers.REMOTE_HOST, ???);
// headers.put(Headers.REMOTE_USER, ???); // headers.put(Headers.REMOTE_USER, ???);
@ -70,11 +81,11 @@ public class HttpSenderOverFCGI extends HttpSender
// TODO: translate remaining HTTP header into the HTTP_* format // TODO: translate remaining HTTP header into the HTTP_* format
int request = getHttpChannel().getRequest(); int request = getHttpChannel().getRequest();
boolean noContent = !content.hasContent(); boolean hasContent = content.hasContent();
Generator.Result result = generator.generateRequestHeaders(request, headers, Generator.Result result = generator.generateRequestHeaders(request, headers,
noContent ? new Callback.Adapter() : callback); hasContent ? callback : new Callback.Adapter());
getHttpChannel().flush(result); getHttpChannel().flush(result);
if (noContent) if (!hasContent)
{ {
result = generator.generateRequestContent(request, null, true, callback); result = generator.generateRequestContent(request, null, true, callback);
getHttpChannel().flush(result); getHttpChannel().flush(result);