Thanks you, this actually works great! Now I have an other question, are there any arguments against doing that with ring-jetty? Is there a possibility that Jetty isolate the requests and those lose context of the descriptor in-between? Or is it fine as long as it's not run as a servlet? If so, is this a scenario where using something like alpeh/http-kit/netty/aloha makes more sense?
On Friday, July 19, 2013 9:49:09 AM UTC-4, Gareth Jones wrote: > > Instead of using the var #'web/app in run-jetty, use a function that takes > your main-db as an argument and returns the routes for your app. You can > use the compojure.core/routes to build your app routes rather than using a > global var. > > > On Fri, Jul 19, 2013 at 3:42 AM, Tarik Ansari <tar...@gmail.com<javascript:> > > wrote: > >> Hello Folks, >> >> I am a complete Clojure newbie and trying to achieve something pretty >> simple and looking for an idiomatic, if I can make it work at all, way to >> do it. >> >> My issue is I need to retain the LevelDB descriptor and share it between >> requests, LevelDB is already thread-safe. >> For example: >> >> (defn -main >> "I don't do a whole lot ... yet." >> [& args] >> >> (println "Opening LevelDB file in db/main") >> (with-open [main-db (db/open "db/main")] >> >> (println "Running server on port 3000") >> (run-jetty #'web/app {:port 3000}))) >> >> Now, how can I access that main-db descriptor in my requests handlers? >> This, obviously won't work, as main-db is not defined in web/app: >> >> (GET "/test" [] >> (db/put main-db (.getBytes "testKey2") (.getBytes "testValue2")) >> "<h1>Hello World</h1>") >> >> >> PS: If it helps anyone for setup, I have made a Clojar for the LevelDB >> JNI Clojure wrapper based on Sedward's: >> https://clojars.org/org.clojars.aircart/leveldb-clj >> >> Thanks in advance for your insight/help! >> >> -- >> -- >> You received this message because you are subscribed to the Google >> Groups "Clojure" group. >> To post to this group, send email to clo...@googlegroups.com<javascript:> >> Note that posts from new members are moderated - please be patient with >> your first post. >> To unsubscribe from this group, send email to >> clojure+u...@googlegroups.com <javascript:> >> For more options, visit this group at >> http://groups.google.com/group/clojure?hl=en >> --- >> You received this message because you are subscribed to the Google Groups >> "Clojure" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to clojure+u...@googlegroups.com <javascript:>. >> For more options, visit https://groups.google.com/groups/opt_out. >> >> >> > > -- -- 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 --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.