PeanutButter
Loading...
Searching...
No Matches
PeanutButter.Utils.Pool< T > Class Template Reference

Provides a generic pooling mechanism using the Disposable pattern. More...

Inheritance diagram for PeanutButter.Utils.Pool< T >:
PeanutButter.Utils.IPool< T > PeanutButter.SimpleHTTPServer.HttpServerFactory PeanutButter.TempElasticsearch.TempElasticsearchFactory PeanutButter.TempRedis.TempRedisFactory

Public Member Functions

 Pool (Func< T > factory)
 Creates the pool with a factory for the items.
 Pool (Func< T > factory, int maxItems)
 Creates the pool with a factory for the items.
 Pool (Func< T > factory, Action< T > onRelease)
 Creates the pool with the provided factory and an action to run on releasing the item.
 Pool (Func< T > factory, Action< T > onRelease, int maxItems)
 Creates the pool with the provided factory and an action to run on releasing the item.
 Pool (Func< IPool< T >, T > factory)
 Creates the pool with a factory for the items.
 Pool (Func< IPool< T >, T > factory, int maxItems)
 Creates the pool with a factory for the items.
 Pool (Func< IPool< T >, T > factory, Action< T > onRelease)
 Creates the pool with the provided factory and an action to run on releasing the item.
 Pool (Func< IPool< T >, T > factory, Action< T > onRelease, int maxItems)
 Creates the pool with the provided factory and an action to run on releasing the item.
IPoolItem< T > Take ()
 Attempt to take an item from the pool. If possible and required, an item will be created for you. If the pool is full and no item can be made available, this will a pool item with a null instance.
Returns

IPoolItem< T > Take (int maxWaitMilliseconds)
 Attempt to take an item from the pool, with a max wait in ms when the pool is already full and you need to wait on something else to release an instance. If no instance can be found in time, then this will return a PoolItem with a default instance.
Parameters
maxWaitMilliseconds
Returns

IPoolItem< T > Borrow ()
 Attempt to take an item from the pool. If possible and required, an item will be created for you. If the pool is full and no item can be made available, this will a pool item with a null instance.
void Warmup ()
 Causes an initial temporary elasticsearch instance to be started, and gates the next request for an instance.
IPoolItem< T > Borrow (int maxWaitMilliseconds)
 Attempt to take an item from the pool, with a max wait in ms when the pool is already full and you need to wait on something else to release an instance. If no instance can be found in time, then this will return a PoolItem with a default instance.
void Forget (IPoolItem< T > item)
 Forget the item from the pool.
Parameters
item

void Dispose ()
 Disposes of this pool and all items in the pool.

Properties

int MaxItems [get]
 The maximum number of items to hold in the pool.
int Count [get]
 How many items are currently in the pool.
bool WarmupStarted [get]
 Set when warmup starts.
bool WarmedUp [get, set]
 Set when warmup completes.

Detailed Description

Provides a generic pooling mechanism using the Disposable pattern.

Template Parameters
T

Member Function Documentation

◆ Borrow() [1/2]

IPoolItem< T > PeanutButter.Utils.Pool< T >.Borrow ( )

Attempt to take an item from the pool. If possible and required, an item will be created for you. If the pool is full and no item can be made available, this will a pool item with a null instance.

Returns

Implements PeanutButter.Utils.IPool< T >.

◆ Borrow() [2/2]

IPoolItem< T > PeanutButter.Utils.Pool< T >.Borrow ( int maxWaitMilliseconds)

Attempt to take an item from the pool, with a max wait in ms when the pool is already full and you need to wait on something else to release an instance. If no instance can be found in time, then this will return a PoolItem with a default instance.

Parameters
maxWaitMilliseconds
Returns

Implements PeanutButter.Utils.IPool< T >.

◆ Dispose()

void PeanutButter.Utils.Pool< T >.Dispose ( )

Disposes of this pool and all items in the pool.

Implements PeanutButter.Utils.IPool< T >.

