Permalink
Browse files

Added min-threads and max-threads to opts. Bump to 0.2.4.

  • Loading branch information...
1 parent 2252b02 commit 27f05562422b3d645fe8c199faf87c53fc0bdc80 @zk zk committed Jul 3, 2011
Showing with 24 additions and 9 deletions.
  1. +1 −1 project.clj
  2. +23 −8 src/nsfw/server.clj
View
@@ -1,4 +1,4 @@
-(defproject nsfw "0.2.3"
+(defproject nsfw "0.2.4"
:description "No Such Framework -- Experimental"
:dependencies [[org.clojure/clojure "1.2.0"]
[org.clojure/clojure-contrib "1.2.0"]
View
@@ -13,7 +13,8 @@
;; Restart a server
(restart s)"
- (:require [ring.adapter.jetty :as jetty]))
+ (:require [ring.adapter.jetty :as jetty])
+ (:import [org.mortbay.thread QueuedThreadPool]))
(def opts-defaults
{:port 8080
@@ -27,17 +28,31 @@
:handler entry-handler
:server nil})))
+(defn set-threads [server-atom]
+ (let [server (:server @server-atom)
+ {:keys [max-threads min-threads]}
+ (:opts @server-atom)]
+ (when server
+ (let [tp (.getThreadPool server)]
+ (when min-threads (.setMinThreads tp min-threads))
+ (when max-threads (.setMaxThreads tp max-threads))))))
+
(defn stop [server-atom]
(when-let [server (:server @server-atom)]
(.stop server))
(swap! server-atom assoc :server nil))
-
-(defn restart [server-atom]
- (stop server-atom)
- (let [handler (:handler @server-atom)
- opts (:opts @server-atom)]
- (swap! server-atom
- assoc :server (jetty/run-jetty handler opts))))
+(defn restart [server-atom & override-opts]
+ (let [override-opts (apply hash-map override-opts)
+ opts (merge (:opts @server-atom)
+ override-opts)]
+ (stop server-atom)
+ (let [handler (:handler @server-atom)
+ res (swap! server-atom
+ assoc
+ :opts opts
+ :server (jetty/run-jetty handler opts))]
+ (set-threads server-atom)
+ res)))
(def start restart)

0 comments on commit 27f0556

Please sign in to comment.