Skip to main content

DownloadEngine

Struct DownloadEngine 

Source
pub struct DownloadEngine { /* private fields */ }

Implementations§

Source§

impl DownloadEngine

Source

pub fn new(tick_interval_ms: u64) -> Self

Source

pub fn with_retry_policy(tick_interval_ms: u64, policy: RetryPolicy) -> Self

Source

pub fn set_global_rate_limiter(&mut self, config: RateLimiterConfig)

Source

pub fn global_rate_limiter(&self) -> Option<&RateLimiter>

Source

pub fn take_global_rate_limiter(&mut self) -> Option<RateLimiter>

Source

pub fn spawn_progress_aggregator( group: Arc<RwLock<RequestGroup>>, receiver: UnboundedReceiver<ProgressUpdate>, ) -> JoinHandle<()>

Spawn a progress aggregator task that receives ProgressUpdates from download commands and applies them to the shared RequestGroup.

This eliminates per-chunk write-lock contention on the download hot path: each DownloadCommand performs a cheap lock-free mpsc::UnboundedSender::send and this single aggregator task is the only writer of the progress fields.

The aggregator deduplicates consecutive updates with identical completed_bytes values and only refreshes the speed fields when the sender provides a non-zero download_speed sample (0 means “no fresh sample this tick”).

The task exits cleanly when all senders are dropped (the receiver returns None).

This is intentionally an associated function (not &self): it is called automatically by DownloadCommand::spawn_progress_aggregator during execute(), since every DownloadCommand now auto-creates a progress channel in its constructor. External callers rarely need to invoke this directly.

Source

pub fn set_save_session( &mut self, path: PathBuf, interval: Option<Duration>, man: Arc<RwLock<RequestGroupMan>>, )

Source

pub fn mark_session_dirty(&self)

Source

pub fn save_session_path(&self) -> Option<&PathBuf>

Source

pub fn add_command(&self, command: Box<dyn Command>) -> Result<()>

Source

pub fn retry_stats(&self) -> &RetryStats

Source

pub fn retry_policy(&self) -> &RetryPolicy

Source

pub fn ftp_pool(&self) -> &Arc<FtpConnectionPool>

Get a reference to the FTP connection pool for dependency injection.

Source

pub fn dns_cache(&self) -> &Arc<Mutex<DnsCache>>

Get a reference to the DNS cache for dependency injection.

Source

pub fn set_keep_alive(&mut self, v: bool)

Enable/disable keep-alive mode. When true, the engine stays alive even with no pending/running commands (used for RPC listen mode). The loop only exits on shutdown signal.

Source

pub fn command_sender(&self) -> UnboundedSender<Box<dyn Command>>

Clone the command sender so external callers (e.g., RPC) can submit download commands to the engine loop.

Source

pub fn take_shutdown_sender(&mut self) -> Option<Sender<()>>

Take the shutdown sender so an external task (e.g., Ctrl+C handler) can signal the engine to stop. Must be called before run().

Source

pub async fn run(self) -> Result<()>

Source

pub async fn shutdown_engine(&mut self) -> Result<()>

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more