Skip to content

Commit

Permalink
moving all services to keyword, remove java md client/worker implemen…
Browse files Browse the repository at this point in the history
…tation
  • Loading branch information
joshrotenberg committed Dec 22, 2011
1 parent 2c95193 commit 9612b58
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 114 deletions.
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -138,7 +138,7 @@ Majordomo API already written in they guide, but any language that has

See the tests. Most are written as useful examples:
* echo - the standard echo scenario served up a few different ways
* reverse - standard and DSL APIs to create some reverse worker examples
* reverse - standard and DSL APIs to create some reverse worker examples, lots of comments too
* http - an http frontended parallel echo system

## TODO
Expand All @@ -150,7 +150,7 @@ See the tests. Most are written as useful examples:

## License

Copyright (C) 2011 Josh Rotenberg
Portions (C) 2011 Arkadiusz Orzechowski
* Copyright (C) 2011 Josh Rotenberg
* Portions (C) 2011 Arkadiusz Orzechowski

Distributed under the Eclipse Public License, the same as Clojure.
8 changes: 4 additions & 4 deletions src/clj/md_clj/client.clj
Expand Up @@ -23,23 +23,23 @@
(defmulti send! (fn [client service request] (class request)))

(defmethod send! ZMsg [client service request]
(.send (:client client) service request))
(.send (:client client) (name service) request))

(defmethod send! String [client service request]
(let [r (ZMsg.)
_ (.add r (ZFrame. request))]
(.send (:client client) service r)))
(.send (:client client) (name service) r)))

(defmethod send! (Class/forName "[B") [client service request]
(let [r (ZMsg.)
_ (.add r (ZFrame. request))]
(.send (:client client) service r)))
(.send (:client client) (name service) r)))

(defmethod send! ::collection [client service request]
(let [r (ZMsg.)]
(doseq [s request]
(.add r (ZFrame. s)))
(.send (:client client) service r)))
(.send (:client client) (name service) r)))

(defn recv
"Receive from an asynchronous request."
Expand Down
2 changes: 1 addition & 1 deletion src/clj/md_clj/worker.clj
Expand Up @@ -7,7 +7,7 @@

(defn new-worker
[service endpoint function]
(Worker. service endpoint *worker-debug* function))
(Worker. (name service) endpoint *worker-debug* function))

(defn run
"Run the worker."
Expand Down
30 changes: 0 additions & 30 deletions src/jvm/mdclient.java

This file was deleted.

34 changes: 0 additions & 34 deletions src/jvm/mdclient2.java

This file was deleted.

27 changes: 0 additions & 27 deletions src/jvm/mdworker.java

This file was deleted.

12 changes: 6 additions & 6 deletions test/md_clj/test/echo.clj
Expand Up @@ -22,15 +22,15 @@

(deftest echo-test
(let [echo-worker (mdw/new-worker
"echo" "tcp://localhost:5555"
:echo "tcp://localhost:5555"
(fn [request reply]
(doall (map #(.add reply %) (.toArray request)))))
echo-client (mdc/new-client "tcp://localhost:5555")]

(future (mdw/run echo-worker))
(time
(doseq [x random-strings]
(let [reply (mdc/send! echo-client "echo" x)]
(let [reply (mdc/send! echo-client :echo x)]

(is (= x (-> (.toArray reply)
first
Expand All @@ -41,7 +41,7 @@
;; all the results
(deftest echo-async-test
(let [echo-async-worker (mdw/new-worker
"echo-async" "tcp://localhost:5555"
:echo-async "tcp://localhost:5555"
(fn [request reply]
(doall (map #(.add reply %) (.toArray request)))))
echo-async-client (mdc/new-client "tcp://localhost:5555" true)]
Expand All @@ -51,7 +51,7 @@
(doseq [x random-strings]
(let [request (ZMsg.)
_ (.addString request x)]
(mdc/send! echo-async-client "echo-async" request)))
(mdc/send! echo-async-client :echo-async request)))

(doseq [x random-strings]
(let [reply (mdc/recv echo-async-client)]
Expand All @@ -63,7 +63,7 @@
(deftest echo-multi-test
(let [echo-workers (repeat 10
(mdw/new-worker
"echo-multi"
:echo-multi
"tcp://localhost:5555"
(fn [request reply]
;;(Thread/sleep 500)
Expand All @@ -76,7 +76,7 @@

(time
(doseq [x random-strings]
(let [reply (mdc/send! echo-client "echo-multi" x)]
(let [reply (mdc/send! echo-client :echo-multi x)]
(is (= x (-> (.toArray reply)
first
.getData
Expand Down
6 changes: 3 additions & 3 deletions test/md_clj/test/http.clj
Expand Up @@ -21,7 +21,7 @@

;; the echo worker itself
(def echo-http-worker
(mdw/new-worker "echo-http" "tcp://localhost:5555" echo-handler))
(mdw/new-worker :echo-http "tcp://localhost:5555" echo-handler))

;; the client
(def echo-http-md-client (mdc/new-client "tcp://localhost:5555"))
Expand All @@ -35,7 +35,7 @@
(let [body (slurp* (:body request))
request (ZMsg.)
_ (.addString request body)
reply (mdc/send! echo-http-md-client "echo-http" request)]
reply (mdc/send! echo-http-md-client :echo-http request)]
(-> (.toArray reply)
first
.getData
Expand All @@ -58,7 +58,7 @@
(doseq [x random-strings]
(let [request (ZMsg.)
_ (.addString request x)
reply (mdc/send! echo-http-md-client "echo-http" request)]
reply (mdc/send! echo-http-md-client :echo-http request)]
(is (= x (-> (.toArray reply)
first
.getData
Expand Down
18 changes: 12 additions & 6 deletions test/md_clj/test/reverse.clj
Expand Up @@ -17,11 +17,11 @@

(deftest reverse-test
(let [reverse-worker (mdw/new-worker
"reverse" "tcp://localhost:5555" reverse-fn)
:reverse "tcp://localhost:5555" reverse-fn)
reverse-client (mdc/new-client "tcp://localhost:5555")]

(future (mdw/run reverse-worker))
(let [reply (mdc/send! reverse-client "reverse" ["bar" "foo"])]
(let [reply (mdc/send! reverse-client :reverse ["bar" "foo"])]
(is (= "rab" (-> (.toArray reply)
first
.getData
Expand Down Expand Up @@ -70,14 +70,20 @@
"two"])
;; async clients work similarly with the following exceptions:
;; each element in the collection is sent independently, and all
;; elements are sent immediately. then the results are collected
;; and returned in order.
;; elements are sent before any responses are fetched. responses
;; should be in the same order requests were sent. this is a handy
;; way to send a bunch of single item requests at once, but of course
;; you can also make a worker than handles multiple items at the same
;; time

;; makes two async requests, one for boof and one for chuh. once
;; both have been sent, calls recv and collects/returns the response
reply-one-async (mdc/as-client-async :reverse-one ep ["boof" "chuh"])
;; makes three async requests, one for duh, one for [boof], and
;; one for [what, now]. see the note above regarding workers that

;; makes three async requests, one for duh, one for [boof],
;; and one for [what, now]. this is a decent way to send a
;; batch of requests that may contain multiple items.
;; see the note above regarding workers that
;; may need to handle requests with one or more items.
reply-more-async (mdc/as-client-async :reverse-more ep
["duh"
Expand Down

0 comments on commit 9612b58

Please sign in to comment.