📄 server.java
字号:
printWithThread("signalCloseAllServerConnections() exited"); } protected void finalize() throws Throwable { if (serverThread != null) { releaseServerSocket(); } } /** * Retrieves, in string form, this server's host address. * * @return this server's host address * * @jmx.managed-attribute * access="read-write" * description="Host InetAddress" */ public String getAddress() { return socket == null ? serverProperties.getProperty(ServerConstants.SC_KEY_ADDRESS) : socket.getInetAddress().getHostAddress(); } /** * Retrieves the url alias (network name) of the i'th database * that this Server hosts. * * @param index the index of the url alias upon which to report * @param asconfigured if true, report the configured value, else * the live value * @return the url alias component of the i'th database * that this Server hosts, or null if no such name exists. * * @jmx.managed-operation * impact="INFO" * description="url alias component of 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="asconfigured" * type="boolean" * position="1" * description="if true, the configured value, else the live value" */ public String getDatabaseName(int index, boolean asconfigured) { if (asconfigured) { return serverProperties.getProperty(ServerConstants.SC_KEY_DBNAME + "." + index); } else if (getState() == ServerConstants.SERVER_STATE_ONLINE) { return (dbAlias == null || index < 0 || index >= dbAlias.length) ? null : dbAlias[index]; } else { return null; } } /** * Retrieves the HSQLDB path descriptor (uri) of the i'th * Database that this Server hosts. * * @param index the index of the uri upon which to report * @param asconfigured if true, report the configured value, else * the live value * @return the HSQLDB database path descriptor of the i'th database * that this Server hosts, or null if no such path descriptor * exists * * @jmx.managed-operation * impact="INFO" * description="For 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="asconfigured" * type="boolean" * position="1" * description="if true, the configured value, else the live value" */ public String getDatabasePath(int index, boolean asconfigured) { if (asconfigured) { return serverProperties.getProperty( ServerConstants.SC_KEY_DATABASE + "." + index); } else if (getState() == ServerConstants.SERVER_STATE_ONLINE) { return (dbPath == null || index < 0 || index >= dbPath.length) ? null : dbPath[index]; } else { return null; } } public String getDatabaseType(int index) { return (dbType == null || index < 0 || index >= dbType.length) ? null : dbType[index]; } /** * Retrieves the name of the web page served when no page is specified. * This attribute is relevant only when server protocol is HTTP(S). * * @return the name of the web page served when no page is specified * * @jmx.managed-attribute * access="read-write" * description="Used when server protocol is HTTP(S)" */ public String getDefaultWebPage() { return "[IGNORED]"; } /** * Retrieves a String object describing the command line and * properties options for this Server. * * @return the command line and properties options help for this Server */ public String getHelpString() { return BundleHandler.getString(serverBundleHandle, "server.help"); } /** * Retrieves the PrintWriter to which server errors are printed. * * @return the PrintWriter to which server errors are printed. */ public PrintWriter getErrWriter() { return errWriter; } /** * Retrieves the PrintWriter to which server messages are printed. * * @return the PrintWriter to which server messages are printed. */ public PrintWriter getLogWriter() { return logWriter; } /** * Retrieves this server's host port. * * @return this server's host port * * @jmx.managed-attribute * access="read-write" * description="At which ServerSocket listens for connections" */ public int getPort() { return serverProperties.getIntegerProperty( ServerConstants.SC_KEY_PORT, ServerConfiguration.getDefaultPort(serverProtocol, isTls())); } /** * Retrieves this server's product name. <p> * * Typically, this will be something like: "HSQLDB xxx server". * * @return the product name of this server * * @jmx.managed-attribute * access="read-only" * description="Of Server" */ public String getProductName() { return "HSQLDB server"; } /** * Retrieves the server's product version, as a String. <p> * * Typically, this will be something like: "1.x.x" or "2.x.x" and so on. * * @return the product version of the server * * @jmx.managed-attribute * access="read-only" * description="Of Server" */ public String getProductVersion() { return HsqlDatabaseProperties.THIS_VERSION; } /** * Retrieves a string respresentaion of the network protocol * this server offers, typically one of 'HTTP', HTTPS', 'HSQL' or 'HSQLS'. * * @return string respresentation of this server's protocol * * @jmx.managed-attribute * access="read-only" * description="Used to handle connections" */ public String getProtocol() { return isTls() ? "HSQLS" : "HSQL"; } /** * Retrieves a Throwable indicating the last server error, if any. <p> * * @return a Throwable indicating the last server error * * @jmx.managed-attribute * access="read-only" * description="Indicating last exception state" */ public Throwable getServerError() { return serverError; } /** * Retrieves a String identifying this Server object. * * @return a String identifying this Server object * * @jmx.managed-attribute * access="read-only" * description="Identifying Server" */ public String getServerId() { return serverId; } /** * Retrieves current state of this server in numerically coded form. <p> * * Typically, this will be one of: <p> * * <ol> * <li>ServerProperties.SERVER_STATE_ONLINE (1) * <li>ServerProperties.SERVER_STATE_OPENING (4) * <li>ServerProperties.SERVER_STATE_CLOSING (8) * <li>ServerProperties.SERVER_STATE_SHUTDOWN (16) * </ol> * * @return this server's state code. * * @jmx.managed-attribute * access="read-only" * description="1:ONLINE 4:OPENING 8:CLOSING, 16:SHUTDOWN" */ public synchronized int getState() { return serverState; } /** * 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. * * @return this server's state represented as a character sequence. * * @jmx.managed-attribute * access="read-only" * description="State as string" */ public String getStateDescriptor() { String state; Throwable t = getServerError(); switch (serverState) { case ServerConstants.SERVER_STATE_SHUTDOWN : state = "SHUTDOWN"; break; case ServerConstants.SERVER_STATE_OPENING : state = "OPENING"; break; case ServerConstants.SERVER_STATE_CLOSING : state = "CLOSING"; break; case ServerConstants.SERVER_STATE_ONLINE : state = "ONLINE"; break; default : state = "UNKNOWN"; break; } return state; } /** * Retrieves the root context (directory) from which web content * is served. This property is relevant only when the server * protocol is HTTP(S). Although unlikely, it may be that in the future * other contexts, such as jar urls may be supported, so that pages can * be served from the contents of a jar or from the JVM class path. * * @return the root context (directory) from which web content is served * * @jmx.managed-attribute * access="read-write" * description="Context (directory)" */ public String getWebRoot() { return "[IGNORED]"; } /** * Assigns the specified socket to a new conection handler and * starts the handler in a new Thread. * * @param s the socket to connect */ public void handleConnection(Socket s) { Thread t; Runnable r; String ctn; printWithThread("handleConnection(" + s + ") entered"); if (!allowConnection(s)) { try { s.close(); } catch (Exception e) {} printWithThread("allowConnection(): connection refused"); printWithThread("handleConnection() exited"); return; } // Maybe set up socket options, SSL // Session tracing/callbacks, etc. if (socketFactory != null) { socketFactory.configureSocket(s); } if (serverProtocol == ServerConstants.SC_PROTOCOL_HSQL) { r = new ServerConnection(s, this); ctn = ((ServerConnection) r).getConnectionThreadName(); synchronized (serverConnSet) { serverConnSet.add(r); } } else { r = new WebServerConnection(s, (WebServer) this); ctn = ((WebServerConnection) r).getConnectionThreadName(); } t = new Thread(serverConnectionThreadGroup, r, ctn); t.start(); printWithThread("handleConnection() exited"); } /** * Retrieves whether this server calls System.exit() when shutdown. * * @return true if this server does not call System.exit() * * @jmx.managed-attribute * access="read-write" * description="When Shutdown" */ public boolean isNoSystemExit() { return serverProperties.isPropertyTrue( ServerConstants.SC_KEY_NO_SYSTEM_EXIT); } /** * Retrieves whether this server restarts on shutdown. * * @return true this server restarts on shutdown * * @jmx.managed-attribute * access="read-write" * description="Automatically?" */ public boolean isRestartOnShutdown() { return serverProperties.isPropertyTrue( ServerConstants.SC_KEY_AUTORESTART_SERVER); } /** * Retrieves whether silent mode operation was requested in * the server properties. * * @return if true, silent mode was requested, else trace messages * are to be printed * * @jmx.managed-attribute * access="read-write" * description="No trace messages?" */ public boolean isSilent() { return isSilent; } /** * Retrieves whether the use of secure sockets was requested in the * server properties. *
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -