Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

Changed with-router and with-deploy to "real functions" too

  • Loading branch information...
commit b1c0b5bba425336500ae90a222b37e025362da75 1 parent b7bd6dc
@gaverhae authored
Showing with 10 additions and 16 deletions.
  1. +8 −11 src/okku/core.clj
  2. +2 −5 test/okku/test/core.clj
19 src/okku/core.clj
@@ -73,12 +73,10 @@
`(cond ~@(mapcat (fn [[v f]] `[(= ~dv ~v) ~f]) (partition 2 forms))
:else (.unhandled ~'this ~dv)))
-(defn- with-router
+(defn with-router
"Adds a router option to a Props object."
[actor-spec r]
- (if r
- `(.withRouter ~actor-spec ~r)
- actor-spec))
+ (.withRouter actor-spec r))
(defn parse-address
"Returns an from either a string representing the address
@@ -93,12 +91,10 @@
(throw (IllegalArgumentException. "spawn:deploy-on should be either a String or a sequence of 3 or 4 elements")))
:else (throw (IllegalArgumentException. "spawn:deploy-on should be either a String or a sequence of 3 or 4 elements"))))
-(defn- with-deploy
+(defn with-deploy
"Adds a deploy option to a Props object."
[actor-spec address]
- (if address
- `(.withDeploy ~actor-spec (Deploy. (RemoteScope. (parse-address ~address))))
- actor-spec))
+ (.withDeploy actor-spec (Deploy. (RemoteScope. (parse-address address)))))
(defmacro spawn
"Spawns a new actor (side-effect) and returns an ActorRef to it. The first
@@ -112,9 +108,10 @@
- `:deploy-on` must be the address of a remote ActorSystem in one of the three forms accepted by parse-address; the actor is remotely spawned on the remote system (as a root actor)."
[actor-spec & {c :in r :router n :name d :deploy-on
:or {c '(.getContext this)}}]
- (let [p (-> actor-spec
- (with-router r)
- (with-deploy d))]
+ (let [p (reduce (fn [acc [opt f]]
+ (if opt `(~f ~acc ~opt) acc))
+ actor-spec `([~r with-router]
+ [~d with-deploy]))]
(if n `(.actorOf ~c ~p ~n)
`(.actorOf ~c ~p))))
7 test/okku/test/core.clj
@@ -11,14 +11,11 @@
(are [x y] (= (macroexpand-1 (quote x)) y)
(okku.core/spawn act) '(.actorOf (.getContext this) act)
(okku.core/spawn act :in asys :router router :name name)
- '(.actorOf asys (.withRouter act router) name)
+ '(.actorOf asys (okku.core/with-router act router) name)
(okku.core/spawn act :deploy-on addr)
(.getContext this)
- (.withDeploy act
- (
- (akka.remote.RemoteScope.
- (okku.core/parse-address addr)))))))
+ (okku.core/with-deploy act addr))))
(deftest test-dispatch-on
(are [x y] (= (macroexpand-1 x) y)
Please sign in to comment.
Something went wrong with that request. Please try again.