structs.PriorityPool Extends goog.structs.Pool
A generic pool class. If max is greater than min, an error is thrown.

Inheritance

Constructor

goog.structs.PriorityPool(opt_minCountopt_maxCount)

Parameters

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

Instance Methods

Public Protected Private
addFreeObject(obj)
Adds an object to the collection of objects that are free. If the object can not be added, then it is disposed. NOTE: This method does not remove the object from the in use collection.
Arguments:
obj : VALUE
The object to add to the collection of free objects.
code »
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).
code »
disposeInternal()
No description.
code »
getObject(opt_callbackopt_priority) VALUE | undefined
Get a new object from the the pool, if there is one available, otherwise return undefined.
Arguments:
opt_callback : Function=
The function to callback when an object is available. This could be immediately. If this is not present, then an object is immediately returned if available, or undefined if not.
opt_priority : number=
The priority of the request. A smaller value means a higher priority.
Returns: VALUE | undefined  The new object from the pool if there is one available and a callback is not given. Otherwise, undefined.
code »
handleQueueRequests_()
Handles the request queue. Tries to fires off as many queued requests as possible.
code »
setDelay()
No description.
code »
addFreeObject(obj)
Adds an object to the collection of objects that are free. If the object can not be added, then it is disposed.
Arguments:
obj : T
The object to add to collection of free objects.
code »
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).
code »
contains(obj) boolean
Returns true if the given object is in the pool.
Arguments:
obj : T
The object to check the pool for.
Returns: boolean  Whether the pool contains the object.
code »
createObject() T
Should be overridden by sub-classes to return an instance of the object type that is expected in the pool.
Returns: T  The created object.
code »
disposeInternal()
Disposes of the pool and all objects currently held in the pool.
code »
disposeObject(obj)
Should be overridden to dispose of an object. Default implementation is to remove all its members, which should render it useless. Calls the object's dispose() method, if available.
Arguments:
obj : T
The object to dispose.
code »
getCount() number
Returns the number of objects currently in the pool.
Returns: number  Number of objects currently in the pool.
code »
getFreeCount() number
Returns the number of objects currently free in the pool.
Returns: number  Number of objects currently free in the pool.
code »
getInUseCount() number
Returns the number of objects currently in use in the pool.
Returns: number  Number of objects currently in use in the pool.
code »
getObject() T | undefined
No description.
Returns: T | undefined  A new object from the pool if there is one available, otherwise undefined.
code »
isEmpty() boolean
Determines if the pool contains no objects.
Returns: boolean  Whether the pool contains no objects.
code »
objectCanBeReused(obj) boolean
Should be overridden to determine whether an object has become unusable and should not be returned by getObject(). Calls the object's canBeReused() method, if available.
Arguments:
obj : T
The object to test.
Returns: boolean  Whether the object can be reused.
code »
releaseObject(obj) boolean
Returns an object to the pool of available objects so that it can be reused.
Arguments:
obj : T
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).
code »
removeFreeObject_() T | 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.
Returns: T | undefined  The object removed from the free collection, if there is one available. Otherwise, undefined.
code »
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.
Arguments:
delay : number
The minimum delay, in milliseconds.
code »
setMaximumCount(max)
Sets the maximum count of the pool. If max is less than the max count of the pool, an error is thrown.
Arguments:
max : number
The maximum count of the pool.
code »
setMinimumCount(min)
Sets the minimum count of the pool. If min is greater than the max count of the pool, an error is thrown.
Arguments:
min : number
The minimum count of the pool.
code »
addOnDisposeCallback(callbackopt_scope)
Invokes a callback function when this object is disposed. Callbacks are invoked in the order in which they were added.
Arguments:
callback : function(this:T):?
The callback function.
opt_scope : T=
An optional scope to call the callback in.
code »
dispose() void
Disposes of the object. If the object hasn't already been disposed of, calls #disposeInternal. Classes that extend goog.Disposable should override #disposeInternal in order to delete references to COM objects, DOM nodes, and other disposable objects. Reentrant.
Returns: void  Nothing.
code »
disposeInternal()
Deletes or nulls out any references to COM objects, DOM nodes, or other disposable objects. Classes that extend goog.Disposable should override this method. Not reentrant. To avoid calling it twice, it must only be called from the subclass' disposeInternal method. Everywhere else the public dispose method must be used. For example:
  mypackage.MyClass = function() {
    mypackage.MyClass.base(this, 'constructor');
    // Constructor logic specific to MyClass.
    ...
  };
  goog.inherits(mypackage.MyClass, goog.Disposable);

  mypackage.MyClass.prototype.disposeInternal = function() {
    // Dispose logic specific to MyClass.
    ...
    // Call superclass's disposeInternal at the end of the subclass's, like
    // in C++, to avoid hard-to-catch issues.
    mypackage.MyClass.base(this, 'disposeInternal');
  };
code »
getDisposed() boolean
Use #isDisposed instead. No description.
Returns: boolean  Whether the object has been disposed of.
code »
isDisposed() boolean
No description.
Returns: boolean  Whether the object has been disposed of.
code »
registerDisposable(disposable)
Associates a disposable object with this object so that they will be disposed together.
Arguments:
disposable : goog.disposable.IDisposable
that will be disposed when this object is disposed.
code »

Instance Properties

constructor :
No description.
Code »
delayTimeout_ :
The key for the most recent timeout created.
Code »
requestQueue_ : goog.structs.PriorityQueue
Queue of requests for pool objects.
Code »
constructor :
No description.
Code »
delay :
The minimum delay between objects being made available, in milliseconds. If this is 0, no minimum delay is enforced.
Code »
freeQueue_ : goog.structs.Queue
Set used to store objects that are currently in the pool and available to be used.
Code »
inUseSet_ : goog.structs.Set
Set used to store objects that are currently in the pool and in use.
Code »
lastAccess :
The time of the last object being made available, in milliseconds since the epoch (i.e., the result of Date#toTime). If this is null, no access has occurred yet.
Code »
maxCount_ :
Maximum number of objects allowed
Code »
minCount_ :
Minimum number of objects allowed
Code »
creationStack :
If monitoring the goog.Disposable instances is enabled, stores the creation stack trace of the Disposable instance.
Code »
disposed_ :
Whether the object has been disposed of.
Code »
onDisposeCallbacks_ :
Callbacks to invoke when this object is disposed.
Code »

Static Properties

goog.structs.PriorityPool.DEFAULT_PRIORITY_ :
Default priority for pool objects requests.
Code »
goog.structs.PriorityPool.superClass_ :
No description.
Code »

Package structs

Package Reference