Lifecycle protocol for stateful services bound to a core.
Lifecycle protocol for stateful services bound to a core.
(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))))
Takes two objects to compare and a list of forms to compare them by. ```clojure (all-equiv? foo bar (class) (foo 2) (.getSize)) ``` becomes ```clojure (let [a foo b bar] (and (= (class a) (class b)) (= (foo 2 a) (foo 2 b)) (= (.getSize a) (.getSize b)))) ```
(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 ...))
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. ```clojure (executor-service* :graphite {foo: 4} #(ThreadPoolExecutor. 2 ...)) ```
(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.
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 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.
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.
Services are components of a core with a managed lifecycle. They're used for stateful things like connection pools, network servers, and background threads.
Services are components of a core with a managed lifecycle. They're used for stateful things like connection pools, network servers, and background threads.
(conflict? service1 service2)
Do these two services conflict with one another? Adding a service to a core replaces any conflicting services.
Do these two services conflict with one another? Adding a service to a core *replaces* any conflicting services.
(reload! service core)
Informs the service of a change in core.
Informs the service of a change in core.
(start! service)
Starts a service. Must be idempotent.
Starts a service. Must be idempotent.
(stop! service)
Stops a service. Must be idempotent.
Stops a service. Must be idempotent.
(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.
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.
(running? service)
Queries the running state of the service.
Queries the running state of the 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.
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 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:
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
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close