Objection helps you manage graphs of stateful objects that acquire resources that are not managed by the garbage collector.
It is good for things like, connection pools, threads, thread pools, queues, channels etc.
Register objects and dependencies via register
, construct
.
Inspect objects with describe
, id
, data
, id-seq
, status
.
Define singletons with defsingleton
and resolve them with singleton
.
Objection helps you manage graphs of stateful objects that acquire resources that are not managed by the garbage collector. It is good for things like, connection pools, threads, thread pools, queues, channels etc. Register objects and dependencies via `register`, `construct`. Inspect objects with `describe`, `id`, `data`, `id-seq`, `status`. Define singletons with `defsingleton` and resolve them with `singleton`.
(alias x alias)
Aliases an object under the provided key, each alias can only be assigned to one object, so make sure it is unique.
Onced aliased the alias can be used interchangably with the object in objection functions on the object.
Aliases an object under the provided key, each alias can only be assigned to one object, so make sure it is unique. Onced aliased the alias can be used interchangably with the object in objection functions on the object.
(alter-data! x f)
(alter-data! x f & args)
Applies f
to the data for the object (i.e supplied under :data key on registry/construct).
Saves and returns the new data.
Applies `f` to the data for the object (i.e supplied under :data key on registry/construct). Saves and returns the new data.
(construct opts & body)
Takes same opts as register
, takes a body that constructs an object and returns it.
locks dependencies before running the body, so they cannot be stopped while this object is being constructed.
See-also: register
Takes same opts as `register`, takes a body that constructs an object and returns it. locks dependencies before running the body, so they cannot be stopped while this object is being constructed. See-also: register
(data x)
Returns the data associated with x
, which can be a registered object, alias or id.
Returns the data associated with `x`, which can be a registered object, alias or id.
(defsingleton k & body)
Defines a singleton that can be returned via (singleton k), if an instance already exists, it is returned - else the body is run to construct the instance.
If you would prefer to return an existing instance without the possibility of constructing the instance if it does not exist, use (object k).
Redefinition of a singleton will stop any existing instances.
Singletons are always implicitly registered after construction and they also receive an alias of the key used in the definition.
To introduce dependencies, stopfn, additional aliases etc, you can register or construct the object in the body of the singleton in the normal way.
Defines a singleton that can be returned via (singleton k), if an instance already exists, it is returned - else the body is run to construct the instance. If you would prefer to return an existing instance without the possibility of constructing the instance if it does not exist, use (object k). Redefinition of a singleton will stop any existing instances. Singletons are always implicitly registered after construction and they also receive an alias of the key used in the definition. To introduce dependencies, stopfn, additional aliases etc, you can register or construct the object in the body of the singleton in the normal way.
(depend x dependency)
Makes x
dependent on dependency
, both can be registered object instances, aliases or ids.
When you (stop! dependency)
objection will make sure that x
is stopped first.
Makes `x` dependent on `dependency`, both can be registered object instances, aliases or ids. When you `(stop! dependency)` objection will make sure that `x` is stopped first.
(dependencies x)
Returns the ids of dependencies of x
.
Returns the ids of dependencies of `x`.
(dependents x)
Returns the ids of the dependents of x
.
Returns the ids of the dependents of `x`.
(depends? x dependency)
Is x
dependent on dependency?
Is `x` dependent on dependency?
(describe x)
Returns information about x
, which can be a registered object, alias or id.
Returns information about `x`, which can be a registered object, alias or id.
A protocol that can be extended to types in order to tell objection how to stop! them if a :stopfn is not provided on registry.
A protocol that can be extended to types in order to tell objection how to stop! them if a :stopfn is not provided on registry.
(-stop! this)
Extend to types to provide a stop behaviour for objects of that type.
Extend to types to provide a stop behaviour for objects of that type.
(id x)
Returns the id of the object if the object is registered.
You can pass the object instance, or an alias of the object.
Returns the id of the object if the object is registered. You can pass the object instance, or an alias of the object.
(id-seq)
Returns the seq of registered object ids.
Returns the seq of registered object ids.
(need x)
(need x error-message)
Tries to resolve x
to a registered object, or singleton - throws an exception with the message if not possible.
Tries to resolve `x` to a registered object, or singleton - throws an exception with the message if not possible.
(object x)
Returns a registered object, can pass either an id, id-prefix, alias or object instance.
Returns a registered object, can pass either an id, id-prefix, alias or object instance.
(register obj)
(register obj opts)
Registers the object with objection and returns it, will assign it an id automatically.
An object can be practically anything, but would be expected to be something like a connection pool or a thread etc.
A registered object is kept alive by objection. Stop the object using the (stop! obj) function. Almost all objection functions can use the object itself, an id, id prefix or alias.
See-also: construct
Opts:
:name
- a human friendly name to use for the object in display functions, doesn't have to be unique.
:aliases
- a sequence of aliases to apply to the object, each alias can be used interchangebly with the object
in objection functions.
:data
- user supplied metadata about the object, retrieve later with (data obj).
:deps
- a sequence of dependencies, supports passing objection ids, aliases or registered objects.
:stopfn
- a function of the object that performs any shutdown logic. Alternatively implement IAutoStoppable
for the type of the object.
Registers the object with objection and returns it, will assign it an id automatically. An object can be practically anything, but would be expected to be something like a connection pool or a thread etc. A registered object is kept alive by objection. Stop the object using the (stop! obj) function. Almost all objection functions can use the object itself, an id, id prefix or alias. See-also: construct Opts: `:name` - a human friendly name to use for the object in display functions, doesn't have to be unique. `:aliases` - a sequence of aliases to apply to the object, each alias can be used interchangebly with the object in objection functions. `:data` - user supplied metadata about the object, retrieve later with (data obj). `:deps` - a sequence of dependencies, supports passing objection ids, aliases or registered objects. `:stopfn` - a function of the object that performs any shutdown logic. Alternatively implement IAutoStoppable for the type of the object.
(rename! x s)
Changes the :name of x
to s
. Then name is intended for display purposes only.
Changes the :name of `x` to `s`. Then name is intended for display purposes only.
(singleton k)
Like (object k
) but if a singleton is registered under the key k
, it will be constructed if necessary
in order to return the instance.
Singleton will always return an instance if one has been defined.
Like (object `k`) but if a singleton is registered under the key `k`, it will be constructed if necessary in order to return the instance. Singleton will always return an instance if one has been defined.
(singleton-keys)
Returns the keys of each registered singleton.
Returns the keys of each registered singleton.
(status)
Prints information about currently registered objects.
Prints information about currently registered objects.
(stop! x)
(stop! x opts)
Runs the stopfn of x
or the type specific AutoStoppable impl. e.g on AutoCloseable objects .close will be called.
Removes the object from the registry.
If an exception is thrown when stopping the object, it will remain in the registry, use the :force? option to unregister on error.
Runs the stopfn of `x` or the type specific AutoStoppable impl. e.g on AutoCloseable objects .close will be called. Removes the object from the registry. If an exception is thrown when stopping the object, it will remain in the registry, use the :force? option to unregister on error.
(stop-all!)
Stops all current registered objects.
Stops all current registered objects.
(undepend x dependency)
Removes a dependency relationship between x
and dependency
, both of which can be registered object instances, aliases or ids.
Removes a dependency relationship between `x` and `dependency`, both of which can be registered object instances, aliases or ids.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close