mirror of
https://github.com/apache/lucene.git
synced 2025-02-16 15:06:41 +00:00
work harder to shutdown jetty for cases where jetty was started but could not bind to the port - not perfect yet, but works better than a std stop
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1378948 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
72d18af4a0
commit
d72c9dddba
@ -25,6 +25,7 @@ import java.util.Map;
|
|||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
import javax.servlet.DispatcherType;
|
import javax.servlet.DispatcherType;
|
||||||
|
import javax.servlet.Filter;
|
||||||
import javax.servlet.http.HttpServlet;
|
import javax.servlet.http.HttpServlet;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
@ -40,6 +41,7 @@ import org.eclipse.jetty.servlet.ServletContextHandler;
|
|||||||
import org.eclipse.jetty.util.component.LifeCycle;
|
import org.eclipse.jetty.util.component.LifeCycle;
|
||||||
import org.eclipse.jetty.util.log.Logger;
|
import org.eclipse.jetty.util.log.Logger;
|
||||||
import org.eclipse.jetty.util.thread.QueuedThreadPool;
|
import org.eclipse.jetty.util.thread.QueuedThreadPool;
|
||||||
|
import org.eclipse.jetty.util.thread.ThreadPool;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run solr using jetty
|
* Run solr using jetty
|
||||||
@ -47,8 +49,6 @@ import org.eclipse.jetty.util.thread.QueuedThreadPool;
|
|||||||
* @since solr 1.3
|
* @since solr 1.3
|
||||||
*/
|
*/
|
||||||
public class JettySolrRunner {
|
public class JettySolrRunner {
|
||||||
static Map<JettySolrRunner,Exception> RUNNING_JETTIES = new HashMap<JettySolrRunner,Exception>();
|
|
||||||
|
|
||||||
Server server;
|
Server server;
|
||||||
|
|
||||||
FilterHolder dispatchFilter;
|
FilterHolder dispatchFilter;
|
||||||
@ -208,7 +208,6 @@ public class JettySolrRunner {
|
|||||||
|
|
||||||
if (!server.isRunning()) {
|
if (!server.isRunning()) {
|
||||||
server.start();
|
server.start();
|
||||||
RUNNING_JETTIES.put(this, new RuntimeException());
|
|
||||||
}
|
}
|
||||||
synchronized (JettySolrRunner.this) {
|
synchronized (JettySolrRunner.this) {
|
||||||
int cnt = 0;
|
int cnt = 0;
|
||||||
@ -225,21 +224,32 @@ public class JettySolrRunner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void stop() throws Exception {
|
public void stop() throws Exception {
|
||||||
if (!server.isStopped() && !server.isStopping()) {
|
// we try and do a bunch of extra stop stuff because
|
||||||
server.stop();
|
// jetty doesn't like to stop if it started
|
||||||
RUNNING_JETTIES.remove(this);
|
// and ended up in a failure state (like when it cannot get the port)
|
||||||
|
if (server.getState().equals(Server.FAILED)) {
|
||||||
|
Connector[] connectors = server.getConnectors();
|
||||||
|
for (Connector connector : connectors) {
|
||||||
|
connector.stop();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Filter filter = dispatchFilter.getFilter();
|
||||||
|
ThreadPool threadPool = server.getThreadPool();
|
||||||
|
server.getServer().stop();
|
||||||
|
server.stop();
|
||||||
|
if (threadPool instanceof QueuedThreadPool) {
|
||||||
|
((QueuedThreadPool) threadPool).setMaxStopTimeMs(15000);
|
||||||
|
((QueuedThreadPool) threadPool).stop();
|
||||||
|
((QueuedThreadPool) threadPool).stop();
|
||||||
|
((QueuedThreadPool) threadPool).stop();
|
||||||
|
}
|
||||||
|
//server.destroy();
|
||||||
|
if (server.getState().equals(Server.FAILED)) {
|
||||||
|
filter.destroy();
|
||||||
|
}
|
||||||
|
|
||||||
server.join();
|
server.join();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void assertStoppedJetties() {
|
|
||||||
if (RUNNING_JETTIES.size() > 0) {
|
|
||||||
Iterator<Exception> stacktraces = RUNNING_JETTIES.values().iterator();
|
|
||||||
Exception cause = null;
|
|
||||||
cause = stacktraces.next();
|
|
||||||
throw new RuntimeException("Found a bad one!", cause);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the Local Port of the jetty Server.
|
* Returns the Local Port of the jetty Server.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user