A generic pool class. If min is greater than max, an error is thrown.
extends goog.Disposable| Instance Method Summary | |
addFreeObject(?Object obj)Adds an object to the collection of objects that are free. If the object can not be added, then it is disposed. | |
adjustForMinMax()Adjusts the objects held in the pool to be within the min/max constraints. NOTE: It is possible that the number of objects in the pool will still be greater than the maximum count of objects allowed. This will be the case if no more free objects can be disposed of to get below the minimum count (i.e., all objects are in use). | |
contains(?Object obj) ⇒ booleanReturns true if the given object is in the pool. | |
createObject() ⇒ ?ObjectShould be overriden by sub-classes to return an instance of the object type that is expected in the pool. | |
disposeInternal()Disposes of the pool and all objects currently held in the pool. | |
disposeObject(?Object obj)Should be overriden to dispose of an object. Default implementation is to remove all its members, which should render it useless. Calls the object's {@code dispose()} method, if available. | |
getCount() ⇒ numberReturns the number of objects currently in the pool. | |
getFreeCount() ⇒ numberReturns the number of objects currently free in the pool. | |
getInUseCount() ⇒ numberReturns the number of objects currently in use in the pool. | |
getObject() ⇒ (Object|null|undefined) | |
isEmpty() ⇒ booleanDetermines if the pool contains no objects. | |
objectCanBeReused(?Object obj) ⇒ booleanShould be overriden to determine whether an object has become unusable and should not be returned by getObject(). Calls the object's {@code canBeReused()} method, if available. | |
releaseObject(?Object obj) ⇒ booleanReturns an object to the pool of available objects so that it can be reused. | |
removeFreeObject_() ⇒ (Object|null|undefined)Removes a free object from the collection of objects that are free so that it can be used. NOTE: This method does not mark the returned object as in use. | |
setDelay(number delay)Sets the minimum delay between objects being returned by getObject, in milliseconds. This defaults to zero, meaning that no minimum delay is enforced and objects may be used as soon as they're available. | |
setMaximumCount(number max)Sets the maximum count of the pool. If max is less than the max count of the pool, an error is thrown. | |
setMinimumCount(number min)Sets the minimum count of the pool. If min is greater than the max count of the pool, an error is thrown. | |