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]
impl Unicorn
pub fn new(service: Service) -> Self
[src]
pub fn new(service: Service) -> Self
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.
pub fn create<T, H>(
&self,
path: &str,
value: &T,
headers: H
) -> impl Future<Item = bool, Error = Error> where
T: Serialize,
H: IntoIterator<Item = RawHeader>,
[src]
pub fn create<T, H>(
&self,
path: &str,
value: &T,
headers: H
) -> impl Future<Item = bool, Error = Error> where
T: Serialize,
H: IntoIterator<Item = RawHeader>,
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();
pub fn put<T, H>(
&self,
path: &str,
value: &T,
headers: H
) -> impl Future<Item = (bool, Version), Error = Error> where
T: Serialize,
H: IntoIterator<Item = RawHeader>,
[src]
pub fn put<T, H>(
&self,
path: &str,
value: &T,
headers: H
) -> impl Future<Item = (bool, Version), Error = Error> where
T: Serialize,
H: IntoIterator<Item = RawHeader>,
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();
pub fn del<H>(
&self,
path: &str,
version: &Version,
headers: H
) -> impl Future<Item = bool, Error = Error> where
H: IntoIterator<Item = RawHeader>,
[src]
pub fn del<H>(
&self,
path: &str,
version: &Version,
headers: H
) -> impl Future<Item = bool, Error = Error> where
H: IntoIterator<Item = RawHeader>,
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();
pub fn get<T, H>(
&self,
path: &str,
headers: H
) -> impl Future<Item = (Option<T>, Version), Error = Error> where
T: for<'de> Deserialize<'de>,
H: Into<Option<Vec<RawHeader>>>,
[src]
pub fn get<T, H>(
&self,
path: &str,
headers: H
) -> impl Future<Item = (Option<T>, Version), Error = Error> where
T: for<'de> Deserialize<'de>,
H: Into<Option<Vec<RawHeader>>>,
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();
pub fn subscribe<'a, T, H>(
&self,
path: &str,
headers: H
) -> impl Future<Item = (Close, Box<Stream<Item = (Option<T>, Version), Error = Error> + Send + 'a>), Error = Error> where
T: for<'de> Deserialize<'de> + Send + 'static,
H: Into<Option<Vec<RawHeader>>>,
[src]
pub fn subscribe<'a, T, H>(
&self,
path: &str,
headers: H
) -> impl Future<Item = (Close, Box<Stream<Item = (Option<T>, Version), Error = Error> + Send + 'a>), Error = Error> where
T: for<'de> Deserialize<'de> + Send + 'static,
H: Into<Option<Vec<RawHeader>>>,
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.
pub fn children_subscribe<H>(
&self,
path: &str,
headers: H
) -> impl Future<Item = (Close, Box<Stream<Item = (Version, Vec<String>), Error = Error> + Send>), Error = Error> where
H: Into<Option<Vec<RawHeader>>>,
[src]
pub fn children_subscribe<H>(
&self,
path: &str,
headers: H
) -> impl Future<Item = (Close, Box<Stream<Item = (Version, Vec<String>), Error = Error> + Send>), Error = Error> where
H: Into<Option<Vec<RawHeader>>>,
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]
impl Clone for Unicorn
fn clone(&self) -> Unicorn
[src]
fn clone(&self) -> Unicorn
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl Debug for Unicorn
[src]
impl Debug for Unicorn