org.h2.tools
Class Server

java.lang.Object
  extended by org.h2.util.Tool
      extended by org.h2.tools.Server
All Implemented Interfaces:
java.lang.Runnable, ShutdownHandler

public class Server
extends Tool
implements java.lang.Runnable, ShutdownHandler

Starts the H2 Console (web-) server, TCP, and PG server.


Field Summary
 
Fields inherited from class org.h2.util.Tool
out
 
Constructor Summary
Server()
           
Server(Service service, java.lang.String... args)
          Create a new server for the given service.
 
Method Summary
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.
 void run()
          INTERNAL
 void run(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)
          Shutdown a 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.
 void stop()
          Stops the server.
 
Methods inherited from class org.h2.util.Tool
printNoDatabaseFilesFound, readArgBoolean, setOut, showUsage, throwUnsupportedOption
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Server

public Server()

Server

public Server(Service service,
              java.lang.String... args)
       throws java.sql.SQLException
Create a new server for the given service.

Parameters:
service - the service
args - the command line arguments
Throws:
java.sql.SQLException
Method Detail

main

public static void main(java.lang.String... args)
                 throws java.sql.SQLException
When running without options, -tcp, -web, -browser and -pg are started.
Options are case sensitive. Supported options are:
[-help] or [-?] Print the list of options
[-web] Start the web server with the H2 Console
[-webAllowOthers] Allow other computers to connect - see below
[-webPort <port>] The port (default: 8082)
[-webSSL] Use encrypted (HTTPS) connections
[-browser] Start a browser and open a page to connect to the web server
[-tcp] Start the TCP server
[-tcpAllowOthers] Allow other computers to connect - see below
[-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:9094
[-tcpShutdownForce] Do not wait until all connections are closed
[-pg] Start the PG server
[-pgAllowOthers] Allow other computers to connect - see below
[-pgPort <port>] The port (default: 5435)
[-baseDir <dir>] The base directory for H2 databases; for all servers
[-ifExists] Only existing databases may be opened; for all servers
[-trace] Print additional trace information; for all servers
The options -xAllowOthers are potentially risky.
For details, see Advanced Topics / Protection against Remote Access.

Parameters:
args - the command line arguments
Throws:
java.sql.SQLException

run

public void run(java.lang.String... args)
         throws java.sql.SQLException
Description copied from class: Tool
Run the tool with the given output stream and arguments.

Specified by:
run in class Tool
Parameters:
args - the argument list
Throws:
java.sql.SQLException

shutdownTcpServer

public static void shutdownTcpServer(java.lang.String url,
                                     java.lang.String password,
                                     boolean force)
                              throws java.sql.SQLException
Shutdown a TCP server. If force is set to false, the server will not allow new connections, but not kill existing connections, instead it will stop if the last connection is closed. If force is set to true, existing connections are killed. After calling the method with force=false, it is not possible to call it again with force=true because new connections are not allowed. Example:
 Server.shutdownTcpServer("tcp://localhost:9094", password, true);
 

Parameters:
url - example: tcp://localhost:9094
password - the password to use ("" for no password)
force - the shutdown (don't wait)
Throws:
java.lang.ClassNotFoundException
java.sql.SQLException

getStatus

public java.lang.String getStatus()
Get the status of this server.

Returns:
the status

createWebServer

public static Server createWebServer(java.lang.String... args)
                              throws java.sql.SQLException
Create a new web server, but does not start it yet. Example:
 Server server = Server.createWebServer(
     new String[] { "-trace" }).start();
 

Parameters:
args - the argument list
Returns:
the server
Throws:
java.sql.SQLException

createTcpServer

public static Server createTcpServer(java.lang.String... args)
                              throws java.sql.SQLException
Create a new TCP server, but does not start it yet. Example:
 Server server = Server.createTcpServer(
     new String[] { "-tcpAllowOthers" }).start();
 

Parameters:
args - the argument list
Returns:
the server
Throws:
java.sql.SQLException

createPgServer

public static Server createPgServer(java.lang.String... args)
                             throws java.sql.SQLException
Create a new PG server, but does not start it yet. Example:
 Server server =
     Server.createPgServer("-pgAllowOthers").start();
 

Parameters:
args - the argument list
Returns:
the server
Throws:
java.sql.SQLException

start

public Server start()
             throws java.sql.SQLException
Tries to start the server.

Returns:
the server if successful
Throws:
java.sql.SQLException - if the server could not be started

isRunning

public boolean isRunning(boolean traceError)
Checks if the server is running.

Parameters:
traceError - if errors should be written
Returns:
if the server is running

stop

public void stop()
Stops the server.


getURL

public java.lang.String getURL()
Gets the URL of this server.

Returns:
the url

getPort

public int getPort()
Gets the port this server is listening on.

Returns:
the port

run

public void run()
INTERNAL

Specified by:
run in interface java.lang.Runnable

setShutdownHandler

public void setShutdownHandler(ShutdownHandler shutdownHandler)
INTERNAL


shutdown

public void shutdown()
INTERNAL

Specified by:
shutdown in interface ShutdownHandler

getService

public Service getService()
Get the service attached to this server.

Returns:
the service

startWebServer

public static void startWebServer(java.sql.Connection conn)
                           throws java.sql.SQLException
Start a web server and a browser that uses the given connection. The current transaction is preserved. This is specially useful to manually inspect the database when debugging.

Parameters:
conn - the database connection (the database must be open)
Throws:
java.sql.SQLException