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

Can now start a TCP server with port 0 (automatically select a port).

上级 ad836b86
...@@ -75,4 +75,12 @@ public interface Service { ...@@ -75,4 +75,12 @@ public interface Service {
* @return the type * @return the type
*/ */
String getType(); String getType();
/**
* Gets the port this service is listening on.
*
* @return the port
*/
int getPort();
} }
...@@ -64,7 +64,6 @@ public class TcpServer implements Service { ...@@ -64,7 +64,6 @@ public class TcpServer implements Service {
private ServerSocket serverSocket; private ServerSocket serverSocket;
private Set running = Collections.synchronizedSet(new HashSet()); private Set running = Collections.synchronizedSet(new HashSet());
private String baseDir; private String baseDir;
private String url;
private boolean allowOthers; private boolean allowOthers;
private boolean ifExists; private boolean ifExists;
private Connection managementDb; private Connection managementDb;
...@@ -187,11 +186,14 @@ public class TcpServer implements Service { ...@@ -187,11 +186,14 @@ public class TcpServer implements Service {
} }
} }
org.h2.Driver.load(); org.h2.Driver.load();
url = (ssl ? "ssl" : "tcp") + "://" + NetUtils.getLocalAddress() + ":" + port;
} }
public String getURL() { public String getURL() {
return url; return (ssl ? "ssl" : "tcp") + "://" + NetUtils.getLocalAddress() + ":" + port;
}
public int getPort() {
return port;
} }
/** /**
...@@ -210,6 +212,7 @@ public class TcpServer implements Service { ...@@ -210,6 +212,7 @@ public class TcpServer implements Service {
public synchronized void start() throws SQLException { public synchronized void start() throws SQLException {
serverSocket = NetUtils.createServerSocket(port, ssl); serverSocket = NetUtils.createServerSocket(port, ssl);
port = serverSocket.getLocalPort();
initManagementDb(); initManagementDb();
} }
......
...@@ -246,12 +246,17 @@ public class FtpServer implements Service { ...@@ -246,12 +246,17 @@ public class FtpServer implements Service {
public String getURL() { public String getURL() {
return "ftp://" + NetUtils.getLocalAddress() + ":" + port; return "ftp://" + NetUtils.getLocalAddress() + ":" + port;
} }
public int getPort() {
return port;
}
public void start() throws SQLException { public void start() throws SQLException {
fs = FileSystem.getInstance(root); fs = FileSystem.getInstance(root);
root = fs.normalize(root); root = fs.normalize(root);
fs.mkdirs(root); fs.mkdirs(root);
serverSocket = NetUtils.createServerSocket(port, false); serverSocket = NetUtils.createServerSocket(port, false);
port = serverSocket.getLocalPort();
} }
public void stop() { public void stop() {
......
...@@ -43,7 +43,6 @@ public class PgServer implements Service { ...@@ -43,7 +43,6 @@ public class PgServer implements Service {
private ServerSocket serverSocket; private ServerSocket serverSocket;
private Set running = Collections.synchronizedSet(new HashSet()); private Set running = Collections.synchronizedSet(new HashSet());
private String baseDir; private String baseDir;
private String url;
private boolean allowOthers; private boolean allowOthers;
private boolean ifExists; private boolean ifExists;
...@@ -77,8 +76,6 @@ public class PgServer implements Service { ...@@ -77,8 +76,6 @@ public class PgServer implements Service {
} }
} }
org.h2.Driver.load(); org.h2.Driver.load();
url = "pg://" + NetUtils.getLocalAddress() + ":" + port;
// int testing; // int testing;
// log = true; // log = true;
} }
...@@ -119,7 +116,11 @@ public class PgServer implements Service { ...@@ -119,7 +116,11 @@ public class PgServer implements Service {
} }
public String getURL() { public String getURL() {
return url; return "pg://" + NetUtils.getLocalAddress() + ":" + port;
}
public int getPort() {
return port;
} }
private boolean allow(Socket socket) { private boolean allow(Socket socket) {
......
...@@ -464,7 +464,7 @@ public class WebServer implements Service { ...@@ -464,7 +464,7 @@ public class WebServer implements Service {
return ssl; return ssl;
} }
int getPort() { public int getPort() {
return port; return port;
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论