提交 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;
import org.h2.util.JdbcUtils;
import org.h2.util.NetUtils;
import org.h2.util.New;
import org.h2.util.StringUtils;
/**
* The TCP server implements the native H2 database server protocol.
......@@ -55,6 +56,7 @@ public class TcpServer implements Service {
private boolean trace;
private boolean ssl;
private boolean stop;
private ShutdownHandler shutdownHandler;
private ServerSocket serverSocket;
private Set<TcpServerThread> running = Collections.synchronizedSet(new HashSet<TcpServerThread>());
private String baseDir;
......@@ -100,6 +102,19 @@ public class TcpServer implements Service {
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.
*
......@@ -319,6 +334,7 @@ public class TcpServer implements Service {
} else if (shutdownMode == SHUTDOWN_FORCE) {
server.stop();
}
server.shutdown();
}
/**
......@@ -388,14 +404,12 @@ public class TcpServer implements Service {
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());
int idx = url.lastIndexOf(':');
if (idx >= 0) {
String p = url.substring(idx + 1);
idx = p.indexOf('/');
if (idx >= 0) {
p = p.substring(0, idx);
if (StringUtils.isNumber(p)) {
port = Integer.decode(p);
}
port = Integer.decode(p);
}
String db = getManagementDbName(port);
try {
......
......@@ -182,6 +182,7 @@ ShutdownHandler {
if (printStatus) {
out.println(tcp.getStatus());
}
tcp.setShutdownHandler(this);
} catch (SQLException e) {
printProblem(e, tcp);
if (startException == null) {
......
......@@ -27,6 +27,7 @@ import org.h2.util.JdbcUtils;
import org.h2.util.New;
import org.h2.util.ScriptReader;
import org.h2.util.SortedProperties;
import org.h2.util.StringUtils;
import org.h2.util.Tool;
import org.h2.util.Utils;
......@@ -292,7 +293,7 @@ public class Shell extends Tool implements Runnable {
} else {
boolean addToHistory = true;
if (statement == null) {
if (isNumber(line)) {
if (StringUtils.isNumber(line)) {
int pos = Integer.parseInt(line);
if (pos == 0 || pos > history.size()) {
println("Not found");
......@@ -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 {
String url = "jdbc:h2:~/test";
String user = "sa";
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论