pub struct BackendHandle {
pub service_name: String,
pub service_version: String,
pub daemon_process: DaemonProcess,
/* private fields */
}Expand description
A verified handle to a running backend daemon.
The handle carries the daemon identity needed to defend against stale manifests and PID recycling before consumers connect to the IPC endpoint.
A handle is created only through one of the probe* constructors. The
constructor performs all identity checks first; successful callers may then
use Self::is_alive for a cheap liveness check or Self::connect to
open a fresh local-socket connection.
Fields§
§service_name: StringLogical service name from the manifest or direct probe caller.
service_version: StringService version from the manifest or direct probe caller.
daemon_process: DaemonProcessVerified daemon process identity.
Implementations§
Source§impl BackendHandle
impl BackendHandle
Sourcepub fn probe(endpoint: &Endpoint, expected: &DaemonProcess) -> Option<Self>
pub fn probe(endpoint: &Endpoint, expected: &DaemonProcess) -> Option<Self>
Connect to an existing backend by endpoint and verify process identity.
This probe verifies the endpoint identity tuple, requires the endpoint
to answer the nonce-based IPC identity probe, then verifies current boot
ID, process liveness, executable path, and executable SHA-256. It
returns None for stale manifests, dead PIDs, mismatched daemon
binaries, or endpoints that do not answer as the expected backend.
Use this when the caller already has service metadata elsewhere and only needs to know whether the daemon identity is still valid.
BLOCKING. Performs synchronous IPC up to
probe::DEFAULT_ENDPOINT_PROBE_TIMEOUT
(500 ms). From a tokio task, call from spawn_blocking or
switch to [Self::probe_async] (requires the client-async
feature).
use running_process::broker::backend_handle::{BackendHandle, DaemonProcess};
use running_process::broker::protocol::Endpoint;
if let Some(handle) = BackendHandle::probe(&endpoint, &expected) {
assert!(handle.is_alive());
}Sourcepub fn probe_with_service(
service_name: impl Into<String>,
service_version: impl Into<String>,
endpoint: &Endpoint,
expected: &DaemonProcess,
) -> Result<Self>
pub fn probe_with_service( service_name: impl Into<String>, service_version: impl Into<String>, endpoint: &Endpoint, expected: &DaemonProcess, ) -> Result<Self>
Probe an existing backend and attach service metadata to the handle.
This is the preferred constructor for direct-daemon consumers because it preserves the logical service tuple alongside the verified process identity.
BLOCKING. Performs synchronous IPC up to
probe::DEFAULT_ENDPOINT_PROBE_TIMEOUT
(500 ms). From a tokio task, call from spawn_blocking or use
[Self::probe_with_service_async] (requires the
client-async feature) instead — calling this directly from
an async context will block the runtime worker thread.
use running_process::broker::backend_handle::{BackendHandle, DaemonProcess};
use running_process::broker::protocol::Endpoint;
BackendHandle::probe_with_service("zccache", "0.8.0", &endpoint, &expected)Sourcepub fn probe_manifest(manifest: &CacheManifest) -> Option<Self>
pub fn probe_manifest(manifest: &CacheManifest) -> Option<Self>
Probe the current_daemon recorded in a cache manifest.
Returns None when the manifest has no daemon entry or when the daemon
entry no longer matches a live process on the current boot.
use running_process::broker::backend_handle::BackendHandle;
use running_process::broker::protocol::CacheManifest;
match BackendHandle::probe_manifest(manifest) {
Some(handle) if handle.is_alive() => {
// Reuse the verified backend.
}
_ => {
// Spawn or discover a replacement backend.
}
}Sourcepub fn try_from_manifest(manifest: &CacheManifest) -> Result<Option<Self>>
pub fn try_from_manifest(manifest: &CacheManifest) -> Result<Option<Self>>
Fallible variant of Self::probe_manifest that preserves parse errors.
Use this in maintenance tools and diagnostics where malformed manifest identities should be reported separately from a normal cache miss.
Sourcepub fn is_alive(&self) -> bool
pub fn is_alive(&self) -> bool
Check liveness without opening a new IPC connection.
On platforms with an owned process-handle primitive, this checks the handle captured during probing. Otherwise it falls back to opening the process ID again.
Sourcepub async fn connect(&self) -> Result<Connection>
pub async fn connect(&self) -> Result<Connection>
Open a fresh IPC connection to this backend.
The process identity is verified when the handle is created. Callers that
cache handles for a long time should call Self::is_alive or reprobe
from the latest manifest before opening a connection.
use running_process::broker::backend_handle::BackendHandle;
async fn connect_to_verified_backend(
handle: &BackendHandle,
) -> running_process::broker::backend_handle::Result<()> {
let connection = handle.connect().await?;
let _stream = connection.into_inner();
Ok(())
}Sourcepub async fn shutdown(self, timeout: Duration) -> Result<()>
pub async fn shutdown(self, timeout: Duration) -> Result<()>
Send a graceful shutdown signal and wait until the process exits.
On Windows this foundation returns GracefulTerminateUnsupported until
the broker shutdown request protocol lands.
Dropping the handle without calling this method leaves the backend running.
Sourcepub fn force_kill(self) -> Result<()>
pub fn force_kill(self) -> Result<()>
Force-kill the daemon process.
This is the last-resort teardown path for a daemon that ignored graceful shutdown or whose IPC protocol is unavailable.
Auto Trait Implementations§
impl Freeze for BackendHandle
impl RefUnwindSafe for BackendHandle
impl Send for BackendHandle
impl Sync for BackendHandle
impl Unpin for BackendHandle
impl UnsafeUnpin for BackendHandle
impl UnwindSafe for BackendHandle
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more