Skip to content

Commit

Permalink
Merge pull request #37 from AppsFlyer/better-client-events
Browse files Browse the repository at this point in the history
better client-events
  • Loading branch information
barkanido authored Jul 30, 2020
2 parents b536e0d + 8e82972 commit 16542a8
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ aerospike-clj.iml
/.lein-failures
target
.nrepl-port
.lsp
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#### VERSION 0.6.0
* Support ClientEvents vector to be a vector of completions instead of a single one.
* Bump aerospike lib to 4.4.15

#### VERSION 0.5.1
* Added batch-exsits
* Bump aerospike lib to 4.4.10
Expand Down
8 changes: 4 additions & 4 deletions project.clj
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
(defproject aerospike-clj "0.5.5"
(defproject aerospike-clj "0.6.0"
:description "An Aerospike Clojure client."
:url "https://github.com/AppsFlyer/aerospike-clj"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[com.aerospike/aerospike-client "4.4.10"]
:dependencies [[com.aerospike/aerospike-client "4.4.15"]
[manifold "0.1.8"]]
:plugins [[lein-codox "0.10.5"]]
:codox {:output-path "codox"
Expand All @@ -12,9 +12,9 @@
:profiles {:dev {:plugins [[jonase/eastwood "0.3.5"]
[lein-cloverage "1.1.1"]]
:dependencies [[org.clojure/clojure "1.10.1"]
[criterium "0.4.5"]
[criterium "0.4.6"]
[cheshire "5.10.0"]
[com.taoensso/timbre "4.10.0"]
[danlentz/clj-uuid "0.1.9"]
[com.fasterxml.jackson.core/jackson-databind "2.10.2"]]
[com.fasterxml.jackson.core/jackson-databind "2.11.1"]]
:global-vars {*warn-on-reflection* true}}})
13 changes: 7 additions & 6 deletions src/aerospike_clj/client.clj
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@
:client-policy - a ready ClientPolicy
\"username\"
:port (default is 3000)
:client-events an implementation of ClientEvents"
:client-events an implementation of ClientEvents. Either a single one or a vector
thereof. In the case of a vector, the client will chain the instances by order."
([hosts aero-ns]
(init-simple-aerospike-client hosts aero-ns {}))
([hosts aero-ns conf]
Expand All @@ -74,7 +75,7 @@
:el event-loops
:dbns aero-ns
:cluster-name cluster-name
:client-events (:client-events conf)}))))
:client-events (utils/vectorize (:client-events conf))}))))

(defn stop-aerospike-client
"gracefully stop a client, waiting until all async operations finish."
Expand All @@ -95,13 +96,13 @@
"A continuation function. Registered on the operation future and called when operations fails."))

(defn- register-events [op-future db op-name index op-start-time]
(if-let [client-events (:client-events db)]
(doseq [ce (:client-events db)]
(-> op-future
(d/chain' (fn [op-result]
(on-success client-events op-name op-result index op-start-time db)))
(on-success ce op-name op-result index op-start-time db)))
(d/catch' (fn [op-exception]
(on-failure client-events op-name op-exception index op-start-time db))))
op-future))
(on-failure ce op-name op-exception index op-start-time db)))))
op-future)

(defn- ^ExistsListener reify-exists-listener [op-future]
(reify ExistsListener
Expand Down
10 changes: 10 additions & 0 deletions src/aerospike_clj/utils.clj
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,13 @@
"An optimized way to convert vectors into Java arrays of type `cls`"
[cls v]
(.toArray ^Collection v ^"[Ljava.lang.Object;" (make-array cls (count v))))

(defn vectorize
"convert a single value to a vector or any collection to the equivalent vector.
NOTE: a map or a set have no defined order so vectorize them is not allowed"
[v]
(cond
(or (map? v) (set? v)) (throw (IllegalArgumentException. "undefined sequence order for argument"))
(or (nil? v) (vector? v) (seq? v)) (vec v)
:else [v]))

11 changes: 11 additions & 0 deletions test/aerospike_clj/utils_test.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
(ns aerospike-clj.utils-test
(:require [clojure.test :refer [deftest is]]
[aerospike-clj.utils :as utils]))

(deftest vectorize
(is (= [1] (utils/vectorize 1)))
(is (= [] (utils/vectorize nil)))
(is (= [1 2 3] (utils/vectorize '(1 2 3))))
(is (= [1 2 3] (utils/vectorize [1 2 3])))
(is (thrown? IllegalArgumentException (utils/vectorize #{1 2 3})))
(is (thrown? IllegalArgumentException (utils/vectorize {1 2}))))

0 comments on commit 16542a8

Please sign in to comment.