From 9e77c6d0ae99198981ee3ea4906d7698ec523311 Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Sun, 19 Aug 2012 14:14:53 +0200 Subject: Make the Benki compatible with Immutant. --- project.clj | 16 +++++++++++++++- resources/config.sexp.sample | 3 +++ src/mulk/benki/main.clj | 39 +++++++++++++++++++++++++++++---------- src/mulk/benki/util.clj | 19 ++++++++----------- 4 files changed, 55 insertions(+), 22 deletions(-) diff --git a/project.clj b/project.clj index 464c3d5..b035db4 100644 --- a/project.clj +++ b/project.clj @@ -20,7 +20,7 @@ [org.clojure/tools.logging "0.2.3"] [org.clojure/tools.macro "0.1.1"] [org.clojure/tools.namespace "0.1.0"] - [org.clojure/tools.nrepl "0.0.5"] + ;;[org.clojure/tools.nrepl "0.0.5"] [org.clojure/tools.trace "0.7.1"] ;; Web app utilities @@ -32,6 +32,13 @@ [lamina "0.5.0-alpha3"] ;-alpha4 [noir-async "1.1.0-beta9"] + ;; Trial-by-error dependencies + ;; + ;; Netty 3.5.2.Final seems to be required for + ;; Immutant deployment --- throws weird + ;; NoClassDefFound errors otherwise. + [io.netty/netty "3.5.2.Final"] + ;; Relational database access [clojureql "1.0.3"] [postgresql "9.1-901.jdbc4"] @@ -115,4 +122,11 @@ :source-path "src" ;;:jvm-opts ["-Xms32m"] :main mulk.benki.main + :immutant {:resolve-dependencies true + :context-path "/" + ;;:virtual-host "" + ;;:nrepl-port 4112 + ;;:swank-port 4005 ;alternatively: set in config.sexp + :init mulk.benki.main/init! + } :min-lein-version "2.0.0") diff --git a/resources/config.sexp.sample b/resources/config.sexp.sample index 5f3f696..804117d 100644 --- a/resources/config.sexp.sample +++ b/resources/config.sexp.sample @@ -11,6 +11,9 @@ :tag-base "example.com" :web-port 3001 :mode :production ;or :dev + :swank {:enabled true ;will be assumed true if absent + :port 4005 + :bind "127.0.0.1"} :xmpp {:enabled true ;will be assumed true if absent :user "benki" :service-name "example.com" diff --git a/src/mulk/benki/main.clj b/src/mulk/benki/main.clj index 35f6e03..9849a31 100644 --- a/src/mulk/benki/main.clj +++ b/src/mulk/benki/main.clj @@ -143,17 +143,36 @@ (org.bouncycastle.jce.provider.BouncyCastleProvider.)) (Class/forName "net.java.dev.sommer.foafssl.sesame.verifier.SesameFoafSslVerifier")) +(defn run-immutant-swank! + "Call `immutant.repl/start-swank` with the Swank configuration + specified in `benki-config`. If loading the immutant.repl namespace + fails, ignore the error and return `nil` without doing anything. In + case of success, return true." [] + (when-let [swank-config (get @benki-config :swank)] + (when (and (get swank-config :enabled true) + (try + (require 'immutant.repl) + true + (catch Exception e + false))) + ((ns-resolve 'immutant.repl 'start-swank) + (:bind swank-config) (:port swank-config)) + true))) + +(defn init! [] + (init-config!) + (init-middleware!) + (noir.server/load-views-ns 'mulk.benki) + (init-security!) + (future (run-immutant-swank!)) + (future (require 'mulk.benki.xmpp) + ((ns-resolve 'mulk.benki.xmpp 'init-xmpp!))) + (future (require 'mulk.benki.lazychat) + ((ns-resolve 'mulk.benki.lazychat 'init-lazychat!))) + (future (reset! server (run-server)))) + (defn -main [& args] - (do - (init-config!) - (init-middleware!) - (noir.server/load-views-ns 'mulk.benki) - (init-security!) - (future (require 'mulk.benki.xmpp) - ((ns-resolve 'mulk.benki.xmpp 'init-xmpp!))) - (future (require 'mulk.benki.lazychat) - ((ns-resolve 'mulk.benki.lazychat 'init-lazychat!))) - (future (reset! server (run-server)))) + (init!) (loop [] (Thread/sleep 1000000) (recur))) diff --git a/src/mulk/benki/util.clj b/src/mulk/benki/util.clj index 366e9c0..db27432 100644 --- a/src/mulk/benki/util.clj +++ b/src/mulk/benki/util.clj @@ -8,7 +8,8 @@ [noir.request :as request] [noir.response :as response] [clojure.java.jdbc :as sql] - [clojure.pprint]) + [clojure.pprint] + [clojure.tools.logging :as logging]) (:import [java.text DateFormat] [java.security SecureRandom] [java.math BigInteger] @@ -145,15 +146,11 @@ ;;;; * Debugging -(defonce logger - (org.apache.log4j.Logger/getLogger "eu.mulk.benki")) +(defmacro info [& args] + `(logging/info ~@args)) -(defn info [s] - (.info logger s)) - -(defn log [s] - (.info logger s)) - -(defn debug [s] - (.debug logger s)) +(defmacro debug [& args] + `(logging/debug ~@args)) +(defmacro log [& args] + `(logging/info ~@args)) -- cgit v1.2.3