提交 f35d1435 authored 作者: Thomas Mueller's avatar Thomas Mueller

Server.shutdownTcpServer can now stop all TCP servers on this JVM.

上级 329a4137
......@@ -287,11 +287,19 @@ public class TcpServer implements Service {
* Stop a running server. This method is called via reflection from the
* STOP_SERVER function.
*
* @param port the port where the server runs
* @param password the password
* @param port the port where the server runs, or 0 for all running servers
* @param password the password (or null)
* @param shutdownMode the shutdown mode, SHUTDOWN_NORMAL or SHUTDOWN_FORCE.
*/
public static void stopServer(int port, String password, int shutdownMode) {
if (port == 0) {
for (int p : SERVERS.keySet().toArray(new Integer[0])) {
if (p != 0) {
stopServer(p, password, shutdownMode);
}
}
return;
}
TcpServer server = SERVERS.get(port);
if (server == null) {
return;
......@@ -374,8 +382,10 @@ public class TcpServer implements Service {
* @param url the database URL
* @param password the password
* @param force if the server should be stopped immediately
* @param all whether all TCP servers that are running in the JVM should be
* stopped
*/
public static synchronized void shutdown(String url, String password, boolean force) throws SQLException {
public static synchronized void shutdown(String url, String password, boolean force, boolean all) throws SQLException {
try {
int port = Constants.DEFAULT_TCP_PORT;
int idx = url.indexOf(':', "jdbc:h2:".length());
......@@ -399,7 +409,7 @@ public class TcpServer implements Service {
try {
conn = DriverManager.getConnection("jdbc:h2:" + url + "/" + db, "sa", password);
prep = conn.prepareStatement("CALL STOP_SERVER(?, ?, ?)");
prep.setInt(1, port);
prep.setInt(1, all ? 0 : port);
prep.setString(2, password);
prep.setInt(3, force ? SHUTDOWN_FORCE : SHUTDOWN_NORMAL);
try {
......
......@@ -201,7 +201,7 @@ public class Server extends Tool implements Runnable, ShutdownHandler {
// TODO server: maybe use one single properties file?
if (tcpShutdown) {
out.println("Shutting down TCP Server at " + tcpShutdownServer);
shutdownTcpServer(tcpShutdownServer, tcpPassword, tcpShutdownForce);
shutdownTcpServer(tcpShutdownServer, tcpPassword, tcpShutdownForce, false);
}
if (webStart) {
web = createWebServer(args);
......@@ -236,7 +236,7 @@ public class Server extends Tool implements Runnable, ShutdownHandler {
}
/**
* Shutdown a TCP server. If force is set to false, the server will not
* Shutdown one or all TCP server. If force is set to false, the server will not
* allow new connections, but not kill existing connections, instead it will
* stop if the last connection is closed. If force is set to true, existing
* connections are killed. After calling the method with force=false, it is
......@@ -244,17 +244,18 @@ public class Server extends Tool implements Runnable, ShutdownHandler {
* not allowed. Example:
*
* <pre>
* Server.shutdownTcpServer(&quot;tcp://localhost:9094&quot;, password, true);
* Server.shutdownTcpServer(
* &quot;tcp://localhost:9094&quot;, password, true, false);
* </pre>
*
* @param url example: tcp://localhost:9094
* @param password the password to use ("" for no password)
* @param force the shutdown (don't wait)
* @throws ClassNotFoundException
* @throws SQLException
* @param all whether all TCP servers that are running in the JVM
* should be stopped
*/
public static void shutdownTcpServer(String url, String password, boolean force) throws SQLException {
TcpServer.shutdown(url, password, force);
public static void shutdownTcpServer(String url, String password, boolean force, boolean all) throws SQLException {
TcpServer.shutdown(url, password, force, all);
}
/**
......
......@@ -19,6 +19,6 @@ public class ShutdownServer {
* @param args the command line parameters
*/
public static void main(String... args) throws Exception {
org.h2.tools.Server.shutdownTcpServer("tcp://localhost:9094", "", false);
org.h2.tools.Server.shutdownTcpServer("tcp://localhost:9094", "", false, false);
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论