Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions ring-jetty-adapter/src/ring/adapter/jetty.clj
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,20 @@
(.setAllowNullPathInfo true)
(JettyWebSocketServletContainerInitializer/configure nil)))

(defn- server-connector ^ServerConnector [^Server server & factories]
(ServerConnector. server #^"[Lorg.eclipse.jetty.server.ConnectionFactory;"
(into-array ConnectionFactory factories)))
(defn- server-connector ^ServerConnector [^Server server factories options]
(let [acceptors (options :acceptor-threads -1)
selectors (options :selector-threads -1)]
(ServerConnector. server (int acceptors) (int selectors)
^"[Lorg.eclipse.jetty.server.ConnectionFactory;"
(into-array ConnectionFactory factories))))

(defn- unix-domain-server-connector ^UnixDomainServerConnector
[^Server server & factories]
(UnixDomainServerConnector. server #^"[Lorg.eclipse.jetty.server.ConnectionFactory;"
(into-array ConnectionFactory factories)))
[^Server server factories options]
(let [acceptors (options :acceptor-threads -1)
selectors (options :selector-threads -1)]
(UnixDomainServerConnector. server (int acceptors) (int selectors)
^"[Lorg.eclipse.jetty.server.ConnectionFactory;"
(into-array ConnectionFactory factories))))

(defn- http-config ^HttpConfiguration [options]
(doto (HttpConfiguration.)
Expand All @@ -196,7 +202,7 @@

(defn- http-connector ^ServerConnector [server options]
(let [http-factory (HttpConnectionFactory. (http-config options))]
(doto (server-connector server http-factory)
(doto (server-connector server [http-factory] options)
(.setPort (options :port 80))
(.setHost (options :host))
(.setIdleTimeout (options :max-idle-time 200000)))))
Expand Down Expand Up @@ -248,7 +254,7 @@
(when-let [scan-interval (options :keystore-scan-interval)]
(.addBean server (doto (KeyStoreScanner. ssl-context)
(.setScanInterval scan-interval))))
(doto (server-connector server ssl-factory http-factory)
(doto (server-connector server [ssl-factory http-factory] options)
(.setPort ssl-port)
(.setHost (options :host))
(.setIdleTimeout (options :max-idle-time 200000)))))
Expand All @@ -257,7 +263,7 @@
(let [http-factory (HttpConnectionFactory. (http-config options))
socket (io/file (options :unix-socket))]
(.deleteOnExit socket)
(doto (unix-domain-server-connector server http-factory)
(doto (unix-domain-server-connector server [http-factory] options)
(.setUnixDomainPath (.toPath socket))
(.setIdleTimeout (options :max-idle-time 200000)))))

Expand Down Expand Up @@ -328,6 +334,8 @@
:thread-pool - custom thread pool instance for Jetty to use
:truststore - a truststore to use for SSL connections
:trust-password - the password to the truststore
:acceptor-threads - the number of acceptor threads to use
:selector-threads - the number of selector threads to use
:max-threads - the maximum number of threads to use (default 50)
:min-threads - the minimum number of threads to use (default 8)
:max-queued-requests - the maximum number of requests to be queued
Expand Down
25 changes: 24 additions & 1 deletion ring-jetty-adapter/test/ring/adapter/test/jetty.clj
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,14 @@
(.send))]
(is (= (.getStatus response) 200))
(is (.getMediaType response) "text/plain")
(is (= (.getContentAsString response) "Hello World")))))))
(is (= (.getContentAsString response) "Hello World"))))
(testing "with custom connector options"
(let [server (run-jetty hello-world {:http? false
:unix-socket test-unix-domain-socket
:join? false
:acceptor-threads 2})]
(is (= 2 (-> server (.getConnectors) first (.getAcceptors))))
(.stop server))))))

(testing "HTTPS server"
(with-server hello-world {:port test-port
Expand Down Expand Up @@ -329,6 +336,22 @@
(is (= 1000 (. thread-pool getIdleTimeout)))
(.stop server)))

(testing "using default connector options"
(let [server (run-jetty hello-world {:port test-port
:join? false})]
(is (>= 1 (-> server (.getConnectors) first (.getAcceptors))))
(is (> (-> server (.getConnectors) first (.getSelectorManager) (.getSelectorCount)) 1))
(.stop server)))

(testing "using custom connector options"
(let [server (run-jetty hello-world {:port test-port
:join? false
:acceptor-threads 2
:selector-threads 8})]
(is (= 2 (-> server (.getConnectors) first (.getAcceptors))))
(is (= 8 (-> server (.getConnectors) first (.getSelectorManager) (.getSelectorCount))))
(.stop server)))

(testing "providing custom thread-pool"
(let [pool (QueuedThreadPool.)
server (run-jetty hello-world {:port test-port
Expand Down
Loading