Repository: calcite Updated Branches: refs/heads/master 1594ed571 -> 5149568ce
[CALCITE-936] Make HttpServer configurable (Navis Ryu) Close apache/calcite#161 Project: http://git-wip-us.apache.org/repos/asf/calcite/repo Commit: http://git-wip-us.apache.org/repos/asf/calcite/commit/b94f4d72 Tree: http://git-wip-us.apache.org/repos/asf/calcite/tree/b94f4d72 Diff: http://git-wip-us.apache.org/repos/asf/calcite/diff/b94f4d72 Branch: refs/heads/master Commit: b94f4d7240393ddd0e342917638462666eb44cba Parents: 1594ed5 Author: navis.ryu <[email protected]> Authored: Mon Oct 26 13:32:39 2015 +0900 Committer: Julian Hyde <[email protected]> Committed: Mon Nov 2 16:35:56 2015 -0800 ---------------------------------------------------------------------- .../calcite/avatica/server/HttpServer.java | 32 +++++++++++++++++--- site/_docs/avatica_overview.md | 26 +++++++++++++++- 2 files changed, 53 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/calcite/blob/b94f4d72/avatica-server/src/main/java/org/apache/calcite/avatica/server/HttpServer.java ---------------------------------------------------------------------- diff --git a/avatica-server/src/main/java/org/apache/calcite/avatica/server/HttpServer.java b/avatica-server/src/main/java/org/apache/calcite/avatica/server/HttpServer.java index ccfb629..161a752 100644 --- a/avatica-server/src/main/java/org/apache/calcite/avatica/server/HttpServer.java +++ b/avatica-server/src/main/java/org/apache/calcite/avatica/server/HttpServer.java @@ -29,6 +29,9 @@ import org.eclipse.jetty.util.thread.QueuedThreadPool; /** * Avatica HTTP server. + * + * <p>If you need to change the server's configuration, override the + * {@link #configureConnector(ServerConnector, int)} method in a derived class. */ public class HttpServer { private static final Log LOG = LogFactory.getLog(HttpServer.class); @@ -37,6 +40,10 @@ public class HttpServer { private int port = -1; private final Handler handler; + public HttpServer(Handler handler) { + this(0, handler); + } + public HttpServer(int port, Handler handler) { this.port = port; this.handler = handler; @@ -52,10 +59,8 @@ public class HttpServer { server = new Server(threadPool); server.manage(threadPool); - final ServerConnector connector = new ServerConnector(server); - connector.setIdleTimeout(60 * 1000); - connector.setSoLingerTime(-1); - connector.setPort(port); + final ServerConnector connector = configureConnector(new ServerConnector(server), port); + server.setConnectors(new Connector[] { connector }); final HandlerList handlerList = new HandlerList(); @@ -71,6 +76,25 @@ public class HttpServer { LOG.info("Service listening on port " + getPort() + "."); } + /** + * Configures the server connector. + * + * <p>The default configuration sets a timeout of 1 minute and disables + * TCP linger time. + * + * <p>To change the configuration, override this method in a derived class. + * The overriding method must call its super method. + * + * @param connector connector to be configured + * @param port port number handed over in constructor + */ + protected ServerConnector configureConnector(ServerConnector connector, int port) { + connector.setIdleTimeout(60 * 1000); + connector.setSoLingerTime(-1); + connector.setPort(port); + return connector; + } + public void stop() { if (server == null) { throw new RuntimeException("Server is already stopped"); http://git-wip-us.apache.org/repos/asf/calcite/blob/b94f4d72/site/_docs/avatica_overview.md ---------------------------------------------------------------------- diff --git a/site/_docs/avatica_overview.md b/site/_docs/avatica_overview.md index 54860cf..6c77eb9 100644 --- a/site/_docs/avatica_overview.md +++ b/site/_docs/avatica_overview.md @@ -38,7 +38,6 @@ The Java implementation uses Jackson to convert request/response command objects to/from JSON. Avatica-Server is a Java implementation of Avatica RPC. -It embeds the Jetty HTTP server. Core concepts: @@ -64,6 +63,31 @@ implementation in Java. The ODBC client would be written in C or C++. Since the Avatica protocol abstracts many of the differences between providers, the same ODBC client could be used for different databases. +## HTTP Server + +Avatica-server embeds the Jetty HTTP server, providing a class +[HttpServer]({{ site.apiRoot }}/org/apache/calcite/avatica/server/HttpServer.html) +that implements the Avatica RPC protocol +and can be run as a standalone Java application. + +Connectors in HTTP server can be configured if needed by extending +`HttpServer` class and overriding its `configureConnector()` method. +For example, user can set `requestHeaderSize` to 64K bytes as follows: + +{% highlight java %} +HttpServer server = new HttpServer(handler) { + @Override + protected ServerConnector configureConnector( + ServerConnector connector, int port) { + HttpConnectionFactory factory = (HttpConnectionFactory) + connector.getDefaultConnectionFactory(); + factory.getHttpConfiguration().setRequestHeaderSize(64 << 10); + return super.configureConnector(connector, port); + } +}; +server.start(); +{% endhighlight %} + ## Project structure We know that it is important that client libraries have minimal dependencies.
