CustomObjectPool<TItem>

Overview

This class expands the BaseObjectPool by defining several new constructors and implementing the OnCreateInstance method, which is used to create instances of pooled objects. Note that the behavior of this class can be easily changed during program execution, because the delegate used to create new instances of pooled objects can be changed during runtime (see the definition of the property CreateInstance for details).

Location

 

constructor  protected    (declared in BaseObjectPool<TItem>)

Creates a new instance of the BaseObjectPool class.

The created pool will have the size -1 (i.e. infinite).

Cannot be called directly.

 

constructor

 

CustomObjectPool<TItem>()

 

Sub New()

constructor (PoolBehavior, Int32, Int32)  protected    (declared in BaseObjectPool<TItem>)

 

constructor(behavior: PoolBehavior; maxSize: Int32; timeout: Int32)

 

CustomObjectPool<TItem>(PoolBehavior behavior, Int32 maxSize, Int32 timeout)

 

Sub New(behavior As PoolBehavior, maxSize As Int32, timeout As Int32)

Parameters:

  • behavior:
  • maxSize:
  • timeout:

 

constructor(createInstanceDelegate: CreateInstanceDelegate<TItem>)

 

CustomObjectPool<TItem>(CreateInstanceDelegate<TItem> createInstanceDelegate)

 

Sub New(createInstanceDelegate As CreateInstanceDelegate<TItem>)

Parameters:

  • createInstanceDelegate:

 

constructor(createInstanceDelegate: CreateInstanceDelegate<TItem>; behavior: PoolBehavior; initialSize: Int32)

 

CustomObjectPool<TItem>(CreateInstanceDelegate<TItem> createInstanceDelegate, PoolBehavior behavior, Int32 initialSize)

 

Sub New(createInstanceDelegate As CreateInstanceDelegate<TItem>, behavior As PoolBehavior, initialSize As Int32)

Parameters:

  • createInstanceDelegate:
  • behavior:
  • initialSize:

constructor (CreateInstanceDelegate<TItem>, PoolBehavior, Int32, Int32, Int32)

 

constructor(createInstanceDelegate: CreateInstanceDelegate<TItem>; behavior: PoolBehavior; initialSize: Int32; maxSize: Int32; timeout: Int32)

 

CustomObjectPool<TItem>(CreateInstanceDelegate<TItem> createInstanceDelegate, PoolBehavior behavior, Int32 initialSize, Int32 maxSize, Int32 timeout)

 

Sub New(createInstanceDelegate As CreateInstanceDelegate<TItem>, behavior As PoolBehavior, initialSize As Int32, maxSize As Int32, timeout As Int32)

Parameters:

  • createInstanceDelegate:
  • behavior:
  • initialSize:
  • maxSize:
  • timeout:

 

constructor(createInstanceDelegate: CreateInstanceDelegate<TItem>; disposeInstanceDelegate: DisposeInstanceDelegate<TItem>)

 

CustomObjectPool<TItem>(CreateInstanceDelegate<TItem> createInstanceDelegate, DisposeInstanceDelegate<TItem> disposeInstanceDelegate)

 

Sub New(createInstanceDelegate As CreateInstanceDelegate<TItem>, disposeInstanceDelegate As DisposeInstanceDelegate<TItem>)

Parameters:

  • createInstanceDelegate:
  • disposeInstanceDelegate:

 

constructor(createInstanceDelegate: CreateInstanceDelegate<TItem>; disposeInstanceDelegate: DisposeInstanceDelegate<TItem>; behavior: PoolBehavior; initialSize: Int32)

 

CustomObjectPool<TItem>(CreateInstanceDelegate<TItem> createInstanceDelegate, DisposeInstanceDelegate<TItem> disposeInstanceDelegate, PoolBehavior behavior, Int32 initialSize)

 

Sub New(createInstanceDelegate As CreateInstanceDelegate<TItem>, disposeInstanceDelegate As DisposeInstanceDelegate<TItem>, behavior As PoolBehavior, initialSize As Int32)

Parameters:

  • createInstanceDelegate:
  • disposeInstanceDelegate:
  • behavior:
  • initialSize:

 

constructor(createInstanceDelegate: CreateInstanceDelegate<TItem>; disposeInstanceDelegate: DisposeInstanceDelegate<TItem>; behavior: PoolBehavior; initialSize: Int32; maxSize: Int32; timeout: Int32)

 