◆ Forget()

void PeanutButter.Utils.Pool< T >.Forget ( IPoolItem< T > item)

Forget the item from the pool.

Parameters
item

Implements PeanutButter.Utils.IPool< T >.

◆ Pool() [1/8]

PeanutButter.Utils.Pool< T >.Pool ( Func< IPool< T >, T > factory)

Creates the pool with a factory for the items.

Parameters
factory
Exceptions
NotImplementedException

◆ Pool() [2/8]

PeanutButter.Utils.Pool< T >.Pool ( Func< IPool< T >, T > factory,
Action< T > onRelease )

Creates the pool with the provided factory and an action to run on releasing the item.

Parameters
factory
onRelease

◆ Pool() [3/8]

PeanutButter.Utils.Pool< T >.Pool ( Func< IPool< T >, T > factory,
Action< T > onRelease,
int maxItems )

Creates the pool with the provided factory and an action to run on releasing the item.

Parameters
factory
maxItems
onRelease

◆ Pool() [4/8]

PeanutButter.Utils.Pool< T >.Pool ( Func< IPool< T >, T > factory,
int maxItems )

Creates the pool with a factory for the items.

Parameters
factory
maxItems
Exceptions
NotImplementedException

◆ Pool() [5/8]

PeanutButter.Utils.Pool< T >.Pool ( Func< T > factory)

Creates the pool with a factory for the items.

Parameters
factory
Exceptions
NotImplementedException

◆ Pool() [6/8]

PeanutButter.Utils.Pool< T >.Pool ( Func< T > factory,
Action< T > onRelease )

Creates the pool with the provided factory and an action to run on releasing the item.

Parameters
factory
onRelease

◆ Pool() [7/8]

PeanutButter.Utils.Pool< T >.Pool ( Func< T > factory,
Action< T > onRelease,
int maxItems )

Creates the pool with the provided factory and an action to run on releasing the item.

Parameters
factory
maxItems
onRelease

◆ Pool() [8/8]

PeanutButter.Utils.Pool< T >.Pool ( Func< T > factory,
int maxItems )

Creates the pool with a factory for the items.

Parameters
factory
maxItems
Exceptions
NotImplementedException

◆ Take() [1/2]

IPoolItem< T > PeanutButter.Utils.Pool< T >.Take ( )

Attempt to take an item from the pool. If possible and required, an item will be created for you. If the pool is full and no item can be made available, this will a pool item with a null instance.

Returns

Implements PeanutButter.Utils.IPool< T >.

◆ Take() [2/2]

IPoolItem< T > PeanutButter.Utils.Pool< T >.Take ( int maxWaitMilliseconds)

Attempt to take an item from the pool, with a max wait in ms when the pool is already full and you need to wait on something else to release an instance. If no instance can be found in time, then this will return a PoolItem with a default instance.

Parameters
maxWaitMilliseconds
Returns

Implements PeanutButter.Utils.IPool< T >.

◆ Warmup()

void PeanutButter.Utils.Pool< T >.Warmup ( )

Causes an initial temporary elasticsearch instance to be started, and gates the next request for an instance.

Implements PeanutButter.Utils.IPool< T >.

Property Documentation

◆ Count

int PeanutButter.Utils.Pool< T >.Count
get

How many items are currently in the pool.

Implements PeanutButter.Utils.IPool< T >.

◆ MaxItems

int PeanutButter.Utils.Pool< T >.MaxItems
get

The maximum number of items to hold in the pool.

Implements PeanutButter.Utils.IPool< T >.

◆ WarmedUp

bool PeanutButter.Utils.Pool< T >.WarmedUp
getset

Set when warmup completes.

  • mostly for external observation

◆ WarmupStarted

bool PeanutButter.Utils.Pool< T >.WarmupStarted
get

Set when warmup starts.

  • more of an internal flag, but may be interesting to observe

The documentation for this class was generated from the following file:
  • source/Utils/PeanutButter.Utils/Pool.cs