riemann.service
Lifecycle protocol for stateful services bound to a core.
all-equal?
macro
(all-equal? a b & forms)
Takes two objects to compare and a list of forms to compare them by.
(all-equiv? foo bar
(class)
(foo 2)
(.getSize))
becomes
(let [a foo
b bar]
(and (= (class a) (class b))
(= (foo 2 a) (foo 2 b))
(= (.getSize a) (.getSize b))))
executor-service
(executor-service name f)
(executor-service name equiv-key f)
Creates a new threadpool executor service … service! Takes a function which generates an ExecutorService. Returns an ExecutorServiceService which provides start/stop/reload/equiv? lifecycle management of that service.
Equivalence-key controls how services are compared to tell if they are equivalent. Services with a nil equivalence key are never equivalent. Otherwise, services are equivalent when their class, name, and equiv-key are equal.
(executor-service* :graphite {foo: 4}
#(ThreadPoolExecutor. 2 ...))
literal-executor-service
macro
(literal-executor-service name executor-service-expr)
Like executor-service, but captures the expression passed to it as the equivalence key. This only works if the expression is literal; if there are any variables or function calls, they will be compared as code, not as their evaluated values.
- OK: (literal-executor-service :io (ThreadPoolExecutor. 2 …))
- OK: (literal-executor-service :io (ThreadPoolExecutor. (inc 1) …))
- BAD: (literal-executor-service :io (ThreadPoolExecutor. x …))
scheduled-task-service
(scheduled-task-service name equiv-key interval delay f)
Returns a ScheduledTaskService which will schedule a task which call (f core) repeatedly every interval
after delay
seconds. Equivalent to other ScheduledTaskService with the same name
, equiv-key
, delay
and interval
. Conflicts with other ScheduledTaskService of the same name.
Service
protocol
Services are components of a core with a managed lifecycle. They’re used for stateful things like connection pools, network servers, and background threads.
members
conflict?
(conflict? service1 service2)
Do these two services conflict with one another? Adding a service to a core replaces any conflicting services.
reload!
(reload! service core)
Informs the service of a change in core.
start!
(start! service)
Starts a service. Must be idempotent.
stop!
(stop! service)
Stops a service. Must be idempotent.
ServiceEquiv
protocol
members
equiv?
(equiv? service1 service2)
Used to identify which services can remain running through a core transition, like reloading. If the old service is equivalent to the new service, the old service may be preserved and used by the new core. Otherwise, the old service may be shut down and replaced by the new.
ServiceStatus
protocol
members
running?
(running? service)
Queries the running state of the service.
thread-service
(thread-service name f)
(thread-service name equiv-key f)
Returns a ThreadService which will call (f core) repeatedly when started. Will only stop between calls to f. Start and stop are blocking operations. Equivalent to other ThreadServices with the same name and equivalence key– if not provided, defaults nil. Conflicts with other ThreadServices of the same name.
threadpool-service
(threadpool-service name)
(threadpool-service name {:keys [core-pool-size max-pool-size keep-alive-time keep-alive-unit queue-size], :as opts, :or {core-pool-size 1, max-pool-size 128, keep-alive-time 10, keep-alive-unit TimeUnit/MILLISECONDS, queue-size 1000}})
An ExecutorServiceService based on a ThreadPoolExecutor with core and maximum threadpool sizes, and a LinkedBlockingQueue of a given size. Options:
- :core-pool-size Default 1
- :max-pool-size Default 128
- :keep-alive-time Default 10
- :keep-alive-unit Default MILLISECONDS
- :queue-size Default 1000