📄 server.java
字号:
* @return if true, secure sockets are requested, else not * * @jmx.managed-attribute * access="read-write" * description="Use TLS/SSL sockets?" */ public boolean isTls() { return serverProperties.isPropertyTrue(ServerConstants.SC_KEY_TLS); } /** * Retrieves whether JDBC trace messages are to go to System.out or the * DriverManger PrintStream/PrintWriter, if any. * * @return true if tracing is on (JDBC trace messages to system out) * * @jmx.managed-attribute * access="read-write" * description="JDBC trace messages to System.out?" */ public boolean isTrace() { return serverProperties.isPropertyTrue(ServerConstants.SC_KEY_TRACE); } /** * Attempts to put properties from the file * with the specified path. The file * extension '.properties' is implicit and should not * be included in the path specification. * * @param path the path of the desired properties file, without the * '.properties' file extension * @throws RuntimeException if this server is running * @return true if the indicated file was read sucessfully, else false * * @jmx.managed-operation * impact="ACTION" * description="Reads in properties" * * @jmx.managed-operation-parameter * name="path" * type="java.lang.String" * position="0" * description="(optional) returns false if path is empty" */ public boolean putPropertiesFromFile(String path) throws RuntimeException { if (getState() != ServerConstants.SERVER_STATE_SHUTDOWN) { throw new RuntimeException(); } path = FileUtil.canonicalOrAbsolutePath(path); HsqlProperties p = ServerConfiguration.getPropertiesFromFile(path); if (p == null || p.isEmpty()) { return false; } printWithThread("putPropertiesFromFile(): [" + path + ".properties]"); setProperties(p); return true; } /** * Puts properties from the supplied string argument. The relevant * key value pairs are the same as those for the (web)server.properties * file format, except that the 'server.' prefix should not be specified. * * @param s semicolon-delimited key=value pair string, * e.g. k1=v1;k2=v2;k3=v3... * @throws RuntimeException if this server is running * * @jmx.managed-operation * impact="ACTION" * description="'server.' key prefix automatically supplied" * * @jmx.managed-operation-parameter * name="s" * type="java.lang.String" * position="0" * description="semicolon-delimited key=value pairs" */ public void putPropertiesFromString(String s) throws RuntimeException { if (getState() != ServerConstants.SERVER_STATE_SHUTDOWN) { throw new RuntimeException(); } if (StringUtil.isEmpty(s)) { return; } printWithThread("putPropertiesFromString(): [" + s + "]"); HsqlProperties p = HsqlProperties.delimitedArgPairsToProps(s, "=", ";", ServerConstants.SC_KEY_PREFIX); setProperties(p); } /** * Sets the InetAddress with which this server's ServerSocket will be * constructed. A null or empty string or the special value "0.0.0.0" * can be used to bypass explicit selection, causing the ServerSocket * to be constructed without specifying an InetAddress. * * @param 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. * @throws RuntimeException if this server is running * * @jmx.managed-attribute */ public void setAddress(String address) throws RuntimeException { checkRunning(false); if (org.hsqldb.lib.StringUtil.isEmpty(address)) { address = ServerConstants.SC_DEFAULT_ADDRESS; } printWithThread("setAddress(" + address + ")"); serverProperties.setProperty(ServerConstants.SC_KEY_ADDRESS, address); } /** * Sets the external name (url alias) of the i'th hosted database. * * @param name external name (url alias) of the i'th HSQLDB database * instance this server is to host. * @throws RuntimeException if this server is running * * @jmx.managed-operation * impact="ACTION" * description="Sets the url alias by which is known the i'th hosted Database" * * @jmx.managed-operation-parameter * name="index" * type="int" * position="0" * description="This Server's index for the hosted Database" * * @jmx.managed-operation-parameter * name="name" * type="java.lang.String" * position="1" * description="url alias component for the hosted Database" */ public void setDatabaseName(int index, String name) throws RuntimeException { checkRunning(false); printWithThread("setDatabaseName(" + index + "," + name + ")"); serverProperties.setProperty(ServerConstants.SC_KEY_DBNAME + "." + index, name); } /** * Sets the path of the hosted database. * * @param path The path of the i'th HSQLDB database instance this server * is to host. * * @jmx.managed-operation * impact="ACTION" * description="Sets the database uri path for the i'th hosted Database" * * @jmx.managed-operation-parameter * name="index" * type="int" * position="0" * description="This Server's index for the hosted Database" * * @jmx.managed-operation-parameter * name="path" * type="java.lang.String" * position="1" * description="database uri path of the hosted Database" */ public void setDatabasePath(int index, String path) throws RuntimeException { checkRunning(false); printWithThread("setDatabasePath(" + index + "," + path + ")"); serverProperties.setProperty(ServerConstants.SC_KEY_DATABASE + "." + index, path); } /** * Sets the name of the web page served when no page is specified. * * @param file the name of the web page served when no page is specified * * @jmx.managed-attribute */ public void setDefaultWebPage(String file) { checkRunning(false); printWithThread("setDefaultWebPage(" + file + ")"); if (serverProtocol != ServerConstants.SC_PROTOCOL_HTTP) { return; } serverProperties.setProperty(ServerConstants.SC_KEY_WEB_DEFAULT_PAGE, file); } /** * Sets the server listen port. * * @param port the port at which this server listens * * @jmx.managed-attribute */ public void setPort(int port) throws RuntimeException { checkRunning(false); printWithThread("setPort(" + port + ")"); serverProperties.setProperty(ServerConstants.SC_KEY_PORT, port); } /** * Sets the PrintWriter to which server errors are logged. <p> * * Setting this attribute to null disables server error logging * * @param pw the PrintWriter to which server messages are logged */ public void setErrWriter(PrintWriter pw) { errWriter = pw; } /** * Sets the PrintWriter to which server messages are logged. <p> * * Setting this attribute to null disables server message logging * * @param pw the PrintWriter to which server messages are logged */ public void setLogWriter(PrintWriter pw) { logWriter = pw; } /** * Sets whether this server calls System.exit() when shutdown. * * @param noExit if true, System.exit() will not be called. * * @jmx.managed-attribute */ public void setNoSystemExit(boolean noExit) { printWithThread("setNoSystemExit(" + noExit + ")"); serverProperties.setProperty(ServerConstants.SC_KEY_NO_SYSTEM_EXIT, noExit); } /** * Sets whether this server restarts on shutdown. * * @param restart if true, this server restarts on shutdown * * @jmx.managed-attribute */ public void setRestartOnShutdown(boolean restart) { printWithThread("setRestartOnShutdown(" + restart + ")"); serverProperties.setProperty( ServerConstants.SC_KEY_AUTORESTART_SERVER, restart); } /** * Sets silent mode operation * * @param silent if true, then silent mode, else trace messages * are to be printed * * @jmx.managed-attribute */ public void setSilent(boolean silent) { printWithThread("setSilent(" + silent + ")"); serverProperties.setProperty(ServerConstants.SC_KEY_SILENT, silent); isSilent = silent; } /** * Sets whether to use secure sockets * * @param tls true for secure sockets, else false * @throws RuntimeException if this server is running * * @jmx.managed-attribute */ public void setTls(boolean tls) { checkRunning(false); printWithThread("setTls(" + tls + ")"); serverProperties.setProperty(ServerConstants.SC_KEY_TLS, tls); } /** * Sets whether trace messages go to System.out or the * DriverManger PrintStream/PrintWriter, if any. * * @param trace if true, route JDBC trace messages to System.out * * @jmx.managed-attribute */ public void setTrace(boolean trace) { printWithThread("setTrace(" + trace + ")"); serverProperties.setProperty(ServerConstants.SC_KEY_TRACE, trace); JavaSystem.setLogToSystem(trace); } /** * Sets the path of the root directory from which web content is served. * * @param root the root (context) directory from which web content * is served * * @jmx.managed-attribute */ public void setWebRoot(String root) { checkRunning(false); root = (new File(root)).getAbsolutePath(); printWithThread("setWebRoot(" + root + ")"); if (serverProtocol != ServerConstants.SC_PROTOCOL_HTTP) { return; } serverProperties.setProperty(ServerConstants.SC_KEY_WEB_ROOT, root); } /** * Sets server properties using the specified properties object * * @param p The object containing properties to set */ public void setProperties(HsqlProperties p) { checkRunning(false); if (p != null) { serverProperties.addProperties(p); ServerConfiguration.translateAddressProperty(serverProperties); } maxConnections = serverProperties.getIntegerProperty( ServerConstants.SC_KEY_MAX_CONNECTIONS, 16); JavaSystem.setLogToSystem(isTrace()); isSilent = serverProperties.isPropertyTrue(ServerConstants.SC_KEY_SILENT); isRemoteOpen = serverProperties.isPropertyTrue( ServerConstants.SC_KEY_REMOTE_OPEN_DB); } /** * Starts this server synchronously. <p> * * 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. * * @return the server state noted at entry to this method * * @jmx.managed-operation * impact="ACTION_INFO" * description="Invokes asynchronous startup sequence; returns previous state" */ public int start() { printWithThread("start() entered"); int previousState = getState(); if (serverThread != null) { printWithThread("start(): serverThread != null; no action taken"); return previousState; } setState(ServerConstants.SERVER_STATE_OPENING); serverThread = new ServerThread("HSQLDB Server "); serverThread.start(); // call synchronized getState() to become owner of the Server Object's monitor while (getState() == ServerConstants.SERVER_STATE_OPENING) { try { Thread.sleep(100); } catch (InterruptedException e) {} } printWithThread("start() exiting"); return previousState; } /** * Stops this server asynchronously. <p> *
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -