Class TcpServer
java.lang.Object
org.h2.server.TcpServer
- All Implemented Interfaces:
Service
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.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionIf no key is set, return the original database name.booleanCheck if remote connections are allowed.static StringgetManagementDbName(int port) Get the database name of the management database.getName()Get the human readable name of the service.intgetPort()Gets the port this service is listening on.booleangetSSL()Returns whether a secure protocol is used.getType()Get the human readable short name of the service.getURL()Get the URL of this service in a human readable formvoidInitialize the service from command line options.booleanisDaemon()Check if a daemon thread should be used.booleanisRunning(boolean traceError) Check if the service is running.voidlisten()Listen for incoming connections.voidsetShutdownHandler(ShutdownHandler shutdownHandler) static voidStop the TCP server with the given URL.voidstart()Start the service.voidstop()Stop the service.static voidstopServer(int port, String password, int shutdownMode) Stop a running server.
-
Constructor Details
-
TcpServer
public TcpServer()
-
-
Method Details
-
getManagementDbName
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:)
-
setShutdownHandler
-
init
-
getURL
-
getPort
-
getSSL
public boolean getSSL()Returns whether a secure protocol is used.- Returns:
trueif SSL socket is used,falseif plain socket is used
-
start
Description copied from interface:ServiceStart the service. This usually means create the server socket. This method must not block.- Specified by:
startin interfaceService- Throws:
SQLException- on failure
-
listen
-
isRunning
-
stop
-
stopServer
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 serverspassword- the password (or null)shutdownMode- the shutdown mode, SHUTDOWN_NORMAL or SHUTDOWN_FORCE.
-
getAllowOthers
public boolean getAllowOthers()Description copied from interface:ServiceCheck if remote connections are allowed.- Specified by:
getAllowOthersin interfaceService- Returns:
- true if remote connections are allowed
-
getType
-
getName
-
shutdown
public 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 URLpassword- the passwordforce- if the server should be stopped immediatelyall- whether all TCP servers that are running in the JVM should be stopped- Throws:
SQLException- on failure
-
checkKeyAndGetDatabaseName
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
-
isDaemon
-