A Server object acts as a network database server and is one way of using the client-server mode of HSQLDB Database Engine. Instances of this class handle native HSQL protocol connections exclusively, allowing database queries to be performed efficiently across the network. Server's direct descendant, WebServer, handles HTTP protocol connections exclusively, allowing HSQL protocol to be tunnelled over HTTP to avoid sandbox and firewall issues, albeit less efficiently.
There are a number of ways to configure and start a Server instance.
When started from the command line or programatically via the main(String[]) method, configuration occurs in three phases, with later phases overriding properties set by previous phases:
From the command line, the options are as follows:
+-----------------+-------------+----------+------------------------------+ | OPTION | TYPE | DEFAULT | DESCRIPTION | +-----------------+-------------+----------+------------------------------| | --help | | | prints this message | | --address | name|number | any | server inet address | | --port | number | 9001/544 | port at which server listens | | --database.i | [type]spec | 0=test | path of database i | | --dbname.i | alias | | url alias for database i | | --silent | true|false | true | false => display all queries | | --trace | true|false | false | display JDBC trace messages | | --tls | true|false | false | TLS/SSL (secure) sockets | | --no_system_exit| true|false | false | do not issue System.exit() | | --remote_open | true|false | false | can open databases remotely | | --props | filepath | | file path of properties file | +-----------------+-------------+----------+------------------------------+The database.i and dbname.i options need further explanation:
If omitted, the type component is taken to be 'file:'.
A full description of how
'[type]spec' values are interpreted appears in the overview for
JDBCConnection.
This behaviour allows the previous database connection url format to work with essentially unchanged semantics.
Here is an example 'server.properties' file:
server.port=9001 server.database.0=test server.dbname.0=... ... server.database.n=... server.dbname.n=... server.silent=trueStarting with 1.7.2, Server has been refactored to become a simple JavaBean with non-blocking start() and stop() service methods. It is possible to configure a Server instance through the JavaBean API as well, but this part of the public interface is still under review and will not be finalized or documented fully until the final 1.7.2 release.
Note:
The 'no_system_exit' property is of particular interest.
If a Server instance is to run embedded in, say, an application server, such as when the JDBCDataSource or HsqlServerFactory classes are used, it is typically necessary to avoid calling System.exit() when the Server instance shuts down.
By default, 'no_system_exit' is set:
| Modifier and Type | Class and Description |
|---|---|
| private class | Server.
A specialized Thread inner class in which the run() method of this server executes. |
| Modifier and Type | Field and Description |
|---|---|
| private ServerAcl | |
| pack-priv volatile long | |
| pack-priv HashSet | |
| protected long[] | |
| protected String[] | |
| protected int[] | |
| protected String[] | |
| protected HsqlProperties[] | |
| protected String[] | |
| private PrintWriter | |
| protected boolean | |
| protected volatile boolean | |
| private volatile boolean | |
| private volatile boolean | |
| private PrintWriter | |
| protected int | |
| protected int | |
| protected static final int | |
| protected ThreadGroup | |
| pack-priv HashSet | |
| pack-priv final Object | |
| private Throwable | |
| protected String | |
| pack-priv ServerProperties | |
| protected int | |
| private volatile int | |
| private Thread | |
| protected volatile ServerSocket | |
| protected HsqlSocketFactory | |
| private HsqlDateTime. |
| Access | Constructor and Description |
|---|---|
| public | |
| protected | Server(int
the ServerConstants code indicating which
connection protocol to handle protocol)Creates a new Server instance handling the specified connection protocol. |
| Modifier and Type | Method and Description |
|---|---|
| protected boolean | Returns: booleanthe socket to test. socket)Retrieves whether the specified socket should be allowed to make a connection. |
| public void | checkRunning(boolean
if true, ensure the server is running, else ensure the
server is not running running)Checks if this Server object is or is not running and throws if the current state does not match the specified value. |
| protected int | |
| public String | Returns: this server's host addressRetrieves, in string form, this server's host address. |
| public String | Returns: the url alias component of the i'th database that this Server hosts, or null if no such name exists.the index of the url alias upon which to report index, boolean if true, report the configured value, else
the live value asconfigured)Retrieves the url alias (network name) of the i'th database that this Server hosts. |
| public String | Returns: the HSQLDB database path descriptor of the i'th database that this Server hosts, or null if no such path descriptor existsthe index of the uri upon which to report index, boolean if true, report the configured value, else
the live value asconfigured)Retrieves the HSQLDB path descriptor (uri) of the i'th Database that this Server hosts. |
| public String | |
| pack-priv final synchronized int | |
| private IntKeyHashMap | Returns: IntKeyHashMapReturns a map of n values from server.dbname.n values to database names from the properties object. |
| public String | Returns: the name of the web page served when no page is specifiedRetrieves the name of the web page served when no page is specified. |
| public PrintWriter | Returns: the PrintWriter to which server errors are printed.Retrieves the PrintWriter to which server errors are printed. |
| pack-priv final int | |
| public String | Returns: the command line and properties options help for this ServerRetrieves a String object describing the command line and properties options for this Server. |
| public int | Returns: this server socket's actual host portRetrieves this server socket's actual host port. |
| public PrintWriter | Returns: the PrintWriter to which server messages are printed.Retrieves the PrintWriter to which server messages are printed. |
| public int | Returns: this server socket's max wait timeRetrieves this server socket's max wait time for connection handshake in milliseconds. |
| public int | Returns: this server's host port as configuredRetrieves this server's host port as configured. |
| public String | |
| public String | Returns: the product version of the serverRetrieves the server's product version, as a String. |
| public String | Returns: string representation of this server's protocolRetrieves a string resresentaion of the network protocol this server offers, typically one of 'HTTP', HTTPS', 'HSQL' or 'HSQLS'. |
| public Throwable | Returns: a Throwable indicating the last server errorRetrieves a Throwable indicating the last server error, if any. |
| public String | Returns: a String identifying this Server objectRetrieves a String identifying this Server object. |
| public Thread | |
| public int | Returns: this server's state code.Retrieves current state of this server in numerically coded form. |
| public String | Returns: this server's state represented as a character sequence.Retrieves a character sequence describing this server's current state, including the message of the last exception, if there is one, and it is still in context. |
| public String | Returns: the root context (directory) from which web content is servedRetrieves the root context (directory) from which web content is served. |
| public void | handleConnection(Socket
the socket to connect s)Implements org. Assigns the specified socket to a new connection handler and starts the handler in a new Thread. |
| protected void | init(int
typically either SC_PROTOCOL_HTTP or SC_PROTOCOL_HSQL protocol)Initializes this server, setting the accepted connection protocol. |
| public boolean | Returns: true if this server does not call System.exit()Retrieves whether this server calls System.exit() when shutdown. |
| public boolean | |
| public boolean | Returns: true this server restarts on shutdownRetrieves whether this server restarts on shutdown. |
| public boolean | Returns: if true, silent mode was requested, else trace messages are to be printedRetrieves whether silent mode operation was requested in the server properties. |
| public boolean | Returns: if true, secure sockets are requested, else notRetrieves whether the use of secure sockets was requested in the server properties. |
| public boolean | Returns: true if tracing is on (JDBC trace messages to system out)Retrieves whether JDBC trace messages are to go to System.out or the DriverManger PrintStream/PrintWriter, if any. |
| public static void | |
| public final void | notify(int
database id id)Implements org. This is called from org.hsqldb.DatabaseManager when a database is shutdown. |
| pack-priv final int | |
| pack-priv final boolean | |
| private void | |
| protected void | |
| protected void | printError(String
the message to print msg)Prints an error message to this Server object's errWriter. |
| protected static void | |
| protected void | |
| pack-priv final void | printRequest(long
the connection identifier cid, Result the request whose description is to be printed r)Prints a description of the request encapsulated by the Result argument, r. Printing occurs iff isSilent() is false. |
| pack-priv final void | printResource(String
the resource key key)Prints value from server's resource bundle, formatted to identify that the print operation is against this server instance. |
| private void | |
| protected void | printStackTrace(Throwable
the Throwable whose stack trace is to be printed t)Prints the stack trace of the Throwable, t, to this Server object's errWriter. |
| protected void | printWithThread(String
the message to print msg)Prints a message formatted similarly to print(String), additionally identifying the current (calling) thread. |
| pack-priv final void | printWithTimestamp(String
the message to print msg)Prints the specified message, s, prepended with a timestamp representing the current date and time, formatted to identify that the print operation is against this server instance. |
| public boolean | Returns: true if the indicated file was read successfully, else falsethe path of the desired properties file, without the
'.properties' file extension path)Attempts to put properties from the file with the specified path. |
| public boolean | Returns: true if the indicated file was read successfully, else falsethe path of the desired properties file. path, String extension to add to path extension)Attempts to put properties from the file with given extension. |
| public void | putPropertiesFromString(String
semicolon-delimited key=value pair string,
e.g. silent=false;port=8080;... s)Puts properties from the supplied string argument. |
| pack-priv final synchronized void | |
| private synchronized void | releaseServerSocket()
Puts this server into the SERVER_CLOSING state, closes the ServerSocket and nullifies the reference to it. |
| private void | run()
Attempts to bring this server fully online by opening a new ServerSocket, obtaining the hosted databases, notifying the status waiter thread (if any) and finally entering the listen loop if all else succeeds. |
| pack-priv synchronized void | |
| public void | setAddress(String
A string representing the desired InetAddress as would
be retrieved by InetAddres.getByName(), or a null or empty string
or "0.0.0.0" to signify that the server socket should be constructed
using the signature that does not specify the InetAddress. address)Sets the InetAddress with which this server's ServerSocket will be constructed. |
| public void | |
| public void | setDatabaseName(int
int index, String external name (url alias) of the i'th HSQLDB database
instance this server is to host. name)Sets the external name (url alias) of the i'th hosted database. |
| public void | setDatabasePath(int
int index, String The path of the i'th HSQLDB database instance this server is
to host. path)Sets the path of the hosted database. |
| private void | |
| public void | setDefaultWebPage(String
the name of the web page served when no page is specified file)Sets the name of the web page served when no page is specified. |
| public void | setErrWriter(PrintWriter
the PrintWriter to which server messages are logged pw)Sets the PrintWriter to which server errors are logged. |
| private static void | |
| public void | setLogWriter(PrintWriter
the PrintWriter to which server messages are logged pw)Sets the PrintWriter to which server messages are logged. |
| public void | setMaxWait(int
an integer between 0 and 30000 maxWait)Sets the max wait time for connection handshake in milliseconds. |
| public void | setNoSystemExit(boolean
if true, System.exit() will not be called. noExit)Sets whether this server calls System.exit() when shutdown. |
| public void | |
| public void | setProperties(Properties
The object containing properties to set props)Sets server properties using the specified properties object |
| public void | setProperties(HsqlProperties
The HsqlProperties object containing properties to set props)Sets server properties using the specified HsqlProperties object |
| public void | setRestartOnShutdown(boolean
if true, this server restarts on shutdown restart)Sets whether this server restarts on shutdown. |
| protected void | setServerError(Throwable
The new value for the server error t)Sets this Server's last encountered error state. |
| public void | setSilent(boolean
if true, then silent mode, else trace messages
are to be printed silent)Sets silent mode operation |
| protected synchronized void | |
| public void | |
| public void | setTrace(boolean
if true, route JDBC trace messages to System.out trace)Sets whether trace messages go to System.out or the DriverManger PrintStream/PrintWriter, if any. |
| public void | setWebRoot(String
the root (context) directory from which web content
is served root)Sets the path of the root directory from which web content is served. |
| public void | |
| protected synchronized void | shutdown(boolean
true if shutdown is in response to an error
state, else false error)Shuts down this server. |
| public void | shutdownCatalogs(int
a value between 1-4, usually 2 for NORMAL. shutdownMode)Shuts down all the database served by this server. |
| public void | shutdownWithCatalogs(int
a value between 1-4, usually 2 for NORMAL. shutdownMode)Shuts down this server and all the database served by this server. |
| public synchronized void | signalCloseAllServerConnections()
Implements org. Closes all connections to this Server. |
| public int | |
| public int |