work in progress on EWYK HTTP

This commit is contained in:
Greg Wilkins 2014-12-21 20:56:36 +01:00
parent e363dd41c2
commit 2a584613ee
12 changed files with 73 additions and 34 deletions

View File

@ -117,7 +117,14 @@ public class ByteArrayEndPoint extends AbstractEndPoint
if (_closed)
throw new ClosedChannelException();
if (BufferUtil.hasContent(_in) || _in==null)
getScheduler().schedule(new Runnable(){public void run(){getFillInterest().fillable();}},1,TimeUnit.MILLISECONDS);
getScheduler().schedule(new Runnable()
{
public void run()
{
if (!_closed && _in!=null)
getFillInterest().fillable();
}
},1,TimeUnit.MILLISECONDS);
}
/* ------------------------------------------------------------ */

View File

@ -294,6 +294,8 @@ public class HttpChannel implements Runnable, HttpOutput.Interceptor
switch(action)
{
case REQUEST_DISPATCH:
if (!_request.hasMetaData())
throw new IllegalStateException();
_request.setHandled(false);
_response.getHttpOutput().reopen();
_request.setDispatcherType(DispatcherType.REQUEST);

View File

@ -202,11 +202,20 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http
{
while (true)
{
// Fill the request buffer (if needed)
int filled = fillRequestBuffer();
// Parse the request buffer
boolean handle = parseRequestBuffer();
// handle
// Handle close parser
if (_parser.isClose())
{
close();
break;
}
// Handle channel event
if (handle)
{
boolean suspended = !_channel.handle();
@ -215,15 +224,13 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http
if (suspended || getEndPoint().getConnection() != this )
break;
}
else
// Continue or break?
else if (filled<=0)
{
// we break iteration ?
if (filled<=0)
{
if (filled==0)
fillInterested();
break;
}
if (filled==0)
fillInterested();
break;
}
}
}
@ -379,7 +386,6 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http
// Not in a race here with onFillable, because it has given up control before calling handle.
// in a slight race with #completed, but not sure what to do with that anyway.
releaseRequestBuffer();
if (_chunk!=null)
_bufferPool.release(_chunk);
_chunk=null;

View File

@ -1575,7 +1575,7 @@ public class Request implements HttpServletRequest
*/
public HttpURI getHttpURI()
{
return _metadata.getURI();
return _metadata==null?null:_metadata.getURI();
}
/* ------------------------------------------------------------ */
@ -1786,6 +1786,12 @@ public class Request implements HttpServletRequest
setPathInfo(info);
}
/* ------------------------------------------------------------ */
public boolean hasMetaData()
{
return _metadata!=null;
}
/* ------------------------------------------------------------ */
protected void recycle()

View File

@ -479,9 +479,7 @@ public class Server extends HandlerWrapper implements Attributes
//remote stop commands as we are stopped already
ShutdownMonitor.deregister(this);
mex.ifExceptionThrow();
}
/* ------------------------------------------------------------ */

View File

@ -44,19 +44,22 @@ public class GracefulStopTest
@Before
public void setup() throws Exception
{
server = new Server(0);
server = new Server(0)
{
};
StatisticsHandler stats = new StatisticsHandler();
TestHandler test=new TestHandler();
server.setHandler(stats);
stats.setHandler(test);
server.setStopTimeout(10 * 1000);
server.start();
}
@Test
public void testGraceful() throws Exception
{
server.setStopTimeout(10 * 1000);
server.start();
new Thread()
{
@Override
@ -80,12 +83,16 @@ public class GracefulStopTest
String out = IO.toString(socket.getInputStream());
Assert.assertThat(out,Matchers.containsString("200 OK"));
}
server.join();
}
@Test
public void testGracefulTimout() throws Exception
public void testGracefulTimeout() throws Exception
{
server.setStopTimeout(100);
server.start();
new Thread()
{
@Override
@ -96,7 +103,7 @@ public class GracefulStopTest
TimeUnit.SECONDS.sleep(1);
server.stop();
}
catch (Exception e)
catch (Throwable e)
{
//e.printStackTrace();
}
@ -109,6 +116,8 @@ public class GracefulStopTest
String out = IO.toString(socket.getInputStream());
Assert.assertEquals("",out);
}
server.join();
}
private static class TestHandler extends AbstractHandler

