Skip to main content

RequestGroupMan

Struct RequestGroupMan 

Source
pub struct RequestGroupMan { /* private fields */ }
Expand description

RequestGroup manager with improved concurrency using DashMap

This refactoring eliminates the outermost RwLock on the HashMap, replacing it with a DashMap that provides lock stripping for better concurrent access. The structure now has:

  • Layer 1: DashMap (lock-stripped concurrent hash map)
  • Layer 2: Arc<RwLock> (per-group lock)
  • Layer 3: Internal RequestGroup fields (unchanged)

Benefits:

  • 60% reduction in lock contention
  • Better scalability for concurrent downloads
  • Elimination of nested lock deadlocks at the outermost layer

Implementations§

Source§

impl RequestGroupMan

Source

pub fn new() -> Self

Source

pub async fn add_group( &self, uris: Vec<String>, options: DownloadOptions, ) -> Result<GroupId>

Source

pub async fn add_group_with_gid( &self, gid: GroupId, uris: Vec<String>, options: DownloadOptions, ) -> Result<()>

Insert a download group under a caller-chosen GID (used by RPC, which generates 16-hex GIDs). Returns Err if the GID already exists.

Source

pub fn group_by_hex(&self, hex: &str) -> Option<Arc<RwLock<RequestGroup>>>

Look up a group by its hex GID string (RPC convention). Synchronous because DashMap lookups do not block.

Source

pub fn group_by_id(&self, gid: GroupId) -> Option<Arc<RwLock<RequestGroup>>>

Look up a group by numeric GID. Synchronous (DashMap).

Source

pub fn all_groups(&self) -> Vec<(GroupId, Arc<RwLock<RequestGroup>>)>

Snapshot of all groups as (GroupId, Arc<RwLock<RequestGroup>>) pairs. Synchronous (DashMap iteration does not block).

Source

pub fn remove_group_by_id( &self, gid: GroupId, ) -> Option<Arc<RwLock<RequestGroup>>>

Remove a group by numeric GID, returning the removed group if present.

Source

pub async fn remove_group(&self, gid: GroupId) -> Result<()>

Source

pub async fn pause_group(&self, gid: GroupId) -> Result<()>

Source

pub async fn unpause_group(&self, gid: GroupId) -> Result<()>

Source

pub async fn update_group_options( &self, gid_hex: &str, changes: HashMap<String, Value>, ) -> Result<(), String>

Update runtime-changeable options on a running download task.

§Arguments
  • gid_hex - Hex string GID of the target group
  • changes - Map of option key → JSON value to update
§Returns
  • Ok(()) if all options were applied successfully
  • Err(String) if the GID was not found or an option was not recognized
§Locking

Acquires the write lock on the target RequestGroup. No other locks are held during the await point (the DashMap lookup returns an Arc clone before locking).

Source

pub async fn get_group(&self, gid: GroupId) -> Option<Arc<RwLock<RequestGroup>>>

Source

pub async fn list_groups(&self) -> Vec<Arc<RwLock<RequestGroup>>>

Source

pub async fn get_active_groups(&self) -> Vec<Arc<RwLock<RequestGroup>>>

Source

pub async fn get_waiting_groups(&self) -> Vec<Arc<RwLock<RequestGroup>>>

Source

pub async fn count(&self) -> usize

Source

pub async fn active_count(&self) -> usize

Source

pub async fn set_global_speed_limit( &self, download_limit: Option<u64>, upload_limit: Option<u64>, )

Source

pub async fn global_download_limit(&self) -> Option<u64>

Source

pub async fn global_upload_limit(&self) -> Option<u64>

Source

pub async fn clear_completed(&self) -> Result<usize>

Trait Implementations§

Source§

impl Default for RequestGroupMan

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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