diff --git a/.gitignore b/.gitignore index 4f2bad6..feb8c6c 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ aerospike-clj.iml /.lein-failures target .nrepl-port +.lsp diff --git a/CHANGELOG.md b/CHANGELOG.md index 01c8cb0..950ea34 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/project.clj b/project.clj index bc8fd8f..5b52fd3 100644 --- a/project.clj +++ b/project.clj @@ -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" @@ -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}}}) diff --git a/src/aerospike_clj/client.clj b/src/aerospike_clj/client.clj index bf34c07..635f8bd 100644 --- a/src/aerospike_clj/client.clj +++ b/src/aerospike_clj/client.clj @@ -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] @@ -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." @@ -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 diff --git a/src/aerospike_clj/utils.clj b/src/aerospike_clj/utils.clj index cc72661..c942cd3 100644 --- a/src/aerospike_clj/utils.clj +++ b/src/aerospike_clj/utils.clj @@ -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])) + diff --git a/test/aerospike_clj/utils_test.clj b/test/aerospike_clj/utils_test.clj new file mode 100644 index 0000000..c8554f6 --- /dev/null +++ b/test/aerospike_clj/utils_test.clj @@ -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}))))