The goog.structs.Pool Class

goog.structs.Pool
> goog.Disposable

goog.structs.Pool(opt_minCount, opt_maxCount)

A generic pool class. If min is greater than max, an error is thrown.

opt_minCount {number=}
Min. number of objects (Default: 1).
opt_maxCount {number=}
Max. number of objects (Default: 10).

.addFreeObject(obj)

Adds an object to the collection of objects that are free. If the object can not be added, then it is disposed.

obj {Object}
The object to add to collection of free objects.

.addOnDisposeCallback(callback, opt_scope)

Inherited from goog.Disposable .

Invokes a callback function when this object is disposed. Callbacks are invoked in the order in which they were added.

callback {!Function}
The callback function.
opt_scope {Object=}
An optional scope to call the callback in.

.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(obj)

Returns true if the given object is in the pool.

obj {Object}
The object to check the pool for.
returns {boolean}
Whether the pool contains the object.

.createObject()

Should be overriden by sub-classes to return an instance of the object type that is expected in the pool.

returns {Object}
The created object.

.creationStack {string}

Inherited from goog.Disposable .

If monitoring the goog.Disposable instances is enabled, stores the creation stack trace of the Disposable instance.

.dispose()

Inherited from goog.Disposable .

Disposes of the object. If the object hasn't already been disposed of, calls {@link #disposeInternal}. Classes that extend {@code goog.Disposable} should override {@link #disposeInternal} in order to delete references to COM objects, DOM nodes, and other disposable objects. Reentrant.

returns {void}
Nothing.

.disposeObject(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.

obj {Object}
The object to dispose.

.getCount()

Returns the number of objects currently in the pool.

returns {number}
Number of objects currently in the pool.

.getFreeCount()

Returns the number of objects currently free in the pool.

returns {number}
Number of objects currently free in the pool.

.getInUseCount()

Returns the number of objects currently in use in the pool.

returns {number}
Number of objects currently in use in the pool.

.getObject()

returns {Object|undefined}
A new object from the pool if there is one available, otherwise undefined.

.isDisposed()

Inherited from goog.Disposable .

returns {boolean}
Whether the object has been disposed of.

.isEmpty()

Determines if the pool contains no objects.

returns {boolean}
Whether the pool contains no objects.

.objectCanBeReused(obj)

Should 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.

obj {Object}
The object to test.
returns {boolean}
Whether the object can be reused.

.registerDisposable(disposable)

Inherited from goog.Disposable .

Associates a disposable object with this object so that they will be disposed together.

disposable {goog.disposable.IDisposable}
that will be disposed when this object is disposed.

.releaseObject(obj)

Returns an object to the pool of available objects so that it can be reused.

obj {Object}
The object to return to the pool of free objects.
returns {boolean}
Whether the object was found in the Pool's set of in-use objects (in other words, whether any action was taken).

.setDelay(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.

delay {number}
The minimum delay, in milliseconds.

.setMaximumCount(max)

Sets the maximum count of the pool. If max is less than the max count of the pool, an error is thrown.

max {number}
The maximium count of the pool.

.setMinimumCount(min)

Sets the minimum count of the pool. If min is greater than the max count of the pool, an error is thrown.

min {number}
The minimum count of the pool.