public class Server extends Tool implements java.lang.Runnable, ShutdownHandler
| Constructor and Description |
|---|
Server() |
Server(Service service,
java.lang.String... args)
Create a new server for the given service.
|
| Modifier and Type | Method and Description |
|---|---|
static Server |
createPgServer(java.lang.String... args)
Create a new PG server, but does not start it yet.
|
static Server |
createTcpServer(java.lang.String... args)
Create a new TCP server, but does not start it yet.
|
static Server |
createWebServer(java.lang.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.
|
java.lang.String |
getStatus()
Get the status of this server.
|
java.lang.String |
getURL()
Gets the URL of this server.
|
boolean |
isRunning(boolean traceError)
Checks if the server is running.
|
static void |
main(java.lang.String... args)
When running without options, -tcp, -web, -browser and -pg are started.
|
static void |
openBrowser(java.lang.String url)
Open a new browser tab or window with the given URL.
|
void |
run()
INTERNAL
|
void |
runTool(java.lang.String... args)
Run the tool with the given output stream and arguments.
|
void |
setShutdownHandler(ShutdownHandler shutdownHandler)
INTERNAL
|
void |
shutdown()
INTERNAL
|
static void |
shutdownTcpServer(java.lang.String url,
java.lang.String password,
boolean force,
boolean all)
Shutdown one or all TCP server.
|
Server |
start()
Tries to start the server.
|
static void |
startWebServer(java.sql.Connection conn)
Start a web server and a browser that uses the given connection.
|
static void |
startWebServer(java.sql.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, java.lang.String... args) throws java.sql.SQLException
service - the serviceargs - the command line argumentsjava.sql.SQLExceptionpublic static void main(java.lang.String... args)
throws java.sql.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 |
| [-webDaemon] | Use a daemon thread |
| [-webPort <port>] | The port (default: 8082) |
| [-webSSL] | Use encrypted (HTTPS) connections |
| [-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) |
| [-trace] | Print additional trace information (all servers) |
| [-key <from> <to>] | Allows to map a database name to another (all servers) |
args - the command line argumentsjava.sql.SQLExceptionpublic void runTool(java.lang.String... args)
throws java.sql.SQLException
Toolpublic static void shutdownTcpServer(java.lang.String url,
java.lang.String password,
boolean force,
boolean all)
throws java.sql.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
stoppedjava.sql.SQLExceptionpublic java.lang.String getStatus()
public static Server createWebServer(java.lang.String... args) throws java.sql.SQLException
Server server = Server.createWebServer("-trace").start();
Supported options are:
-webPort, -webSSL, -webAllowOthers, -webDaemon,
-trace, -ifExists, -baseDir, -properties.
See the main method for details.args - the argument listjava.sql.SQLExceptionpublic static Server createTcpServer(java.lang.String... args) throws java.sql.SQLException
Server server = Server.createTcpServer(
"-tcpPort", "9123", "-tcpAllowOthers").start();
Supported options are:
-tcpPort, -tcpSSL, -tcpPassword, -tcpAllowOthers, -tcpDaemon,
-trace, -ifExists, -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 listjava.sql.SQLExceptionpublic static Server createPgServer(java.lang.String... args) throws java.sql.SQLException
Server server =
Server.createPgServer("-pgAllowOthers").start();
Supported options are:
-pgPort, -pgAllowOthers, -pgDaemon,
-trace, -ifExists, -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 listjava.sql.SQLExceptionpublic Server start() throws java.sql.SQLException
java.sql.SQLException - if the server could not be startedpublic boolean isRunning(boolean traceError)
traceError - if errors should be writtenpublic void stop()
public java.lang.String getURL()
public int getPort()
public void run()
run in interface java.lang.Runnablepublic void setShutdownHandler(ShutdownHandler shutdownHandler)
public void shutdown()
shutdown in interface ShutdownHandlerpublic Service getService()
public static void openBrowser(java.lang.String url)
throws java.lang.Exception
url - the URL to openjava.lang.Exceptionpublic static void startWebServer(java.sql.Connection conn)
throws java.sql.SQLException
conn - the database connection (the database must be open)java.sql.SQLExceptionpublic static void startWebServer(java.sql.Connection conn,
boolean ignoreProperties)
throws java.sql.SQLException
conn - the database connection (the database must be open)ignoreProperties - if true properties from
.h2.server.properties will be ignoredjava.sql.SQLException