Skip to content

Commit

Permalink
and it works\! self-configuring cluster.
Browse files Browse the repository at this point in the history
  • Loading branch information
rosejn committed May 10, 2011
1 parent fc6eef8 commit 9bf488e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
18 changes: 13 additions & 5 deletions src/benchmark/auto_configure.clj
@@ -1,15 +1,23 @@
(ns benchmark.auto-configure
(:use
[plasma config]
[plasma.net peer presence]))
[plasma config api]
[plasma.net peer presence])
(:require [plasma.query.core :as q]
[logjam.core :as log]))

(config :presence true)

(log/repl :peer)
(println "starting peer...")
(def p (peer))

(Thread/sleep 12000)
(println "peer started")

(println "sleeping 10 secs...")
(Thread/sleep 10000)

(let [ps (get-peers p)]
(println "Got" (count ps) "peers\n\n" ps))
(println "n-peers: " (count ps))
(println "peers: \n" ps))

(System/exit)
(close p)
11 changes: 6 additions & 5 deletions src/plasma/net/peer.clj
Expand Up @@ -181,14 +181,15 @@

(defn- setup-peer-presence
[p]
(let [h (local-addr)
p (:port p)
pchan (lamina/filter* #(not (and (= h (:host %)) (= p (:port %))))
(let [p-host (local-addr)
p-port (:port p)
pchan (lamina/filter* #(not (and (= p-host (:host %))
(= p-port (:port %))))
(presence-channel))]
(lamina/receive-all pchan
(fn [{:keys [id host port]}]
(add-peer p id (plasma-url host port))))
(presence-broadcaster (peer-id p) h p (config :presence-period))))
(presence-broadcaster (peer-id p) p-host p-port (config :presence-period))))

(defmulti rpc-handler
"A general purpose rpc multimethod."
Expand Down Expand Up @@ -309,7 +310,7 @@
(setup-peer-graph p)
(on-connect p (partial handle-peer-connection p))

(when (:presence options)
(when (config :presence)
(setup-peer-presence p))
p)))

Expand Down

0 comments on commit 9bf488e

Please sign in to comment.