On Sat, Jan 19, 2013 at 5:24 AM, faenvie <fanny.aen...@gmx.de> wrote:
> i have learned that for a ring/compojure-app the embedded jetty
> service can be started like this:
>
> (def app (handler/site routes))
>
> (defn start [port]
>   (ring/run-jetty (var app) {:port (or port 8080)
>                                      :join? false}))
>
> can anyone explain, what is the var for ? why '(var app)' or #'app ?
> i found some remarks about being able to change the app without
> having to restart the server but how exactly does this relate ?

If you pass in the app as it is, then the var gets evaluated to the
function that the var refers to and the jetty adapter uses that
function to run the server.

Now if you recompile your ring handlers (aka functions) the same app
var will get rebound to a new function while the jetty server will
continue holding on to the old handler function, so if you refresh the
page, etc. you won't see the change on your browser. You will have to
kill the server and restart jetty.

If you pass just the var instead, jetty holds on to the container (the
var) and not the value. The jetty-adapter derefs the var on every
request and sends the response back. As a result if you recompile your
handlers you'll see the effects immediately without restarting the
server.

The derefing has a penalty, albeit minor. Thus, you may choose to not
pass in the app as a var in production deployments.

Regards,
BG



--
Baishampayan Ghose
b.ghose at gmail.com

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to