Struct cocaine::service::unicorn::Unicorn[][src]

pub struct Unicorn { /* fields omitted */ }

Wraps a Service, providing a convenient interface to the Unicorn service.

The Unicorn service is a Cloud Configuration Service. It provides an ability to save, read and subscribe for your configuration updates in a strongly-consistent way. Thus all values have some epoch number to match the version of the value obtained.

A typical use case is to load the configuration at application start-up. Another use case is to subscribe for configuration updates to be able to be notified on its changes immediately without explicit polling.

Note

It's not recommended to use the Unicorn as a storage for large files, cluster states or something else big enough - a typical node size must count in kilobytes at max.

Methods

impl Unicorn
[src]

Construct a new Unicorn by wrapping the specified Service.

A Service is meant to be properly configured to point at "unicorn" service. Violating this will result in various framing errors.

Creates record at specified path with provided value.

This method returns a optional boolean value of operation result

Examples

use cocaine::{Core, Service};
use cocaine::service::Unicorn;

let mut core = Core::new().unwrap();
let unicorn = Unicorn::new(Service::new("unicorn", &core.handle()));

let future = unicorn.create("/cocaine/config", &vec![1,2,3], None);

let result: bool = core.run(future).unwrap();

Writes record at specified path with provided version.

This method returns a optional boolean value of operation result, plus assigned version.

Examples

use cocaine::{Core, Service};
use cocaine::service::Unicorn;

let mut core = Core::new().unwrap();
let unicorn = Unicorn::new(Service::new("unicorn", &core.handle()));

let future = unicorn.put("/cocaine/config", &vec![1,2,3], None);

let result: (bool, i64) = core.run(future).unwrap();

Deletes the record at specified path with provided version.

This method returns a optional boolean value of operation result.

Examples

use cocaine::{Core, Service};
use cocaine::service::Unicorn;

let mut core = Core::new().unwrap();
let unicorn = Unicorn::new(Service::new("unicorn", &core.handle()));

let future = unicorn.del("/cocaine/config", &(42 as i64), None);

let result: bool = core.run(future).unwrap();

Obtains a value with its version stored at specified path.

This method returns a future with specified Deserialize type.

Examples

use cocaine::{Core, Service};
use cocaine::service::Unicorn;

let mut core = Core::new().unwrap();
let unicorn = Unicorn::new(Service::new("unicorn", &core.handle()));

let future = unicorn.get("/cocaine/config", None);

let (value, version): (Option<String>, i64) = core.run(future).unwrap();

Subscribes for updates for the node at the specified path.

This method returns a future, which can be split into a cancellation token and a stream of versioned node values. In addition it tries to convert received values into the specified Deserialize type.

Errors

Any error occurred is transformed to a stream error (note, that until futures 0.2 errors are not force the stream to be closed).

In addition to common errors this method also emits Error::InvalidDataFraming on failed attempt to deserialize the received value into the specified type.

Subscribes for children updates for the node at the specified path.

This method returns a future, which can be split into a cancellation token and a stream, which will return the actual list of children on each child creation or deletion. Other operations, such as children mutation, are not the subject of this method.

Trait Implementations

impl Clone for Unicorn
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl Debug for Unicorn
[src]

Formats the value using the given formatter. Read more

Auto Trait Implementations

impl Send for Unicorn

impl Sync for Unicorn