   (:import (fault ServiceExecutor
                   MultipleWriterResilientPromise
                   ResilientPromise
-                  ResilientAction)))
+                  ResilientAction RejectedActionException)
+           (java.util ArrayList)))
 
 (set! *warn-on-reflection* true)
 

        service-count (count key->service)
        rand-fn (fn [] (rand-int service-count))]
    (assert (>= service-count action-count))
    (->Shotgun context
               (if (= service-count action-count)
                 (fn []
                   key-service-tuples)

          (map #(nth key-service-tuples %)
               (take service-count (iterate next-fn start-idx))))))))

(deftype Shotgun [action-count context shotgun-fn]
  ComposedService
  (submit-action [this action-fn timeout-millis]
    (let [^ResilientPromise promise (MultipleWriterResilientPromise.)
          rejects (ArrayList. ^long action-count)]
      (doseq [[key service] (shotgun-fn)
              :let [svc-context (get context key)]]
        (try
          (.submitAction ^ServiceExecutor (:service-executor service)
                         (reify ResilientAction (run [_] (action-fn svc-context)))
                         promise
                         timeout-millis)
          (catch RejectedActionException e (.add rejects (.reason e)))))
      (when (not= (count rejects) action-count)
        (future/->CLJResilientFuture promise))))
  (submit-action-map [this key->fn timeout-millis]
    (let [^ResilientPromise promise (MultipleWriterResilientPromise.)
          rejects (ArrayList. ^long action-count)]
      (doseq [[key service] (shotgun-fn)
              :let [fn (get key->fn key)]]
        (try
          (.submitAction ^ServiceExecutor (:service-executor service)
                         (reify ResilientAction (run [_] (fn)))
                         promise
                         timeout-millis)
          (catch RejectedActionException e (.add rejects (.reason e)))))
      (when (not= (count rejects) action-count)
        (future/->CLJResilientFuture promise))))
  (perform-action [this action-fn]
    (throw (UnsupportedOperationException. "Cannot perform action with Shotgun")))
  (perform-action-map [this key->fn]
