提交 625cbac8 authored 作者: Thomas Mueller's avatar Thomas Mueller

Server tool: the tcpShutdown feature now also stops other servers (web server…

Server tool: the tcpShutdown feature now also stops other servers (web server and PostgreSQL server).
上级 8d894677
...@@ -29,6 +29,7 @@ import org.h2.message.TraceSystem; ...@@ -29,6 +29,7 @@ import org.h2.message.TraceSystem;
import org.h2.util.JdbcUtils; import org.h2.util.JdbcUtils;
import org.h2.util.NetUtils; import org.h2.util.NetUtils;
import org.h2.util.New; import org.h2.util.New;
import org.h2.util.StringUtils;
/** /**
* The TCP server implements the native H2 database server protocol. * The TCP server implements the native H2 database server protocol.
...@@ -55,6 +56,7 @@ public class TcpServer implements Service { ...@@ -55,6 +56,7 @@ public class TcpServer implements Service {
private boolean trace; private boolean trace;
private boolean ssl; private boolean ssl;
private boolean stop; private boolean stop;
private ShutdownHandler shutdownHandler;
private ServerSocket serverSocket; private ServerSocket serverSocket;
private Set<TcpServerThread> running = Collections.synchronizedSet(new HashSet<TcpServerThread>()); private Set<TcpServerThread> running = Collections.synchronizedSet(new HashSet<TcpServerThread>());
private String baseDir; private String baseDir;
...@@ -100,6 +102,19 @@ public class TcpServer implements Service { ...@@ -100,6 +102,19 @@ public class TcpServer implements Service {
SERVERS.put(port, this); SERVERS.put(port, this);
} }
/**
* Shut down this server.
*/
void shutdown() {
if (shutdownHandler != null) {
shutdownHandler.shutdown();
}
}
public void setShutdownHandler(ShutdownHandler shutdownHandler) {
this.shutdownHandler = shutdownHandler;
}
/** /**
* Add a connection to the management database. * Add a connection to the management database.
* *
...@@ -319,6 +334,7 @@ public class TcpServer implements Service { ...@@ -319,6 +334,7 @@ public class TcpServer implements Service {
} else if (shutdownMode == SHUTDOWN_FORCE) { } else if (shutdownMode == SHUTDOWN_FORCE) {
server.stop(); server.stop();
} }
server.shutdown();
} }
/** /**
...@@ -388,15 +404,13 @@ public class TcpServer implements Service { ...@@ -388,15 +404,13 @@ public class TcpServer implements Service {
public static synchronized void shutdown(String url, String password, boolean force, boolean all) throws SQLException { public static synchronized void shutdown(String url, String password, boolean force, boolean all) throws SQLException {
try { try {
int port = Constants.DEFAULT_TCP_PORT; int port = Constants.DEFAULT_TCP_PORT;
int idx = url.indexOf(':', "jdbc:h2:".length()); int idx = url.lastIndexOf(':');
if (idx >= 0) { if (idx >= 0) {
String p = url.substring(idx + 1); String p = url.substring(idx + 1);
idx = p.indexOf('/'); if (StringUtils.isNumber(p)) {
if (idx >= 0) {
p = p.substring(0, idx);
}
port = Integer.decode(p); port = Integer.decode(p);
} }
}
String db = getManagementDbName(port); String db = getManagementDbName(port);
try { try {
org.h2.Driver.load(); org.h2.Driver.load();
......
...@@ -182,6 +182,7 @@ ShutdownHandler { ...@@ -182,6 +182,7 @@ ShutdownHandler {
if (printStatus) { if (printStatus) {
out.println(tcp.getStatus()); out.println(tcp.getStatus());
} }
tcp.setShutdownHandler(this);
} catch (SQLException e) { } catch (SQLException e) {
printProblem(e, tcp); printProblem(e, tcp);
if (startException == null) { if (startException == null) {
......
...@@ -27,6 +27,7 @@ import org.h2.util.JdbcUtils; ...@@ -27,6 +27,7 @@ import org.h2.util.JdbcUtils;
import org.h2.util.New; import org.h2.util.New;
import org.h2.util.ScriptReader; import org.h2.util.ScriptReader;
import org.h2.util.SortedProperties; import org.h2.util.SortedProperties;
import org.h2.util.StringUtils;
import org.h2.util.Tool; import org.h2.util.Tool;
import org.h2.util.Utils; import org.h2.util.Utils;
...@@ -292,7 +293,7 @@ public class Shell extends Tool implements Runnable { ...@@ -292,7 +293,7 @@ public class Shell extends Tool implements Runnable {
} else { } else {
boolean addToHistory = true; boolean addToHistory = true;
if (statement == null) { if (statement == null) {
if (isNumber(line)) { if (StringUtils.isNumber(line)) {
int pos = Integer.parseInt(line); int pos = Integer.parseInt(line);
if (pos == 0 || pos > history.size()) { if (pos == 0 || pos > history.size()) {
println("Not found"); println("Not found");
...@@ -342,18 +343,6 @@ public class Shell extends Tool implements Runnable { ...@@ -342,18 +343,6 @@ public class Shell extends Tool implements Runnable {
} }
} }
private boolean isNumber(String s) {
if (s.length() == 0) {
return false;
}
for (char c : s.toCharArray()) {
if (!Character.isDigit(c)) {
return false;
}
}
return true;
}
private void connect() throws IOException, SQLException { private void connect() throws IOException, SQLException {
String url = "jdbc:h2:~/test"; String url = "jdbc:h2:~/test";
String user = "sa"; String user = "sa";
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论