Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
On slacker server, you can configure interceptors to add custom, additional functions. Each interceptor receives a request map contains information about the function call. You can read / update / add data to this map and pass it to next interceptor (or server handler).
Slacker ships some predefined interceptors which is common used.
slacker.interceptors.stats/function-call-statsis a statistic on how many times each function called via slacker server. The data is exposed via JMX, which you can view with tools like jconsole.
slacker.interceptors.exectime/exectime-statssummarize call time of most recent 50 calls of each function, and expose via JMX.
slacker.interceptors.slowwatchdog/slow-watch-doglogs slow function calls and arguments.
slacker.interceptors.logargs/logargslogs arguments that causes a server side exception.
To add interceptors, using the option
:interceptors when you start slacker server.
(start-slacker-server (the-ns 'slapi) 2104 :interceptors logging-interceptor)
If you have multiple interceptors, you should combine them with macro
(start-slacker-server (the-ns 'slapi) 2104 :interceptors (interceptors logging-interceptor another-interceptor))
Write your own
You are encouraged to write interceptors for your own needs. Slacker has two macros
definterceptor+ for interceptor development.
A practical example of the usage:
(definterceptor logging-interceptor :before (fn [req] (println (str "calling " (:fname req))) req) :after (fn [req] (println (str "called " (:fname req))) req))
Currently, there are two stages
:after to intercept the request processing. You can define interceptor for both of them or either one.
definterceptor+ allows you to use arguments to configure interceptors when using it. A code example:
(definterceptor+ logging-interceptor2 [prefix] :before (fn [req] (println (str prefix "calling " (:fname req))) req) :after (fn [req] (println (str prefix "called " (:fname req))) req)) (start-slacker-server .... :interceptors (interceptors (logging-interceptor2 "=>>")))
You may have more practical example instead :-)
Attributes of the request object available to interceptors are :
:content-typecontent type of the request
:fnamefunction name of the call, as string
:funcfunction of the call
:argsa vector of arguements
:clientclient connection information
:resultthe data returned by the function call
You are free to add your own properties to request by assoc new key-value pairs to it.