Skip to main content

ConnectionPool

Struct ConnectionPool 

Source
pub struct ConnectionPool<S> { /* private fields */ }
Expand description

Connection pool

ConnectionPool holds reusable connections. A reusable connection is released to this pool to be picked up by another user/request.

Implementations§

Source§

impl<S> ConnectionPool<S>

Source

pub fn new(size: usize) -> Self

Create a new ConnectionPool with a global size limit.

When a connection is released to this pool and total occupancy is at or above size, the least recently used connection is dropped.

Source

pub fn pop_closed(&self, meta: &ConnectionMeta)

Source

pub fn get(&self, key: &u64) -> Option<S>

Get a connection from this pool under the same group key

Source

pub fn put( &self, meta: &ConnectionMeta, connection: S, ) -> (Arc<Notify>, Receiver<bool>)

Release a connection to this pool for reuse

Source

pub async fn idle_poll<Stream>( &self, connection: OwnedMutexGuard<Stream>, meta: &ConnectionMeta, timeout: Option<Duration>, notify_evicted: Arc<Notify>, watch_use: Receiver<bool>, ) -> bool
where Stream: AsyncRead + Unpin + Send,

Actively monitor the health of a connection that is already released to this pool

When the connection breaks, or the optional timeout is reached this function will remove it from the pool and drop the connection.

If the connection is reused via Self::get() or being evicted, this function will just exit.

Returns true if the connection was evicted from the pool, and false otherwise.

Source

pub async fn idle_timeout( &self, meta: &ConnectionMeta, timeout: Option<Duration>, notify_evicted: Arc<Notify>, notify_closed: Receiver<bool>, watch_use: Receiver<bool>, ) -> bool

Passively wait to close the connection after the timeout

If this connection is not being picked up or evicted before the timeout is reach, this function will remove it from the pool and close the connection.

Returns true if the connection was evicted from the pool, and false otherwise.

Auto Trait Implementations§

§

impl<S> !Freeze for ConnectionPool<S>

§

impl<S> !RefUnwindSafe for ConnectionPool<S>

§

impl<S> !UnwindSafe for ConnectionPool<S>

§

impl<S> Send for ConnectionPool<S>
where DashMap<u64, Arc<PoolNode<PoolConnection<S>>>>: Send,

§

impl<S> Sync for ConnectionPool<S>
where DashMap<u64, Arc<PoolNode<PoolConnection<S>>>>: Sync,

§

impl<S> Unpin for ConnectionPool<S>
where DashMap<u64, Arc<PoolNode<PoolConnection<S>>>>: Unpin,

§

impl<S> UnsafeUnpin for ConnectionPool<S>
where DashMap<u64, Arc<PoolNode<PoolConnection<S>>>>: UnsafeUnpin,

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, 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.