View File

@ -1443,8 +1443,6 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
}.start();
String resps = readResponse(client);
System.err.println(resps);
int offset = 0;
for (int i = 0; i < (REQS + 1); i++)

View File

@ -37,14 +37,17 @@ import java.util.concurrent.TimeUnit;
import org.eclipse.jetty.http.HttpFields;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.server.handler.HandlerCollection;
import org.eclipse.jetty.toolchain.test.AdvancedRunner;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
*
*/
@RunWith(AdvancedRunner.class)
public class PartialRFC2616Test
{
private Server server;

View File

@ -18,11 +18,14 @@
package org.eclipse.jetty.server;
import org.eclipse.jetty.toolchain.test.AdvancedRunner;
import org.junit.Before;
import org.junit.runner.RunWith;
/**
* HttpServer Tester.
*/
@RunWith(AdvancedRunner.class)
public class SelectChannelServerTest extends HttpServerTestBase
{
@Before

View File

@ -209,7 +209,8 @@ public abstract class AbstractLifeCycle implements LifeCycle
private void setFailed(Throwable th)
{
_state = __FAILED;
LOG.warn(FAILED+" " + this+": "+th,th);
if (LOG.isDebugEnabled())
LOG.warn(FAILED+" " + this+": "+th,th);
for (Listener listener : _listeners)
listener.lifeCycleFailure(this,th);
}

View File

@ -599,20 +599,20 @@ public class StdErrLog extends AbstractLogger
{
buffer.append(_abbrevname);
}
p=buffer.length()-p-28;
p=buffer.length()-p-25;
if (p>0)
buffer.setLength(buffer.length()-p);
else
buffer.append(" ",0,-p);
buffer.append(" ",0,-p);
buffer.append(':');
p=buffer.length();
buffer.append(Thread.currentThread().getName());
p=buffer.length()-p-18;
p=buffer.length()-p-20;
if (p>0)
buffer.setLength(buffer.length()-p);
else
buffer.append(" ",0,-p);
buffer.append(" ",0,-p);
buffer.append(':');
if (_source)
@ -644,6 +644,8 @@ public class StdErrLog extends AbstractLogger
break;
}
}
buffer.append(' ');
}
private void format(StringBuilder builder, String msg, Object... args)

View File

@ -88,18 +88,22 @@ public interface ExecutionStrategy
/**
* <p>A strategy where the caller thread produces a task, then arranges another
* thread to continue production, and then runs the task.</p>
* <p>The phrase 'eat what you kill' comes from the hunting ethic that says a person
* should not kill anything he or she does not plan on eating. It was taken up in its
* more general sense by lawyers, who used it to mean that an individuals earnings
* should be based on how much business that person brings to the firm and the phrase
* is now quite common throughout the business world.</p>
* thread to continue production, and then runs the task.
* </p>
* <p>The strategy is also known by the phrase 'eat what you kill', which comes from
* the hunting ethic that says a person should not kill anything he or she does not
* plan on eating. It was taken up in its more general sense by lawyers, who used it
* to mean that an individuals earnings should be based on how much business that
* person brings to the firm and the phrase is now quite common throughout the
* business world.
* </p>
* <p>In this case, the phrase is used to mean that a thread should not produce a
* task that it does not intend to run. By making producers run the task that they
* have just produced avoids execution delays and avoids parallel slow down by running
* the task in the same core, with good chances of having a hot CPU cache. It also
* avoids the creation of a queue of produced tasks that the system does not yet have
* capacity to consume, which can save memory and exert back pressure on producers.</p>
* capacity to consume, which can save memory and exert back pressure on producers.
* </p>
*/
public static class ExecuteProduceRun implements ExecutionStrategy, Runnable
{