Permalink
Browse files

code cleanup, encourage user to use a;ter-var-root to change configur…

…able items across multiple threads
  • Loading branch information...
1 parent de66b01 commit ea32d38fc4967bee6bd3987964c86fa87a637db8 @sunng87 committed Oct 20, 2012
Showing with 40 additions and 51 deletions.
  1. +29 −36 src/slacker/client/common.clj
  2. +11 −15 src/slacker/server.clj
@@ -49,44 +49,38 @@
(inspect [this cmd args])
(close [this]))
-(deftype SlackerClient [conn rmap trans-id-gen content-type ob-init ob-max]
+(deftype SlackerClient [conn rmap trans-id-gen content-type]
SlackerClientProtocol
(sync-call-remote [this ns-name func-name params]
- (binding [*ob-init* ob-init
- *ob-max* ob-max]
- (let [fname (str ns-name "/" func-name)
- tid (swap! trans-id-gen inc)
- request (make-request tid content-type fname params)
- prms (promise)]
- (swap! rmap assoc tid {:promise prms})
- (send conn request)
- (deref prms *timeout* nil)
- (if (realized? prms)
- (handle-response @prms)
- (do
- (swap! rmap dissoc tid)
- (throw+ {:error :timeout}))))))
+ (let [fname (str ns-name "/" func-name)
+ tid (swap! trans-id-gen inc)
+ request (make-request tid content-type fname params)
+ prms (promise)]
+ (swap! rmap assoc tid {:promise prms})
+ (send conn request)
+ (deref prms *timeout* nil)
+ (if (realized? prms)
+ (handle-response @prms)
+ (do
+ (swap! rmap dissoc tid)
+ (throw+ {:error :timeout})))))
(async-call-remote [this ns-name func-name params cb]
- (binding [*ob-init* ob-init
- *ob-max* ob-max]
- (let [fname (str ns-name "/" func-name)
- tid (swap! trans-id-gen inc)
- request (make-request tid content-type fname params)
- prms (promise)]
- (swap! rmap assoc tid {:promise prms :callback cb :async? true})
- (send conn request)
- prms)))
+ (let [fname (str ns-name "/" func-name)
+ tid (swap! trans-id-gen inc)
+ request (make-request tid content-type fname params)
+ prms (promise)]
+ (swap! rmap assoc tid {:promise prms :callback cb :async? true})
+ (send conn request)
+ prms))
(inspect [this cmd args]
- (binding [*ob-init* ob-init
- *ob-max* ob-max]
- (let [tid (swap! trans-id-gen inc)
- request (make-inspect-request tid cmd args)
- prms (promise)]
- (swap! rmap assoc tid {:promise prms :type :inspect})
- (send conn request)
- (deref prms *timeout* nil)
- (if (realized? prms)
- (parse-inspect-response @prms)))))
+ (let [tid (swap! trans-id-gen inc)
+ request (make-inspect-request tid cmd args)
+ prms (promise)]
+ (swap! rmap assoc tid {:promise prms :type :inspect})
+ (send conn request)
+ (deref prms *timeout* nil)
+ (if (realized? prms)
+ (parse-inspect-response @prms))))
(close [this]
(link.core/close conn)))
@@ -133,8 +127,7 @@
client (tcp-client host port handler
:codec slacker-base-codec
:tcp-options tcp-options)]
- ; Passing in currently bound values of *ob-init*, *ob-max*
- (SlackerClient. client rmap (atom 0) content-type *ob-init* *ob-max*)))
+ (SlackerClient. client rmap (atom 0) content-type)))
(defn invoke-slacker
"Invoke remote function with given slacker connection.
View
@@ -123,22 +123,19 @@
:else (-handle-request req server-pipeline
client-info inspect-handler)))
-(defn- create-server-handler [funcs interceptors acl debug ob-init ob-max]
+(defn- create-server-handler [funcs interceptors acl]
(let [server-pipeline (build-server-pipeline funcs interceptors)
inspect-handler (build-inspect-handler funcs)]
(create-handler
(on-message [ch data addr]
- (binding [*debug* debug
- *ob-init* ob-init
- *ob-max* ob-max]
- (let [client-info {:remote-addr addr}
- result (handle-request
- server-pipeline
- data
- client-info
- inspect-handler
- acl)]
- (send ch result))))
+ (let [client-info {:remote-addr addr}
+ result (handle-request
+ server-pipeline
+ data
+ client-info
+ inspect-handler
+ acl)]
+ (send ch result)))
(on-error [ch ^Exception e]
(log/error e "Unexpected error in event loop")
(close ch)))))
@@ -198,7 +195,7 @@
:as options}]
(let [exposed-ns (if (coll? exposed-ns) exposed-ns [exposed-ns])
funcs (apply merge (map ns-funcs exposed-ns))
- handler (create-server-handler funcs interceptors acl *debug* *ob-init* *ob-max*)]
+ handler (create-server-handler funcs interceptors acl)]
(when *debug* (doseq [f (keys funcs)] (println f)))
@@ -208,7 +205,6 @@
:ordered? false
:tcp-options tcp-options)
(when-not (nil? http)
- (http-server http (apply slacker-ring-app exposed-ns options)
- :debug *debug*))))
+ (http-server http (apply slacker-ring-app exposed-ns options)))))

0 comments on commit ea32d38

Please sign in to comment.