CustomObjectPool<TItem>(CreateInstanceDelegate<TItem> createInstanceDelegate, DisposeInstanceDelegate<TItem> disposeInstanceDelegate, PoolBehavior behavior, Int32 initialSize, Int32 maxSize, Int32 timeout)

 

Sub New(createInstanceDelegate As CreateInstanceDelegate<TItem>, disposeInstanceDelegate As DisposeInstanceDelegate<TItem>, behavior As PoolBehavior, initialSize As Int32, maxSize As Int32, timeout As Int32)

Parameters:

  • createInstanceDelegate:
  • disposeInstanceDelegate:
  • behavior:
  • initialSize:
  • maxSize:
  • timeout:

AcquiredInstancesCount    (declared in BaseObjectPool<TItem>)

Gets the count of the currently acquired object pool elements.

 

property AcquiredInstancesCount: Int32 read;

 

Int32 AcquiredInstancesCount { get; }

 

ReadOnly Property AcquiredInstancesCount() As Int32

AcquireInstance    (declared in BaseObjectPool<TItem>)

Acquires an item from the pool.

If there are non-acquired pool items or pool has an infinite size, the pool item is acquired and returned to the caller. Otherwise, the Behavior property specifies the result of the method call:

  • PoolBehavior.Wait - wait until any pool item becomes available.
  • PoolBehavior.IgnoreAndReturn - wait for no more than WaitTimeOut milliseconds for any pool items. If there still are no pool items available after timeout, null will be returned.
  • PoolBehavior.Raise - wait for no more than WaitTimeOut milliseconds for any pool items. If there still are no pool items available after timeout, an NoFreeObjectsInPoolException is raised.

 

method AcquireInstance: TItem

 

TItem AcquireInstance()

 

Function AcquireInstance() As TItem

Behavior    (declared in BaseObjectPool<TItem>)

Specifies the behavior of the object pool when an item is requested but the pool is empty (i.e. all available elements are acquired).

See the description of the AcquireInstance method for more details about possible Behavior settings.

 

property Behavior: PoolBehavior read write;

 

PoolBehavior Behavior { get; set; }

 

Property Behavior() As PoolBehavior

Clear    (declared in BaseObjectPool<TItem>)

Clears all items from the pool.

 

method Clear

 

void Clear()

 

Sub Clear()

CreateInstance

 

property CreateInstance: CreateInstanceDelegate<TItem> read write;

 

CreateInstanceDelegate<TItem> CreateInstance { get; set; }

 

Property CreateInstance() As CreateInstanceDelegate<TItem>

Current    (declared in BaseObjectPool<TItem>)

Gets the current element in the collection.

This property is a part of the IEnumerator interface implementation.

 

property Current: Object read;

 

Object Current { get; }

 

ReadOnly Property Current() As Object

Dispose    (declared in BaseObjectPool<TItem>)

Releases all pool resources.

The FinalizePool method can be overridden in case some specific cleanup actions are needed.

 

method Dispose

 

void Dispose()

 

Sub Dispose()

DisposeInstance

 

property DisposeInstance: DisposeInstanceDelegate<TItem> read write;

 

DisposeInstanceDelegate<TItem> DisposeInstance { get; set; }

 

Property DisposeInstance() As DisposeInstanceDelegate<TItem>

DropInstance    (declared in BaseObjectPool<TItem>)

Removes the anItem object from the pool.

 

method DropInstance(item: TItem)

 

void DropInstance(TItem item)

 

Sub DropInstance(item As TItem)

Parameters:

  • item:

ExposeNonAcquiredInstances    (declared in BaseObjectPool<TItem>)

Exposes all non-acquired pool objects using the specified aDelegate.

 

method ExposeNonAcquiredInstances(action: ExposeNonAcquiredInstancesDelegate<TItem>)

 

void ExposeNonAcquiredInstances(ExposeNonAcquiredInstancesDelegate<TItem> action)

 

Sub ExposeNonAcquiredInstances(action As ExposeNonAcquiredInstancesDelegate<TItem>)

Parameters:

  • action:

FinalizePool  protected    (declared in BaseObjectPool<TItem>)

Finalizes the object pool.

