Created
December 23, 2011 15:24
-
-
Save bcg/1514458 to your computer and use it in GitHub Desktop.
Clojure Zookeeper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns playbook.core | |
(:use compojure.core | |
playbook.views.index | |
[hiccup.middleware :only (wrap-base-url)] | |
[zookeeper :as zk]) | |
(:require [compojure.route :as route] | |
[compojure.handler :as handler])) | |
(defroutes main-routes | |
(GET "/" [] (index-page)) | |
(route/resources "/") | |
(route/not-found "Page not found")) | |
(def app | |
(-> (handler/site main-routes) | |
(wrap-base-url))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns playbook.views.index | |
(:use | |
[playbook.zk] | |
[hiccup core page-helpers] | |
[zookeeper :as zk])) | |
(defn index-page [] | |
(html5 | |
[:head | |
[:title "Playbook!"] | |
(include-css "/css/style.css")] | |
[:body | |
[:h1 "Playbook!"] | |
[:ul | |
(for [x (zk/children *client* "/pb")] | |
[:li x])]])) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns playbook.zk | |
(:use [zookeeper :as zk])) | |
(def *client* (zk/connect "127.0.0.1:2181" :watcher (fn [event] (println event)))) | |
(when-not (zk/exists *client* "/pb") | |
(zk/create *client* "/pb" :persistent? true)) | |
(when-not (zk/exists *client* "/pb/apps") | |
(zk/create *client* "/pb/apps" :persistent? true)) | |
(when-not (zk/exists *client* "/pb/deps") | |
(zk/create *client* "/pb/deps" :persistent? true)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment