Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Bartel2013-07-10 07:18:20 +0000
committerJan Bartel2013-07-10 07:21:43 +0000
commitfde47b10833167284176939ac524f75ae9315ac0 (patch)
treeb63e80a01ee54bbe0ff484ae915d4460907372a4
parent809c3aa472f39f7003c588e3b3aa11ca688f58e9 (diff)
downloadorg.eclipse.jetty.project-fde47b10833167284176939ac524f75ae9315ac0.tar.gz
org.eclipse.jetty.project-fde47b10833167284176939ac524f75ae9315ac0.tar.xz
org.eclipse.jetty.project-fde47b10833167284176939ac524f75ae9315ac0.zip
412637 ShutdownMonitorThread already started
-rw-r--r--jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyStopMojo.java30
-rw-r--r--jetty-server/src/main/java/org/eclipse/jetty/server/ShutdownMonitor.java35
2 files changed, 58 insertions, 7 deletions
diff --git a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyStopMojo.java b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyStopMojo.java
index 99854467cd..2270d7a1e1 100644
--- a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyStopMojo.java
+++ b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyStopMojo.java
@@ -18,6 +18,8 @@
package org.eclipse.jetty.maven.plugin;
+import java.io.InputStreamReader;
+import java.io.LineNumberReader;
import java.io.OutputStream;
import java.net.ConnectException;
import java.net.InetAddress;
@@ -54,6 +56,13 @@ public class JettyStopMojo extends AbstractMojo
* @required
*/
protected String stopKey;
+
+ /**
+ * Max time in seconds that the plugin will wait for confirmation that jetty has stopped.
+ * @parameter
+ */
+ protected int stopWait;
+
public void execute() throws MojoExecutionException, MojoFailureException
{
@@ -66,10 +75,29 @@ public class JettyStopMojo extends AbstractMojo
{
Socket s=new Socket(InetAddress.getByName("127.0.0.1"),stopPort);
s.setSoLinger(false, 0);
-
+
OutputStream out=s.getOutputStream();
out.write((stopKey+"\r\nstop\r\n").getBytes());
out.flush();
+
+ if (stopWait > 0)
+ {
+ s.setSoTimeout(stopWait * 1000);
+ s.getInputStream();
+
+ System.err.printf("Waiting %d seconds for jetty to stop%n",stopWait);
+ LineNumberReader lin = new LineNumberReader(new InputStreamReader(s.getInputStream()));
+ String response;
+ boolean stopped = false;
+ while (!stopped && ((response = lin.readLine()) != null))
+ {
+ if ("Stopped".equals(response))
+ {
+ stopped = true;
+ System.err.println("Server reports itself as Stopped");
+ }
+ }
+ }
s.close();
}
catch (ConnectException e)
diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/ShutdownMonitor.java b/jetty-server/src/main/java/org/eclipse/jetty/server/ShutdownMonitor.java
index e789d389a5..ded5bdc4fe 100644
--- a/jetty-server/src/main/java/org/eclipse/jetty/server/ShutdownMonitor.java
+++ b/jetty-server/src/main/java/org/eclipse/jetty/server/ShutdownMonitor.java
@@ -102,6 +102,13 @@ public class ShutdownMonitor
// Graceful Shutdown
debug("Issuing graceful shutdown..");
ShutdownThread.getInstance().run();
+
+ //Stop accepting any more
+ close(serverSocket);
+ serverSocket = null;
+
+ //Shutdown input from client
+ shutdownInput(socket);
// Reply to client
debug("Informing client that we are stopped.");
@@ -109,11 +116,10 @@ public class ShutdownMonitor
out.flush();
// Shutdown Monitor
- debug("Shutting down monitor");
+ socket.shutdownOutput();
close(socket);
- socket = null;
- close(serverSocket);
- serverSocket = null;
+ socket = null;
+ debug("Shutting down monitor");
if (exitVm)
{
@@ -248,7 +254,7 @@ public class ShutdownMonitor
}
catch (IOException ignore)
{
- /* ignore */
+ debug(ignore);
}
}
@@ -265,10 +271,27 @@ public class ShutdownMonitor
}
catch (IOException ignore)
{
- /* ignore */
+ debug(ignore);
}
}
+
+ private void shutdownInput(Socket socket)
+ {
+ if (socket == null)
+ return;
+
+ try
+ {
+ socket.shutdownInput();
+ }
+ catch (IOException ignore)
+ {
+ debug(ignore);
+ }
+ }
+
+
private void debug(String format, Object... args)
{
if (DEBUG)

Back to the top