This method's implementation is empty in the BaseObjectPool class but can be overriden in derived classes in case some specific cleanup actions are needed.

 

method FinalizePool

 

void FinalizePool()

 

Sub FinalizePool()

GetEnumerator    (declared in BaseObjectPool<TItem>)

Returns an enumerator that iterates through a collection of non-acquired pool objects.

This method is part of the IEnumerable interface implementation.

 

method GetEnumerator: IEnumerator

 

IEnumerator GetEnumerator()

 

Function GetEnumerator() As IEnumerator

Instances  protected    (declared in BaseObjectPool<TItem>)

Gets all pooled instances as a linked list.

This property can be used in the BaseObjectPool descendants to fine-tune pooled instances etc.

 

property Instances: LinkedList<TItem> read;

 

LinkedList<TItem> Instances { get; }

 

ReadOnly Property Instances() As LinkedList<TItem>

MaxPoolSize    (declared in BaseObjectPool<TItem>)

Gets the maximum number of items that can be contained in the pool.

-1 means the pool is of unlimited size.

It is not possible to set this property to a positive value less than the AcquiredInstancesCount, doing so will raise an exception. At the same time, it is always possible to set value of this property to -1.

 

property MaxPoolSize: Int32 read write;

 

Int32 MaxPoolSize { get; set; }

 

Property MaxPoolSize() As Int32

MoveNext    (declared in BaseObjectPool<TItem>)

Advances the enumerator to the next element of the collection of non-acquired object pool items.

This property is part of the IEnumerator interface implementation.

 

method MoveNext: Boolean

 

Boolean MoveNext()

 

Function MoveNext() As Boolean

NonAcquiredInstancesCount    (declared in BaseObjectPool<TItem>)

Gets the number of pool items that were instantiated but are not currently acquired.

 

property NonAcquiredInstancesCount: Int32 read;

 

Int32 NonAcquiredInstancesCount { get; }

 

ReadOnly Property NonAcquiredInstancesCount() As Int32

OnCreateInstance  protected

This method fires a CreateInstance event to instantiate a new object pool item.

 

method OnCreateInstance: TItem

 

TItem OnCreateInstance()

 

Function OnCreateInstance() As TItem

OnDisposeInstance  protected

 

method OnDisposeInstance(instance: TItem)

 

void OnDisposeInstance(TItem instance)

 

Sub OnDisposeInstance(instance As TItem)

Parameters:

  • instance:

PoolSize    (declared in BaseObjectPool<TItem>)

Gets the current pool size. The value of this property equals the sum of the AcquiredInstancesCount and the NonAcquiredInstancesCount.

 

property PoolSize: Int32 read;

 

Int32 PoolSize { get; }

 

ReadOnly Property PoolSize() As Int32

ReleaseInstance    (declared in BaseObjectPool<TItem>)

Releases an acquired item back into the object pool.

 

method ReleaseInstance(item: TItem)

 

void ReleaseInstance(TItem item)

 

Sub ReleaseInstance(item As TItem)

Parameters:

  • item:

Reset    (declared in BaseObjectPool<TItem>)

Sets the enumerator to its initial position, which is before the first element in the collection of non-acquired object pool items.

This property is part of the IEnumerator interface implementation.

 

method Reset

 

void Reset()

 

Sub Reset()

Resize    (declared in BaseObjectPool<TItem>)

Instantiates the object pool items until there are at least aNewSize non-acquired items in the pool.

If the value of the second parameter is true, this method also sets the MaxPoolSize to aNewSize.

If the value of the second parameter is false and there are more pool items (both acquired and non-acquired) than aNewSize, an exception is raised.

 

method Resize(newSize: Int32; resetMaxPoolSize: Boolean): Int32

 

Int32 Resize(Int32 newSize, Boolean resetMaxPoolSize)

 

Function Resize(newSize As Int32, resetMaxPoolSize As Boolean) As Int32

Parameters:

  • newSize:
  • resetMaxPoolSize:

WaitTimeOut    (declared in BaseObjectPool<TItem>)

Gets or sets the timeout in milliseconds for acquiring new pool items. This is the time that the pool will wait to acquire a new instance before throwing a timeout exception when the Behavior is set to PoolBehavior.Wait.

If the value is -1, the pool will wait indefinitely.

 

