(attach component k attach-component)
(attach component k attach-component dependencies)
Attach the given component to this one (associng it using k
and having it depend on dependencies
).
Attach the given component to this one (associng it using `k` and having it depend on `dependencies`).
(concurrently component-seq)
Tag the seq of components as elligible to be concurrently started. The return value is the same sequence of components, but #'start-all will start them concurrently.
Tag the seq of components as elligible to be concurrently started. The return value is the same sequence of components, but #'start-all will start them concurrently.
(connect m src-id dst-id)
(connect m src-id src-key dst-id)
Let the component identified by src-id
be using the component identified
by dst-id
as a dependency to be assoc'd in at the key src-key
.
Let the component identified by `src-id` be using the component identified by `dst-id` as a dependency to be assoc'd in at the key `src-key`.
(defcomponent id dependencies & component-logic)
Create new component type from a vector of dependencies
(the components/fields that should
be filled before the component is started, as well as a series of keyword/start/stop forms.
Each keyword has to be followed by a form that will be executed at startup and optionally a (non-keyword) function to be run at shutdown.
(defcomponent LoopRunner [f interval]
:data (fetch-some-data!)
:thread (doto (Thread. #(while (not (.isInterrupted ...)) ...))
(.start))
#(.interrupt ^Thread %))
The results of the form/function will be assoc'd into the component. Please use the map->...
function to create an instance of the record. Using fields with the namespace peripheral
you
can manipulate the component record directly:
(defcomponent TestComponent [...]
:peripheral/start #(...) ;; called before fields are initialized
:peripheral/started #(...) ;; called after fields are initialized
:peripheral/stop #(...) ;; called before fields are cleaned up
:peripheral/stopped #(...)) ;; called after fields are cleaned up
Note that these take a function, not a form, and only allow for one value!
If you don't need to alter the component record, the 'on' prefix can be used to directly execute forms:
(defcomponent TestComponent [...]
:on/start (println "starting"))
Finally, if you need access to the whole component, you can bind it to a symbol using ':this/as':
(defcomponent TestComponent [x]
:this/as *this*
:y (+ (:x *this*) 10)
:z (- (:y *this*) 5))
Create new component type from a vector of `dependencies` (the components/fields that should be filled before the component is started, as well as a series of keyword/start/stop forms. Each keyword has to be followed by a form that will be executed at startup and optionally a (non-keyword) function to be run at shutdown. ``` (defcomponent LoopRunner [f interval] :data (fetch-some-data!) :thread (doto (Thread. #(while (not (.isInterrupted ...)) ...)) (.start)) #(.interrupt ^Thread %)) ``` The results of the form/function will be assoc'd into the component. Please use the `map->...` function to create an instance of the record. Using fields with the namespace `peripheral` you can manipulate the component record directly: ``` (defcomponent TestComponent [...] :peripheral/start #(...) ;; called before fields are initialized :peripheral/started #(...) ;; called after fields are initialized :peripheral/stop #(...) ;; called before fields are cleaned up :peripheral/stopped #(...)) ;; called after fields are cleaned up ``` Note that these take a function, not a form, and only allow for one value! If you don't need to alter the component record, the 'on' prefix can be used to directly execute forms: ``` (defcomponent TestComponent [...] :on/start (println "starting")) ``` Finally, if you need access to the whole component, you can bind it to a symbol using ':this/as': ``` (defcomponent TestComponent [x] :this/as *this* :y (+ (:x *this*) 10) :z (- (:y *this*) 5)) ```
(defsystem+ id & components)
(defsystem+ id [dependency ...] & components)
Create a new system of components. Example:
(defsystem+ MySystem [^:global configuration, api-options]
:engine []
:monitor [:scheduler :api]
:api [:engine {:options :api-options}]
:scheduler [:engine])
On startup, the following injections will happen:
:configuration
into :engine
, :api
and :scheduler
(since it is
marked as :global
),:engine
into :api
and :scheduler
,:api-options
- aliased as :options
- into :api
,:scheduler
and :api
into :monitor
.It is possible to give default values for each component using the :default
metadata:
(defsystem+ MySystem [...]
:engine ^{:default (default-engine)} []
...)
Unless the key :engine
is present and non-nil on system startup, it'll
be filled with the result of (default-engine)
.
Create a new system of components. Example: (defsystem+ MySystem [^:global configuration, api-options] :engine [] :monitor [:scheduler :api] :api [:engine {:options :api-options}] :scheduler [:engine]) On startup, the following injections will happen: - `:configuration` into `:engine`, `:api` and `:scheduler` (since it is marked as `:global`), - `:engine` into `:api` and `:scheduler`, - `:api-options` - aliased as `:options` - into `:api`, - `:scheduler` and `:api` into `:monitor`. It is possible to give default values for each component using the `:default` metadata: (defsystem+ MySystem [...] :engine ^{:default (default-engine)} [] ...) Unless the key `:engine` is present and non-nil on system startup, it'll be filled with the result of `(default-engine)`.
(detach component k)
Detach the given component key from this component.
Detach the given component key from this component.
(reify-component & component-logic)
(reify-component dependencies & component-logic)
Create a one-off component (i.e. without creating an explicit component
record). The syntax is identical to defcomponent
without the class name.
(let [db-config {...}]
(reify-component
:db (connect! db-config) disconnect!
...))
The resulting value will implement all map interfaces, as well as the
com.stuartsierra.component/Lifecycle
protocol.
Create a one-off component (i.e. without creating an explicit component record). The syntax is identical to [[defcomponent]] without the class name. ``` (let [db-config {...}] (reify-component :db (connect! db-config) disconnect! ...)) ``` The resulting value will implement all map interfaces, as well as the `com.stuartsierra.component/Lifecycle` protocol.
(restart component)
Restart the given component by calling stop
and start
.
Restart the given component by calling `stop` and `start`.
(running? component)
Check whether the component is running (per its metadata).
Check whether the component is running (per its metadata).
(start component)
Begins operation of this component. Synchronous, does not return until the component is started. Returns an updated version of this component.
Begins operation of this component. Synchronous, does not return until the component is started. Returns an updated version of this component.
(stop component)
Ceases operation of this component. Synchronous, does not return until the component is stopped. Returns an updated version of this component.
Ceases operation of this component. Synchronous, does not return until the component is stopped. Returns an updated version of this component.
(subsystem system components)
Create subsystem. The resulting system will only start the given components and their dependencies.
Create subsystem. The resulting system will only start the given components and their dependencies.
(with-start [form component & more] & body)
Start the given component, binding the started component to the given form, ensuring the shutdown of the component after the body has been executed.
Start the given component, binding the started component to the given form, ensuring the shutdown of the component after the body has been executed.
(with-start* component f)
Start the given component, call the given function with the started component as only parameter, then stop the component.
Start the given component, call the given function with the started component as only parameter, then stop the component.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close