mirror of
https://github.com/jetty/jetty.project.git
synced 2025-02-28 19:09:10 +00:00
Issue #3440 Stop on Unavailable
+ Any schedulers created are named (for ease of debug) and daemon so they do not stop the JVM exiting. + If the server.doStart() fails, it calls server.doStop to ensure connectors are stopped, ports are free etc. + cleanup of addBean handling of scheduler in proxy Signed-off-by: Greg Wilkins <gregw@webtide.com>
This commit is contained in:
parent
7bb1adb798
commit
375ad81f4b
@ -98,7 +98,7 @@ public class LikeJettyXml
|
||||
Server server = new Server(threadPool);
|
||||
|
||||
// Scheduler
|
||||
server.addBean(new ScheduledExecutorScheduler());
|
||||
server.addBean(new ScheduledExecutorScheduler(null,true));
|
||||
|
||||
// HTTP Configuration
|
||||
HttpConfiguration http_config = new HttpConfiguration();
|
||||
|
@ -23,7 +23,6 @@ import java.lang.management.ManagementFactory;
|
||||
|
||||
import org.eclipse.jetty.jmx.MBeanContainer;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.server.handler.AllowSymLinkAliasChecker;
|
||||
import org.eclipse.jetty.webapp.WebAppContext;
|
||||
|
||||
public class OneWebApp
|
||||
@ -58,11 +57,11 @@ public class OneWebApp
|
||||
// the server so it is aware of where to send the appropriate requests.
|
||||
server.setHandler(webapp);
|
||||
|
||||
// Start things up!
|
||||
// Start things up!
|
||||
server.start();
|
||||
|
||||
server.dumpStdErr();
|
||||
|
||||
|
||||
// The use of server.join() the will make the current thread join and
|
||||
// wait until the server is done executing.
|
||||
// See http://docs.oracle.com/javase/7/docs/api/java/lang/Thread.html#join()
|
||||
|
@ -44,7 +44,6 @@ import org.eclipse.jetty.io.Connection;
|
||||
import org.eclipse.jetty.io.EndPoint;
|
||||
import org.eclipse.jetty.io.ManagedSelector;
|
||||
import org.eclipse.jetty.io.MappedByteBufferPool;
|
||||
import org.eclipse.jetty.io.SelectChannelEndPoint;
|
||||
import org.eclipse.jetty.io.SelectorManager;
|
||||
import org.eclipse.jetty.io.SocketChannelEndPoint;
|
||||
import org.eclipse.jetty.server.Handler;
|
||||
@ -56,7 +55,6 @@ import org.eclipse.jetty.util.BufferUtil;
|
||||
import org.eclipse.jetty.util.Callback;
|
||||
import org.eclipse.jetty.util.HostPort;
|
||||
import org.eclipse.jetty.util.Promise;
|
||||
import org.eclipse.jetty.util.TypeUtil;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
import org.eclipse.jetty.util.thread.ScheduledExecutorScheduler;
|
||||
@ -106,6 +104,7 @@ public class ConnectHandler extends HandlerWrapper
|
||||
|
||||
public void setScheduler(Scheduler scheduler)
|
||||
{
|
||||
updateBean(this.scheduler,scheduler);
|
||||
this.scheduler = scheduler;
|
||||
}
|
||||
|
||||
@ -116,6 +115,7 @@ public class ConnectHandler extends HandlerWrapper
|
||||
|
||||
public void setByteBufferPool(ByteBufferPool bufferPool)
|
||||
{
|
||||
updateBean(this.bufferPool, bufferPool);
|
||||
this.bufferPool = bufferPool;
|
||||
}
|
||||
|
||||
@ -168,10 +168,18 @@ public class ConnectHandler extends HandlerWrapper
|
||||
executor = getServer().getThreadPool();
|
||||
|
||||
if (scheduler == null)
|
||||
addBean(scheduler = new ScheduledExecutorScheduler());
|
||||
{
|
||||
scheduler = getServer().getBean(Scheduler.class);
|
||||
if (scheduler == null)
|
||||
scheduler = new ScheduledExecutorScheduler(String.format("Proxy-Scheduler-%x", hashCode()), true);
|
||||
addBean(scheduler);
|
||||
}
|
||||
|
||||
if (bufferPool == null)
|
||||
addBean(bufferPool = new MappedByteBufferPool());
|
||||
{
|
||||
bufferPool = new MappedByteBufferPool();
|
||||
addBean(bufferPool);
|
||||
}
|
||||
|
||||
addBean(selector = newSelectorManager());
|
||||
selector.setConnectTimeout(getConnectTimeout());
|
||||
|
@ -183,7 +183,7 @@ public abstract class AbstractConnector extends ContainerLifeCycle implements Co
|
||||
_executor=executor!=null?executor:_server.getThreadPool();
|
||||
if (scheduler==null)
|
||||
scheduler=_server.getBean(Scheduler.class);
|
||||
_scheduler=scheduler!=null?scheduler:new ScheduledExecutorScheduler();
|
||||
_scheduler=scheduler!=null?scheduler:new ScheduledExecutorScheduler(String.format("Connector-Scheduler-%x",hashCode()),true);
|
||||
if (pool==null)
|
||||
pool=_server.getBean(ByteBufferPool.class);
|
||||
_byteBufferPool = pool!=null?pool:new ArrayByteBufferPool();
|
||||
|
@ -402,7 +402,18 @@ public class Server extends HandlerWrapper implements Attributes
|
||||
if (isDumpAfterStart())
|
||||
dumpStdErr();
|
||||
|
||||
mex.ifExceptionThrow();
|
||||
if (mex.size()>0)
|
||||
{
|
||||
try
|
||||
{
|
||||
doStop();
|
||||
}
|
||||
catch(Throwable e)
|
||||
{
|
||||
mex.add(e);
|
||||
}
|
||||
mex.ifExceptionThrow();
|
||||
}
|
||||
|
||||
LOG.info(String.format("Started @%dms",Uptime.getUptime()));
|
||||
}
|
||||
|
@ -1148,7 +1148,7 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu
|
||||
case UNAVAILABLE:
|
||||
baseRequest.setHandled(true);
|
||||
response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
|
||||
return false;
|
||||
return true;
|
||||
default:
|
||||
if ((DispatcherType.REQUEST.equals(dispatch) && baseRequest.isHandled()))
|
||||
return false;
|
||||
|
@ -121,7 +121,7 @@ public class HouseKeeper extends AbstractLifeCycle
|
||||
|
||||
if (_scheduler == null)
|
||||
{
|
||||
_scheduler = new ScheduledExecutorScheduler();
|
||||
_scheduler = new ScheduledExecutorScheduler(String.format("Session-HouseKeeper-%x",hashCode()),true);
|
||||
_ownScheduler = true;
|
||||
_scheduler.start();
|
||||
if (LOG.isDebugEnabled()) LOG.debug("Using own scheduler for scavenging");
|
||||
|
@ -18,8 +18,6 @@
|
||||
|
||||
package org.eclipse.jetty.server.session;
|
||||
|
||||
import static java.lang.Math.round;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
@ -67,6 +65,8 @@ import org.eclipse.jetty.util.thread.Locker.Lock;
|
||||
import org.eclipse.jetty.util.thread.ScheduledExecutorScheduler;
|
||||
import org.eclipse.jetty.util.thread.Scheduler;
|
||||
|
||||
import static java.lang.Math.round;
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* SessionHandler.
|
||||
@ -523,10 +523,9 @@ public class SessionHandler extends ScopedHandler
|
||||
_scheduler = server.getBean(Scheduler.class);
|
||||
if (_scheduler == null)
|
||||
{
|
||||
_scheduler = new ScheduledExecutorScheduler();
|
||||
_scheduler = new ScheduledExecutorScheduler(String.format("Session-Scheduler-%x",hashCode()), true);
|
||||
_ownScheduler = true;
|
||||
_scheduler.start();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -281,7 +281,7 @@ public class DoSFilter implements Filter
|
||||
{
|
||||
try
|
||||
{
|
||||
Scheduler result = new ScheduledExecutorScheduler();
|
||||
Scheduler result = new ScheduledExecutorScheduler(String.format("DoS-Scheduler-%x",hashCode()),true);
|
||||
result.start();
|
||||
return result;
|
||||
}
|
||||
|
@ -30,6 +30,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
@ -86,7 +87,7 @@ public class WebSocketServerFactory extends ContainerLifeCycle implements WebSoc
|
||||
private final ClassLoader contextClassloader;
|
||||
private final Map<Integer, WebSocketHandshake> handshakes = new HashMap<>();
|
||||
// TODO: obtain shared (per server scheduler, somehow)
|
||||
private final Scheduler scheduler = new ScheduledExecutorScheduler();
|
||||
private final Scheduler scheduler = new ScheduledExecutorScheduler(String.format("WebSocket-Scheduler-%x",hashCode()),true);
|
||||
private final List<WebSocketSessionListener> listeners = new ArrayList<>();
|
||||
private final String supportedVersions;
|
||||
private final WebSocketPolicy defaultPolicy;
|
||||
|
Loading…
x
Reference in New Issue
Block a user