             entry (extensions/read-log-entry (:log client) position)
             new-replica (extensions/apply-log-entry entry replica)
             diff (extensions/replica-diff entry replica new-replica)]
-        ((:chsk-send! sente) uid [:cluster/replica {:replica new-replica
-                                                    :diff diff}])
+        (send-fn! uid [:deployment/replica {:replica new-replica :diff diff}])
         (recur new-replica)))))
 
 (def env-conf

   :onyx.peer/job-scheduler :onyx.job-scheduler/round-robin 
   :onyx/id :SUPPLY_ME})

(comment (reset! replica-state nil)
         (deref replica-state)
         (clojure.pprint/pprint {:orig orig :new new}))

(defn event->uid [event]
  (get-in event [:ring-req :cookies "ring-session" :value]))

(def tracking (atom {}))

(defn launch-event-handler [sente peer-config]
  (thread
    (loop []
      (let [[event _] (alts!! [(:ch-chsk sente) 
                               #_(:ring-ajax-get-or-ws-handshake sente)])]
        (when event
          (info "EVENT:" event)
          ;; TODO: more sophisticated tracking,
          ;; should track by cluster id rather than user
          ;; and count the number of users tracking it. When the user count drops to 0
          ;; then stop the future.
          (case (:id event) 
            :cluster/track (let [user-id (event->uid event)] 
                             (swap! tracking 
                                    assoc 
                                    user-id
                                    (future (track-cluster sente 
                                                           (assoc env-conf :onyx/id (:?data event)) 
                                                           user-id))))
            :chsk/uidport-close (let [user-id (event->uid event)] 
                                  (future-cancel (@tracking user-id))
                                  (swap! tracking dissoc user-id)) 
            (println "Dunno what to do with: " event))
          (recur))))))

(defrecord HttpServer [peer-config]
  component/Lifecycle
  (start [{:keys [sente] :as component}]

      (GET  "/" [] (page))
      (GET  "/chsk" req ((:ring-ajax-get-or-ws-handshake sente) req))
      (POST "/chsk" req ((:ring-ajax-post sente) req))
      ;(GET "/cluster/:deployment-id" req (get-job-output req))
      ;(GET "/job/:job-id" req (get-job-output req))
      (resources "/")
      (resources "/react" {:root "react"})
      (route/not-found "Page not found"))
    (launch-event-handler sente peer-config)
    (refresh-deployments-watch (partial send-mult-fn 
                                        (:chsk-send! sente) 
                                        (:connected-uids sente)) 
                               (zk/connect (:zookeeper/address env-conf)))

    (let [my-ring-handler (ring.middleware.defaults/wrap-defaults my-routes ring-defaults-config)
          server (http-kit-server/run-server my-ring-handler {:port 3000})