property WaitTimeOut: Int32 read write;

 

Int32 WaitTimeOut { get; set; }

 

Property WaitTimeOut() As Int32

 

AcquiredInstancesCount    (declared in BaseObjectPool<TItem>)

Gets the count of the currently acquired object pool elements.

 

property AcquiredInstancesCount: Int32 read;

 

Int32 AcquiredInstancesCount { get; }

 

ReadOnly Property AcquiredInstancesCount() As Int32

Behavior    (declared in BaseObjectPool<TItem>)

Specifies the behavior of the object pool when an item is requested but the pool is empty (i.e. all available elements are acquired).

See the description of the AcquireInstance method for more details about possible Behavior settings.

 

property Behavior: PoolBehavior read write;

 

PoolBehavior Behavior { get; set; }

 

Property Behavior() As PoolBehavior

CreateInstance

 

property CreateInstance: CreateInstanceDelegate<TItem> read write;

 

CreateInstanceDelegate<TItem> CreateInstance { get; set; }

 

Property CreateInstance() As CreateInstanceDelegate<TItem>

Current    (declared in BaseObjectPool<TItem>)

Gets the current element in the collection.

This property is a part of the IEnumerator interface implementation.

 

property Current: Object read;

 

Object Current { get; }

 

ReadOnly Property Current() As Object

DisposeInstance

 

property DisposeInstance: DisposeInstanceDelegate<TItem> read write;

 

DisposeInstanceDelegate<TItem> DisposeInstance { get; set; }

 

Property DisposeInstance() As DisposeInstanceDelegate<TItem>

Instances  protected    (declared in BaseObjectPool<TItem>)

Gets all pooled instances as a linked list.

This property can be used in the BaseObjectPool descendants to fine-tune pooled instances etc.

 

property Instances: LinkedList<TItem> read;

 

LinkedList<TItem> Instances { get; }

 

ReadOnly Property Instances() As LinkedList<TItem>

MaxPoolSize    (declared in BaseObjectPool<TItem>)

Gets the maximum number of items that can be contained in the pool.

-1 means the pool is of unlimited size.

It is not possible to set this property to a positive value less than the AcquiredInstancesCount, doing so will raise an exception. At the same time, it is always possible to set value of this property to -1.

 

property MaxPoolSize: Int32 read write;

 

Int32 MaxPoolSize { get; set; }

 

Property MaxPoolSize() As Int32

NonAcquiredInstancesCount    (declared in BaseObjectPool<TItem>)

Gets the number of pool items that were instantiated but are not currently acquired.

 

property NonAcquiredInstancesCount: Int32 read;

 

Int32 NonAcquiredInstancesCount { get; }

 

ReadOnly Property NonAcquiredInstancesCount() As Int32

PoolSize    (declared in BaseObjectPool<TItem>)

Gets the current pool size. The value of this property equals the sum of the AcquiredInstancesCount and the NonAcquiredInstancesCount.

 

property PoolSize: Int32 read;

 

Int32 PoolSize { get; }

 

ReadOnly Property PoolSize() As Int32

WaitTimeOut    (declared in BaseObjectPool<TItem>)

Gets or sets the timeout in milliseconds for acquiring new pool items. This is the time that the pool will wait to acquire a new instance before throwing a timeout exception when the Behavior is set to PoolBehavior.Wait.

If the value is -1, the pool will wait indefinitely.

 

property WaitTimeOut: Int32 read write;

 

Int32 WaitTimeOut { get; set; }

 

Property WaitTimeOut() As Int32

 

constructor  protected    (declared in BaseObjectPool<TItem>)

Creates a new instance of the BaseObjectPool class.

The created pool will have the size -1 (i.e. infinite).

Cannot be called directly.

 

constructor

 

CustomObjectPool<TItem>()

 

Sub New()

constructor (PoolBehavior, Int32, Int32)  protected    (declared in BaseObjectPool<TItem>)

 

constructor(behavior: PoolBehavior; maxSize: Int32; timeout: Int32)

 

CustomObjectPool<TItem>(PoolBehavior behavior, Int32 maxSize, Int32 timeout)

 

Sub New(behavior As PoolBehavior, maxSize As Int32, timeout As Int32)

Parameters:

  • behavior:
  • maxSize:
  • timeout:

 

