Struct cocaine::Service [−][src]
pub struct Service { /* fields omitted */ }
A low-level entry point to the Cocaine Cloud.
The Service
provides an ability to work with Cocaine services in a thread-safe manner with
automatic name resolution and reconnection before the next request after any unexpected
I/O error.
Internally it has an asynchronous state machine, which runs in an event loop associated with the handle given at construction time.
Most time you find out that it's more practical to use convenient service wrappers, like
Locator
, Unicorn
etc.
Methods
impl Service
[src]
impl Service
pub fn new<N>(name: N, handle: &Handle) -> Self where
N: Into<Cow<'static, str>>,
[src]
pub fn new<N>(name: N, handle: &Handle) -> Self where
N: Into<Cow<'static, str>>,
Constructs a new Service
with a given name.
This will not perform a connection attempt until required - both name resolution and
connection will be performed on demand, but you can still call connect
method
to perform connection attempt.
For more fine-grained service configuration use ServiceBuilder
instead.
Examples
use cocaine::{Core, Service}; let core = Core::new().unwrap(); let locator = Service::new("locator", &core.handle()); let name = "app".to_string(); let service = Service::new(name, &core.handle()); assert_eq!("app", service.name()); assert_eq!("locator", locator.name());
pub fn name(&self) -> &str
[src]
pub fn name(&self) -> &str
Returns service name.
pub fn connect(
&self
) -> impl Future<Item = (), Error = Error>
[src]
pub fn connect(
&self
) -> impl Future<Item = (), Error = Error>
Connects to the service, performing name resolution and TCP connection establishing.
Does nothing, if a service is already connected to some backend.
Usually a service connects automatically on demand, however it may be useful to optimize away a connection delay by doing pre-connection using this method.
pub fn methods(&self) -> Option<HashMap<u64, EventGraph>>
[src]
pub fn methods(&self) -> Option<HashMap<u64, EventGraph>>
Returns methods map if available.
The return value can be None
if either the service is not connected or the Resolve
has
provided incomplete information.
Note that this method aren't meant to be used to check whether the service is connected,
because it can return valid methods map, while still connecting to real endpoint. To check
the connection status use peer_addr
method instead.
pub fn disconnect(&self)
[src]
pub fn disconnect(&self)
Disconnects from a remote service without discarding pending requests.
pub fn peer_addr(&self) -> Result<SocketAddr, Error>
[src]
pub fn peer_addr(&self) -> Result<SocketAddr, Error>
Returns the socket address of the remote peer of this TCP connection.
Returns an I/O error with ErrorKind::NotConnected
if this Service
is not currently
connected.
pub fn local_addr(&self) -> Result<SocketAddr, Error>
[src]
pub fn local_addr(&self) -> Result<SocketAddr, Error>
Returns the socket address of the local half of this TCP connection.
Returns an I/O error with ErrorKind::NotConnected
if this Service
is not currently
connected.
pub fn call<D>(
&self,
request: Request,
dispatch: D
) -> impl Future<Item = Sender, Error = Error> where
D: Dispatch + 'static,
[src]
pub fn call<D>(
&self,
request: Request,
dispatch: D
) -> impl Future<Item = Sender, Error = Error> where
D: Dispatch + 'static,
Performs an RPC with a specified type and arguments.
The result type is a future of Sender
, because service requires TCP connection
established before the request can be processed.
Warning
Calling a mute event using this method essentially leads to memory leak during this
object's entire lifetime, since the specified Dispatch
will be captured.
For mute RPC use call_mute
instead.
pub fn call_mute(
&self,
request: Request
) -> impl Future<Item = Sender, Error = Error>
[src]
pub fn call_mute(
&self,
request: Request
) -> impl Future<Item = Sender, Error = Error>
Performs a mute RPC with a specified type and arguments.
Mute calls have no responses, that's why this method does not require a dispatch.
Warning
Calling a service event, that actually does respond, leads to silent dropping all received response chunks.
Trait Implementations
impl Clone for Service
[src]
impl Clone for Service
fn clone(&self) -> Service
[src]
fn clone(&self) -> Service
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 Service
[src]
impl Debug for Service