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]
fn new<N>(name: N, handle: &Handle) -> Self where
N: Into<Cow<'static, str>>,
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.
fn name(&self) -> &str
Returns service name.
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.
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.
fn disconnect(&self)
Disconnects from a remote service without discarding pending requests.
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.
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.
fn call<T, D>(
&self,
ty: u64,
args: &T,
headers: Vec<RawHeader>,
dispatch: D
) -> impl Future<Item = Sender, Error = Error> where
T: Serialize,
D: Dispatch + 'static,
&self,
ty: u64,
args: &T,
headers: Vec<RawHeader>,
dispatch: D
) -> impl Future<Item = Sender, Error = Error> where
T: Serialize,
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.
fn call_mute<T>(
&self,
ty: u64,
args: &T
) -> impl Future<Item = Sender, Error = Error> where
T: Serialize,
&self,
ty: u64,
args: &T
) -> impl Future<Item = Sender, Error = Error> where
T: Serialize,
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]
fn clone(&self) -> Service
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more