java - Initialization hook for Clojure Noir WAR/Servlet (CloudFoundry) -
java - Initialization hook for Clojure Noir WAR/Servlet (CloudFoundry) -
i'm building clojure noir web application run war file in cloudfoundry.
in project.clj have:
:ring {:handler appname.server/handler}
in server.clj create handler using noir:
(def handler (noir.server/gen-handler {:ns 'appname}))
i build war file using lein ring plugin:
lein ring uberwar
then force cloudfoundry using:
vmc force appname
the request handler works fine , can browse url of application fine.
so question is: right way initialization when application started?
i can next in server.clj:
(when (system/getenv "vcap_application") (init-func))
but there couple problems that. first, seems doing initialization @ wrong time (when code read/eval'd rather on app start). second, protector specific cloudfoundry , there proper general war way this.
i think purpose of contextinitialized method on servletcontextlistener how hook in noir/ring?
figured out looking @ ring source war handling
the project.clj :ring map takes :init keyword so:
:ring {:init appname.server/my-init :handler appname.server/handler}
the my-init function called on application startup.
caveat: apparently balloons amount of memory needed application initial startup. 128m sufficient without initialization. initialization code , app startup failed, had bump memory 256m. suspect init code jvm doesn't have time garbage collect before clojure code compiled/executed.
java clojure war leiningen
Comments
Post a Comment