constructor(createInstanceDelegate: CreateInstanceDelegate<TItem>)

 

CustomObjectPool<TItem>(CreateInstanceDelegate<TItem> createInstanceDelegate)

 

Sub New(createInstanceDelegate As CreateInstanceDelegate<TItem>)

Parameters:

  • createInstanceDelegate:

 

constructor(createInstanceDelegate: CreateInstanceDelegate<TItem>; behavior: PoolBehavior; initialSize: Int32)

 

CustomObjectPool<TItem>(CreateInstanceDelegate<TItem> createInstanceDelegate, PoolBehavior behavior, Int32 initialSize)

 

Sub New(createInstanceDelegate As CreateInstanceDelegate<TItem>, behavior As PoolBehavior, initialSize As Int32)

Parameters:

  • createInstanceDelegate:
  • behavior:
  • initialSize:

constructor (CreateInstanceDelegate<TItem>, PoolBehavior, Int32, Int32, Int32)

 

constructor(createInstanceDelegate: CreateInstanceDelegate<TItem>; behavior: PoolBehavior; initialSize: Int32; maxSize: Int32; timeout: Int32)

 

CustomObjectPool<TItem>(CreateInstanceDelegate<TItem> createInstanceDelegate, PoolBehavior behavior, Int32 initialSize, Int32 maxSize, Int32 timeout)

 

Sub New(createInstanceDelegate As CreateInstanceDelegate<TItem>, behavior As PoolBehavior, initialSize As Int32, maxSize As Int32, timeout As Int32)

Parameters:

  • createInstanceDelegate:
  • behavior:
  • initialSize:
  • maxSize:
  • timeout:

 

constructor(createInstanceDelegate: CreateInstanceDelegate<TItem>; disposeInstanceDelegate: DisposeInstanceDelegate<TItem>)

 

CustomObjectPool<TItem>(CreateInstanceDelegate<TItem> createInstanceDelegate, DisposeInstanceDelegate<TItem> disposeInstanceDelegate)

 

Sub New(createInstanceDelegate As CreateInstanceDelegate<TItem>, disposeInstanceDelegate As DisposeInstanceDelegate<TItem>)

Parameters:

  • createInstanceDelegate:
  • disposeInstanceDelegate:

 

constructor(createInstanceDelegate: CreateInstanceDelegate<TItem>; disposeInstanceDelegate: DisposeInstanceDelegate<TItem>; behavior: PoolBehavior; initialSize: Int32)

 

CustomObjectPool<TItem>(CreateInstanceDelegate<TItem> createInstanceDelegate, DisposeInstanceDelegate<TItem> disposeInstanceDelegate, PoolBehavior behavior, Int32 initialSize)

 

Sub New(createInstanceDelegate As CreateInstanceDelegate<TItem>, disposeInstanceDelegate As DisposeInstanceDelegate<TItem>, behavior As PoolBehavior, initialSize As Int32)

Parameters:

  • createInstanceDelegate:
  • disposeInstanceDelegate:
  • behavior:
  • initialSize:

 

constructor(createInstanceDelegate: CreateInstanceDelegate<TItem>; disposeInstanceDelegate: DisposeInstanceDelegate<TItem>; behavior: PoolBehavior; initialSize: Int32; maxSize: Int32; timeout: Int32)

 

CustomObjectPool<TItem>(CreateInstanceDelegate<TItem> createInstanceDelegate, DisposeInstanceDelegate<TItem> disposeInstanceDelegate, PoolBehavior behavior, Int32 initialSize, Int32 maxSize, Int32 timeout)

 

Sub New(createInstanceDelegate As CreateInstanceDelegate<TItem>, disposeInstanceDelegate As DisposeInstanceDelegate<TItem>, behavior As PoolBehavior, initialSize As Int32, maxSize As Int32, timeout As Int32)

Parameters:

  • createInstanceDelegate:
  • disposeInstanceDelegate:
  • behavior:
  • initialSize:
  • maxSize:
  • timeout:

AcquireInstance    (declared in BaseObjectPool<TItem>)

Acquires an item from the pool.

