|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.hsqldb.server.Server
public class Server
The HSQLDB HSQL protocol network database server.
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 efficienly across the network. Server's direct descendent, WebServer, handles HTTP protocol connections exclusively, allowing HSQL protocol to be tunneled 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:
These values are natural to their context because the first case allows the JVM to exit by default on Server shutdown when a Server instance is started from a command line environment, whereas the second case prevents a typically unwanted JVM exit on Server shutdown when a Server intance is started as part of a larger framework.
Constructor Summary | |
---|---|
Server()
Creates a new Server instance handling HSQL protocol connections. |
Method Summary | |
---|---|
void |
checkRunning(boolean running)
Checks if this Server object is or is not running and throws if the current state does not match the specified value. |
String |
getAddress()
Retrieves, in string form, this server's host address. |
String |
getDatabaseName(int index,
boolean asconfigured)
Retrieves the url alias (network name) of the i'th database that this Server hosts. |
String |
getDatabasePath(int index,
boolean asconfigured)
Retrieves the HSQLDB path descriptor (uri) of the i'th Database that this Server hosts. |
String |
getDatabaseType(int index)
|
String |
getDefaultWebPage()
Retrieves the name of the web page served when no page is specified. |
PrintWriter |
getErrWriter()
Retrieves the PrintWriter to which server errors are printed. |
String |
getHelpString()
Retrieves a String object describing the command line and properties options for this Server. |
PrintWriter |
getLogWriter()
Retrieves the PrintWriter to which server messages are printed. |
int |
getPort()
Retrieves this server's host port. |
String |
getProductName()
Retrieves this server's product name. |
String |
getProductVersion()
Retrieves the server's product version, as a String. |
String |
getProtocol()
Retrieves a string respresentaion of the network protocol this server offers, typically one of 'HTTP', HTTPS', 'HSQL' or 'HSQLS'. |
Throwable |
getServerError()
Retrieves a Throwable indicating the last server error, if any. |
String |
getServerId()
Retrieves a String identifying this Server object. |
Thread |
getServerThread()
Returns thread object for "HSQLDB Server" thread |
int |
getState()
Retrieves current state of this server in numerically coded form. |
String |
getStateDescriptor()
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. |
String |
getWebRoot()
Retrieves the root context (directory) from which web content is served. |
void |
handleConnection(Socket s)
Assigns the specified socket to a new conection handler and starts the handler in a new Thread. |
boolean |
isNoSystemExit()
Retrieves whether this server calls System.exit() when shutdown. |
boolean |
isRestartOnShutdown()
Retrieves whether this server restarts on shutdown. |
boolean |
isSilent()
Retrieves whether silent mode operation was requested in the server properties. |
boolean |
isTls()
Retrieves whether the use of secure sockets was requested in the server properties. |
boolean |
isTrace()
Retrieves whether JDBC trace messages are to go to System.out or the DriverManger PrintStream/PrintWriter, if any. |
static void |
main(String[] args)
Creates and starts a new Server. |
void |
notify(int action,
int id)
This is called from org.hsqldb.DatabaseManager when a database is shutdown. |
boolean |
putPropertiesFromFile(String path)
Attempts to put properties from the file with the specified path. |
boolean |
putPropertiesFromFile(String path,
String extension)
Attempts to put properties from the file with given extension. |
void |
putPropertiesFromString(String s)
Puts properties from the supplied string argument. |
void |
setAddress(String address)
Sets the InetAddress with which this server's ServerSocket will be constructed. |
void |
setDaemon(boolean daemon)
Sets whether server thread is a daemon. |
void |
setDatabaseName(int index,
String name)
Sets the external name (url alias) of the i'th hosted database. |
void |
setDatabasePath(int index,
String path)
Sets the path of the hosted database. |
void |
setDefaultWebPage(String file)
Sets the name of the web page served when no page is specified. |
void |
setErrWriter(PrintWriter pw)
Sets the PrintWriter to which server errors are logged. |
void |
setLogWriter(PrintWriter pw)
Sets the PrintWriter to which server messages are logged. |
void |
setNoSystemExit(boolean noExit)
Sets whether this server calls System.exit() when shutdown. |
void |
setPort(int port)
Sets the server listen port. |
void |
setProperties(org.hsqldb.persist.HsqlProperties props)
Sets server properties using the specified properties object |
void |
setRestartOnShutdown(boolean restart)
Sets whether this server restarts on shutdown. |
void |
setSilent(boolean silent)
Sets silent mode operation |
void |
setTls(boolean tls)
Sets whether to use secure sockets |
void |
setTrace(boolean trace)
Sets whether trace messages go to System.out or the DriverManger PrintStream/PrintWriter, if any. |
void |
setWebRoot(String root)
Sets the path of the root directory from which web content is served. |
void |
shutdown()
External method to shut down this server. |
void |
shutdownCatalogs(int shutdownMode)
Shuts down all the database served by this server. |
void |
shutdownWithCatalogs(int shutdownMode)
Shuts down this server and all the database served by this server. |
void |
signalCloseAllServerConnections()
Closes all connections to this Server. |
int |
start()
Starts this server synchronously. |
int |
stop()
Stops this server asynchronously. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Server()
Method Detail |
---|
public Thread getServerThread()
public void checkRunning(boolean running)
running
- if true, ensure the server is running, else ensure the
server is not running
org.hsqldb.HsqlException
- if the supplied value does not match the
current running statuspublic void signalCloseAllServerConnections()
signalCloseAllServerConnections
in interface org.hsqldb.server.HsqlSocketRequestHandler
public String getAddress()
public String getDatabaseName(int index, boolean asconfigured)
index
- the index of the url alias upon which to reportasconfigured
- if true, report the configured value, else
the live value
public String getDatabasePath(int index, boolean asconfigured)
index
- the index of the uri upon which to reportasconfigured
- if true, report the configured value, else
the live value
public String getDatabaseType(int index)
public String getDefaultWebPage()
public String getHelpString()
public PrintWriter getErrWriter()
public PrintWriter getLogWriter()
public int getPort()
public String getProductName()
Typically, this will be something like: "HSQLDB xxx server".
public String getProductVersion()
Typically, this will be something like: "1.x.x" or "2.x.x" and so on.
public String getProtocol()
public Throwable getServerError()
public String getServerId()
public int getState()
Typically, this will be one of:
public String getStateDescriptor()
public String getWebRoot()
public void handleConnection(Socket s)
handleConnection
in interface org.hsqldb.server.HsqlSocketRequestHandler
s
- the socket to connectpublic boolean isNoSystemExit()
public boolean isRestartOnShutdown()
public boolean isSilent()
public boolean isTls()
public boolean isTrace()
public boolean putPropertiesFromFile(String path)
path
- the path of the desired properties file, without the
'.properties' file extension
org.hsqldb.HsqlException
- if this server is runningpublic boolean putPropertiesFromFile(String path, String extension)
path
- the path of the desired properties file.extension
- extension to add to parth
org.hsqldb.HsqlException
- if this server is runningpublic void putPropertiesFromString(String s)
s
- semicolon-delimited key=value pair string,
e.g. silent=false;port=8080;...
org.hsqldb.HsqlException
- if this server is runningpublic void setAddress(String address)
address
- 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.
org.hsqldb.HsqlException
- if this server is runningpublic void setDatabaseName(int index, String name)
name
- external name (url alias) of the i'th HSQLDB database
instance this server is to host.
org.hsqldb.HsqlException
- if this server is runningpublic void setDatabasePath(int index, String path)
path
- The path of the i'th HSQLDB database instance this server
is to host.public void setDefaultWebPage(String file)
file
- the name of the web page served when no page is specifiedpublic void setPort(int port)
port
- the port at which this server listenspublic void setErrWriter(PrintWriter pw)
Setting this attribute to null disables server error logging
pw
- the PrintWriter to which server messages are loggedpublic void setLogWriter(PrintWriter pw)
Setting this attribute to null disables server message logging
pw
- the PrintWriter to which server messages are loggedpublic void setNoSystemExit(boolean noExit)
noExit
- if true, System.exit() will not be called.public void setRestartOnShutdown(boolean restart)
restart
- if true, this server restarts on shutdownpublic void setSilent(boolean silent)
silent
- if true, then silent mode, else trace messages
are to be printedpublic void setTls(boolean tls)
tls
- true for secure sockets, else false
org.hsqldb.HsqlException
- if this server is runningpublic void setTrace(boolean trace)
trace
- if true, route JDBC trace messages to System.outpublic void setDaemon(boolean daemon)
daemon
- if true, start the thread as a daemon threadpublic void setWebRoot(String root)
root
- the root (context) directory from which web content
is servedpublic void setProperties(org.hsqldb.persist.HsqlProperties props) throws IOException, ServerAcl.AclFormatException
props
- The object containing properties to set
ServerAcl.AclFormatException
- ACL list was requested but problem loading ACL.
IOException
- ACL list was requested but I/O problem loading ACL.public int start()
This method waits for current state to change from SERVER_STATE_OPENNING. In order to discover the success or failure of this operation, server state must be polled or a subclass of Server must be used that overrides the setState method to provide state change notification.
public int stop()
This method returns immediately, regardless of current state. In order to discover the success or failure of this operation, server state must be polled or a subclass of Server must be used that overrides the setState method to provide state change notification.
public final void notify(int action, int id)
action
- a code indicating what has happendpublic void shutdownCatalogs(int shutdownMode)
shutdownMode
- a value between 0-4, usually 0 or 1.public void shutdownWithCatalogs(int shutdownMode)
shutdownMode
- a value between 0-4, usually 0 or 1.public void shutdown()
public static void main(String[] args)
Allows starting a Server via the command line interface.
args
- the command line arguments for the Server instance
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |