412637 ShutdownMonitorThread already started

This commit is contained in:
Jan Bartel 2013-07-10 17:18:20 +10:00
parent 809c3aa472
commit fde47b1083
2 changed files with 58 additions and 7 deletions

View File

@ -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)

View File

@ -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)