If there are non-acquired pool items or pool has an infinite size, the pool item is acquired and returned to the caller. Otherwise, the Behavior property specifies the result of the method call:

  • PoolBehavior.Wait - wait until any pool item becomes available.
  • PoolBehavior.IgnoreAndReturn - wait for no more than WaitTimeOut milliseconds for any pool items. If there still are no pool items available after timeout, null will be returned.
  • PoolBehavior.Raise - wait for no more than WaitTimeOut milliseconds for any pool items. If there still are no pool items available after timeout, an NoFreeObjectsInPoolException is raised.

 

method AcquireInstance: TItem

 

TItem AcquireInstance()

 

Function AcquireInstance() As TItem

Clear    (declared in BaseObjectPool<TItem>)

Clears all items from the pool.

 

method Clear

 

void Clear()

 

Sub Clear()

Dispose    (declared in BaseObjectPool<TItem>)

Releases all pool resources.

The FinalizePool method can be overridden in case some specific cleanup actions are needed.

 

method Dispose

 

void Dispose()

 

Sub Dispose()

DropInstance    (declared in BaseObjectPool<TItem>)

Removes the anItem object from the pool.

 

method DropInstance(item: TItem)

 

void DropInstance(TItem item)

 

Sub DropInstance(item As TItem)

Parameters:

  • item:

ExposeNonAcquiredInstances    (declared in BaseObjectPool<TItem>)

Exposes all non-acquired pool objects using the specified aDelegate.

 

method ExposeNonAcquiredInstances(action: ExposeNonAcquiredInstancesDelegate<TItem>)

 

void ExposeNonAcquiredInstances(ExposeNonAcquiredInstancesDelegate<TItem> action)

 

Sub ExposeNonAcquiredInstances(action As ExposeNonAcquiredInstancesDelegate<TItem>)

Parameters:

  • action:

FinalizePool  protected    (declared in BaseObjectPool<TItem>)

Finalizes the object pool.

This method's implementation is empty in the BaseObjectPool class but can be overriden in derived classes in case some specific cleanup actions are needed.

 

method FinalizePool

 

void FinalizePool()

 

Sub FinalizePool()

GetEnumerator    (declared in BaseObjectPool<TItem>)

Returns an enumerator that iterates through a collection of non-acquired pool objects.

This method is part of the IEnumerable interface implementation.

 

method GetEnumerator: IEnumerator

 

IEnumerator GetEnumerator()

 

Function GetEnumerator() As IEnumerator

MoveNext    (declared in BaseObjectPool<TItem>)

Advances the enumerator to the next element of the collection of non-acquired object pool items.

This property is part of the IEnumerator interface implementation.

 

method MoveNext: Boolean

 

Boolean MoveNext()

 

Function MoveNext() As Boolean

OnCreateInstance  protected

This method fires a CreateInstance event to instantiate a new object pool item.

 

method OnCreateInstance: TItem

 

TItem OnCreateInstance()

 

Function OnCreateInstance() As TItem

OnDisposeInstance  protected

 

method OnDisposeInstance(instance: TItem)

 

void OnDisposeInstance(TItem instance)

 

Sub OnDisposeInstance(instance As TItem)

Parameters:

  • instance:

ReleaseInstance    (declared in BaseObjectPool<TItem>)

Releases an acquired item back into the object pool.

 

method ReleaseInstance(item: TItem)

 

void ReleaseInstance(TItem item)

 

Sub ReleaseInstance(item As TItem)

Parameters:

  • item:

Reset    (declared in BaseObjectPool<TItem>)

Sets the enumerator to its initial position, which is before the first element in the collection of non-acquired object pool items.

This property is part of the IEnumerator interface implementation.

 

method Reset

 

void Reset()

 

Sub Reset()

Resize    (declared in BaseObjectPool<TItem>)

Instantiates the object pool items until there are at least aNewSize non-acquired items in the pool.

If the value of the second parameter is true, this method also sets the MaxPoolSize to aNewSize.

If the value of the second parameter is false and there are more pool items (both acquired and non-acquired) than aNewSize, an exception is raised.

 

method Resize(newSize: Int32; resetMaxPoolSize: Boolean): Int32

 

Int32 Resize(Int32 newSize, Boolean resetMaxPoolSize)

 

Function Resize(newSize As Int32, resetMaxPoolSize As Boolean) As Int32

Parameters:

  • newSize:
  • resetMaxPoolSize: