Browse files

Merge pull request #20 from jjcomer/master

Allow for the thread pool to use daemon threads.
  • Loading branch information...
2 parents 76065ea + fa409ad commit b1743fcea9a04f27e7a2762b26bb8bec71f621a5 @weavejester weavejester committed Sep 29, 2012
View
8 ring-jetty-adapter/src/ring/adapter/jetty.clj
@@ -66,6 +66,7 @@
:port - the port to listen on (defaults to 80)
:host - the hostname to listen on
:join? - blocks the thread until server ends (defaults to true)
+ :daemon? - use daemon threads (defaults to false)
:ssl? - allow connections over HTTPS
:ssl-port - the SSL port to listen on (defaults to 443, implies :ssl?)
:keystore - the keystore to use for SSL connections
@@ -76,10 +77,13 @@
:client-auth - SSL client certificate authenticate, may be set to :need,
:want or :none (defaults to :none)"
[handler options]
- (let [^Server s (create-server (dissoc options :configurator))]
+ (let [^Server s (create-server (dissoc options :configurator))
+ ^QueuedThreadPool p (QueuedThreadPool. (options :max-threads 50))]
+ (when (:daemon? options false)
+ (.setDaemon p true))
(doto s
(.setHandler (proxy-handler handler))
- (.setThreadPool (QueuedThreadPool. (options :max-threads 50))))
+ (.setThreadPool p))
(when-let [configurator (:configurator options)]
(configurator s))
(.start s)
View
16 ring-jetty-adapter/test/ring/adapter/test/jetty.clj
@@ -42,7 +42,7 @@
(is (= (:body response) "Hello World")))))
(testing "configurator set to run last"
- (let [max-threads 20
+ (let [max-threads 20
new-handler (proxy [AbstractHandler] []
(handle [_ ^Request base-request request response]))
threadPool (QueuedThreadPool. ({} :max-threads max-threads))
@@ -56,6 +56,20 @@
(is (= 1 (count (.getHandlers server))))
(.stop server)))
+ (testing "setting daemon threads"
+ (testing "default (daemon off)"
+ (let [server (run-jetty hello-world {:port 4347 :join? false})]
+ (is (not (.. server getThreadPool isDaemon)))
+ (.stop server)))
+ (testing "daemon on"
+ (let [server (run-jetty hello-world {:port 4347 :join? false :daemon? true})]
+ (is (.. server getThreadPool isDaemon))
+ (.stop server)))
+ (testing "daemon off"
+ (let [server (run-jetty hello-world {:port 4347 :join? false :daemon? false})]
+ (is (not (.. server getThreadPool isDaemon)))
+ (.stop server))))
+
(testing "default character encoding"
(with-server (content-type-handler "text/plain") {:port 4347}
(let [response (http/get "http://localhost:4347")]

0 comments on commit b1743fc

Please sign in to comment.