Trait tor_persist::state_dir::InstancePurgeHandler

source ·
pub trait InstancePurgeHandler {
    // Required methods
    fn kind(&self) -> &'static str;
    fn name_filter(&mut self, identity: &SlugRef) -> Result<Liveness>;
    fn age_filter(
        &mut self,
        identity: &SlugRef,
        age: Duration
    ) -> Result<Liveness>;
    fn dispose(
        &mut self,
        info: &InstancePurgeInfo<'_>,
        handle: InstanceStateHandle
    ) -> Result<()>;
}
Available on crate feature state-dir only.
Expand description

For a facility to be expired using purge_instances (caller-provided impl)

A filter which decides which instances to delete, and deletes them if appropriate.

See purge_instances for full documentation.

Required Methods§

source

fn kind(&self) -> &'static str

What kind to iterate over

source

fn name_filter(&mut self, identity: &SlugRef) -> Result<Liveness>

Can we tell by its name that this instance is still live ?

source

fn age_filter(&mut self, identity: &SlugRef, age: Duration) -> Result<Liveness>

Can we tell by recent modification that this instance is still live ?

Many implementations won’t need to use the identity parameter.

§Concurrency

The age passed to this callback might sometimes not be the most recent modification time of the instance. But. before calling dispose, purge_instances will call this function at least once with a fully up-to-date modification time.

source

fn dispose( &mut self, info: &InstancePurgeInfo<'_>, handle: InstanceStateHandle ) -> Result<()>

Decide whether to keep this instance

When it has made its decision, dispose should either call delete, or simply drop handle.

Called only after name_filter and age_filter both returned Liveness::PossiblyUnused.

info includes the instance name and other useful information such as the last modification time.

Note that although the existence of handle implies there can be no other InstanceStateHandles for this instance, the last modification time of this instance has not been updated, as it would be by acquire_instance.

Implementors§