public class Server extends Tool implements Runnable, ShutdownHandler
| 构造器和说明 |
|---|
Server() |
Server(Service service,
String... args)
Create a new server for the given service.
|
| 限定符和类型 | 方法和说明 |
|---|---|
static Server |
createPgServer(String... args)
Create a new PG server, but does not start it yet.
|
static Server |
createTcpServer(String... args)
Create a new TCP server, but does not start it yet.
|
static Server |
createWebServer(String... args)
Create a new web server, but does not start it yet.
|
int |
getPort()
Gets the port this server is listening on.
|
Service |
getService()
Get the service attached to this server.
|
String |
getStatus()
Get the status of this server.
|
String |
getURL()
Gets the URL of this server.
|
boolean |
isRunning(boolean traceError)
Checks if the server is running.
|
static void |
main(String... args)
When running without options, -tcp, -web, -browser and -pg are started.
|
static void |
openBrowser(String url)
Open a new browser tab or window with the given URL.
|
void |
run()
INTERNAL
|
void |
runTool(String... args)
Run the tool with the given output stream and arguments.
|
void |
setShutdownHandler(ShutdownHandler shutdownHandler)
INTERNAL
|
void |
shutdown()
INTERNAL
|
static void |
shutdownTcpServer(String url,
String password,
boolean force,
boolean all)
Shutdown one or all TCP server.
|
Server |
start()
Tries to start the server.
|
static void |
startWebServer(Connection conn)
Start a web server and a browser that uses the given connection.
|
static void |
startWebServer(Connection conn,
boolean ignoreProperties)
Start a web server and a browser that uses the given connection.
|
void |
stop()
Stops the server.
|
isOption, printNoDatabaseFilesFound, setOut, showUsage, showUsageAndThrowUnsupportedOption, throwUnsupportedOptionpublic Server()
public Server(Service service, String... args) throws SQLException
service - the serviceargs - the command line argumentsSQLException - on failurepublic static void main(String... args) throws SQLException
| [-help] or [-?] | Print the list of options |
| [-web] | Start the web server with the H2 Console |
| [-webAllowOthers] | Allow other computers to connect - see below |
| [-webExternalNames <names>] | The comma-separated list of external names and IP addresses of this server, used together with -webAllowOthers |
| [-webDaemon] | Use a daemon thread |
| [-webPort <port>] | The port (default: 8082) |
| [-webSSL] | Use encrypted (HTTPS) connections |
| [-webAdminPassword] | Password of DB Console administrator |
| [-browser] | Start a browser connecting to the web server |
| [-tcp] | Start the TCP server |
| [-tcpAllowOthers] | Allow other computers to connect - see below |
| [-tcpDaemon] | Use a daemon thread |
| [-tcpPort <port>] | The port (default: 9092) |
| [-tcpSSL] | Use encrypted (SSL) connections |
| [-tcpPassword <pwd>] | The password for shutting down a TCP server |
| [-tcpShutdown "<url>"] | Stop the TCP server; example: tcp://localhost |
| [-tcpShutdownForce] | Do not wait until all connections are closed |
| [-pg] | Start the PG server |
| [-pgAllowOthers] | Allow other computers to connect - see below |
| [-pgDaemon] | Use a daemon thread |
| [-pgPort <port>] | The port (default: 5435) |
| [-properties "<dir>"] | Server properties (default: ~, disable: null) |
| [-baseDir <dir>] | The base directory for H2 databases (all servers) |
| [-ifExists] | Only existing databases may be opened (all servers) |
| [-ifNotExists] | Databases are created when accessed |
| [-trace] | Print additional trace information (all servers) |
| [-key <from> <to>] | Allows to map a database name to another (all servers) |
args - the command line argumentsSQLException - on failurepublic void runTool(String... args) throws SQLException
ToolrunTool 在类中 Toolargs - the argument listSQLException - on failurepublic static void shutdownTcpServer(String url, String password, boolean force, boolean all) throws SQLException
Server.shutdownTcpServer("tcp://localhost:9094",
password, true, false);
url - example: tcp://localhost:9094password - the password to use ("" for no password)force - the shutdown (don't wait)all - whether all TCP servers that are running in the JVM should be
stoppedSQLException - on failurepublic String getStatus()
public static Server createWebServer(String... args) throws SQLException
Server server = Server.createWebServer("-trace").start();
Supported options are:
-webPort, -webSSL, -webAllowOthers, -webDaemon,
-trace, -ifExists, -ifNotExists, -baseDir, -properties.
See the main method for details.args - the argument listSQLException - on failurepublic static Server createTcpServer(String... args) throws SQLException
Server server = Server.createTcpServer(
"-tcpPort", "9123", "-tcpAllowOthers").start();
Supported options are:
-tcpPort, -tcpSSL, -tcpPassword, -tcpAllowOthers, -tcpDaemon,
-trace, -ifExists, -ifNotExists, -baseDir, -key.
See the main method for details.
If no port is specified, the default port is used if possible, and if this port is already used, a random port is used. Use getPort() or getURL() after starting to retrieve the port.
args - the argument listSQLException - on failurepublic static Server createPgServer(String... args) throws SQLException
Server server =
Server.createPgServer("-pgAllowOthers").start();
Supported options are:
-pgPort, -pgAllowOthers, -pgDaemon,
-trace, -ifExists, -ifNotExists, -baseDir, -key.
See the main method for details.
If no port is specified, the default port is used if possible, and if this port is already used, a random port is used. Use getPort() or getURL() after starting to retrieve the port.
args - the argument listSQLException - on failurepublic Server start() throws SQLException
SQLException - if the server could not be startedpublic boolean isRunning(boolean traceError)
traceError - if errors should be writtenpublic void stop()
public String getURL()
public int getPort()
public void setShutdownHandler(ShutdownHandler shutdownHandler)
shutdownHandler - to setpublic void shutdown()
shutdown 在接口中 ShutdownHandlerpublic Service getService()
public static void openBrowser(String url) throws Exception
url - the URL to openException - on failurepublic static void startWebServer(Connection conn) throws SQLException
conn - the database connection (the database must be open)SQLException - on failurepublic static void startWebServer(Connection conn, boolean ignoreProperties) throws SQLException
conn - the database connection (the database must be open)ignoreProperties - if true properties from
.h2.server.properties will be ignoredSQLException - on failureCopyright © 2022. All rights reserved.