Merge remote-tracking branch 'origin/master'

This commit is contained in:
Simone Bordet 2011-11-18 12:45:05 +01:00
commit 712d250d3e
5 changed files with 82 additions and 22 deletions

View File

@ -162,6 +162,8 @@ public class SelectChannelEndPoint extends ChannelEndPoint implements AsyncEndPo
// we are not interested in further selecting
_key.interestOps(0);
if (!_dispatched)
updateKey();
return;
}

View File

@ -585,15 +585,6 @@ public abstract class SelectorManager extends AbstractLifeCycle implements Dumpa
// Log and dump some status
_paused=true;
LOG.warn("Selector {} is too busy, pausing!",this);
final SelectSet set = this;
SelectorManager.this.dispatch(
new Runnable(){
public void run()
{
System.err.println(set+":\n"+set.dump());
}
public String toString() {return "Dump-"+super.toString();}
});
}
}
}
@ -991,6 +982,16 @@ public abstract class SelectorManager extends AbstractLifeCycle implements Dumpa
dumpto.add(key.attachment()+" - - ");
}
}
/* ------------------------------------------------------------ */
public String toString()
{
String s=super.toString()+" "+SelectorManager.this.getState();
Selector selector=_selector;
if (selector!=null && selector.isOpen())
s+=",k="+selector.keys().size()+",s="+selector.selectedKeys().size();
return s;
}
}
/* ------------------------------------------------------------ */

View File

@ -238,6 +238,21 @@ public class SslConnection extends AbstractConnection implements AsyncConnection
}
/* ------------------------------------------------------------ */
@Override
public void onIdleExpired()
{
try
{
_sslEndPoint.shutdownOutput();
}
catch (IOException e)
{
LOG.warn(e);
super.onIdleExpired();
}
}
/* ------------------------------------------------------------ */
public void onInputShutdown() throws IOException
{

View File

@ -69,6 +69,8 @@ public class ShutdownHandler extends AbstractHandler
private boolean _exitJvm = false;
/**
* Creates a listener that lets the server be shut down remotely (but only from localhost).
*
@ -110,6 +112,10 @@ public class ShutdownHandler extends AbstractHandler
LOG.info("Shutting down by request from " + getRemoteAddr(request));
new Thread()
{
public void run ()
{
try
{
shutdownServer();
@ -123,6 +129,8 @@ public class ShutdownHandler extends AbstractHandler
throw new RuntimeException("Shutting down server",e);
}
}
}.start();
}
private boolean requestFromLocalhost(HttpServletRequest request)
{

View File

@ -14,12 +14,18 @@ package org.eclipse.jetty.server.handler;
//========================================================================
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.util.component.AbstractLifeCycle;
import org.eclipse.jetty.util.component.LifeCycle;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
@ -48,7 +54,35 @@ public class ShutdownHandlerTest
public void shutdownServerWithCorrectTokenAndIPTest() throws Exception
{
setDefaultExpectations();
final CountDownLatch countDown = new CountDownLatch(1);
server.addLifeCycleListener(new AbstractLifeCycle.Listener ()
{
public void lifeCycleStarting(LifeCycle event)
{
}
public void lifeCycleStarted(LifeCycle event)
{
}
public void lifeCycleFailure(LifeCycle event, Throwable cause)
{
}
public void lifeCycleStopping(LifeCycle event)
{
}
public void lifeCycleStopped(LifeCycle event)
{
countDown.countDown();
}
});
shutdownHandler.handle("/shutdown",null,request,response);
boolean stopped = countDown.await(1000, TimeUnit.MILLISECONDS); //wait up to 1 sec to stop
assertTrue("Server lifecycle stop listener called", stopped);
assertEquals("Server should be stopped","STOPPED",server.getState());
}