TcpServer

The TCP server implements the native H2 database server protocol. It supports multiple client connections to multiple databases (many to many). The same database may be opened by multiple clients. Also supported is the mixed mode: opening databases in embedded mode, and at the same time start a TCP server to allow clients to connect to the same database over the network.

Methods
static String getManagementDbName(int port)
Get the database name of the management database.
static String getManagementDbName(int port)
Get the database name of the management database. The management database contains a table with active sessions (SESSIONS).
Parameters:
port - the TCP server port
Returns:
the database name (usually starting with mem:)
static void shutdown(String url, String password, boolean force, boolean all)
Stop the TCP server with the given URL.
static void shutdown(String url, String password, boolean force, boolean all) throws SQLException
Stop the TCP server with the given URL.
Parameters:
url - the database URL
password - the password
force - if the server should be stopped immediately
all - whether all TCP servers that are running in the JVM should be stopped
static void stopServer(int port, String password, int shutdownMode)
Stop a running server.
static void stopServer(int port, String password, int shutdownMode)
Stop a running server. This method is called via reflection from the STOP_SERVER function.
Parameters:
port - the port where the server runs, or 0 for all running servers
password - the password (or null)
shutdownMode - the shutdown mode, SHUTDOWN_NORMAL or SHUTDOWN_FORCE.
void addConnection(int id, String url, String user)
Add a connection to the management database.
void addConnection(int id, String url, String user)
Add a connection to the management database.
Parameters:
id - the connection id
url - the database URL
user - the user name
boolean allow(Socket socket)
Check if this socket may connect to this server.
boolean allow(Socket socket)
Check if this socket may connect to this server. Remote connections are not allowed if the flag allowOthers is set.
Parameters:
socket - the socket
Returns:
true if this client may connect
void cancelStatement(String sessionId, int statementId)
Cancel a running statement.
void cancelStatement(String sessionId, int statementId)
Cancel a running statement.
Parameters:
sessionId - the session id
statementId - the statement id
String checkKeyAndGetDatabaseName(String db)
If no key is set, return the original database name.
String checkKeyAndGetDatabaseName(String db)
If no key is set, return the original database name. If a key is set, check if the key matches. If yes, return the correct database name. If not, throw an exception.
Parameters:
db - the key to test (or database name if no key is used)
Returns:
the database name
Throws:
DbException - if a key is set but doesn't match
boolean getAllowOthers()
boolean getAllowOthers()
String getBaseDir()
Get the configured base directory.
String getBaseDir()
Get the configured base directory.
Returns:
the base directory
boolean getIfExists()
boolean getIfExists()
String getName()
String getName()
int getPort()
int getPort()
String getType()
String getType()
String getURL()
String getURL()
void init(String... args)
void init(String... args)
boolean isDaemon()
boolean isDaemon()
boolean isRunning(boolean traceError)
boolean isRunning(boolean traceError)
void listen()
void listen()
void remove(TcpServerThread t)
Remove a thread from the list.
void remove(TcpServerThread t)
Remove a thread from the list.
Parameters:
t - the thread to remove
void removeConnection(int id)
Remove a connection from the management database.
void removeConnection(int id)
Remove a connection from the management database.
Parameters:
id - the connection id
void setShutdownHandler(ShutdownHandler shutdownHandler)
void setShutdownHandler(ShutdownHandler shutdownHandler)
void shutdown()
Shut down this server.
void shutdown()
Shut down this server.
void start()
void start() throws SQLException
void stop()
void stop()
void trace(String s)
Print a message if the trace flag is enabled.
void trace(String s)
Print a message if the trace flag is enabled.
Parameters:
s - the message
void traceError(Throwable e)
Print a stack trace if the trace flag is enabled.
void traceError(Throwable e)
Print a stack trace if the trace flag is enabled.
Parameters:
e - the exception