            com.lmax.disruptor.RingBuffer
            com.lmax.disruptor.dsl.Disruptor
            com.lmax.disruptor.EventFactory
+           com.lmax.disruptor.EventTranslatorOneArg
            com.lmax.disruptor.EventHandler)
   (:require [com.stuartsierra.component :as component]
             [clojure.tools.logging      :refer [warn]]

(defcounter cnt-queue)
(defcounter cnt-errors)
(defonce default-poolsize 4)
(defonce default-capacity (int 10e2))

(defprotocol QueueEngine
  (consume! [this k opts f])

  (reify EventFactory
    (newInstance [this]
      (ctor))))

(defprotocol WrapperEvent
  (get-data [_])
  (set-data [this v]))

;; For sakes of prototyping, we are using the mutable
;; wrapper. This is not very idiomatic to ring buffer,
;; so it's better to use mutable bags of primitives.
;; If the approach with RB proves itself, we will migrate
;; the code to use it.
(deftype Event [^{:volatile-mutable true} x]
  WrapperEvent
  (get-data [_] x)
  (set-data [this v] (set! x v)))

(defn wrapper-event-factory
  []
  (make-event-factory
   (fn [] (Event. nil))))

(defn threadpool
  [sz]
