Class comb.collections.Pool
Base class for a pool.
Defined in: Pool.js.
Field Detail
{Number}
count
the total number of objects in the pool, including free and in use objects.
{Number}
freeCount
the number of free objects in this pool.
{Number}
inUseCount
the number of objects in use in this pool.
{Number}
maxObjects
the maximum number of objects this pool should contain
- Default Value:
- 1
{Number}
minObjects
the minimum number of objects this pool should contain.
- Default Value:
- 0
Method Detail
{Object}
createObject()
Creates a new object for this pool.
*
THIS SHOULD BE OVERRIDDEN TO ADD THE CORRECT TYPE OF OBJECT
- Returns:
- {Object} be default just creates an object.
return {};
{*}
getObject()
Retrieves an object from this pool.
`
- Returns:
- {*} an object to contained in this pool
var ret = undefined;
if (this.freeCount > 0) {
ret = this.__freeObjects.dequeue();
this.__inUseObjects.push(ret);
} else if (this.__maxObjects > this.count) {
ret = this.createObject();
this.__inUseObjects.push(ret);
}
return ret;
{*}
removeObject(obj)
Removes an object from the pool, this can be overriden to provide any
teardown of objects that needs to take place.
- Parameters:
- {*} obj
- the object that needs to be removed.
- Returns:
- {*} the object removed.
var index;
if (this.__freeObjects.contains(obj)) {
this.__freeObjects.remove(obj);
} else if ((index = this.__inUseObjects.indexOf(obj)) > -1) {
this.__inUseObjects.splice(index, 1);
}
return obj;
returnObject(obj)
Returns an object to this pool. The object is validated before it is returned to the pool,
if the validation fails then it is removed from the pool;
- Parameters:
- {*} obj
- the object to return to the pool
if (this.validate(obj) && this.count <= this.__maxObjects) {
this.__freeObjects.enqueue(obj);
var index;
if ((index = this.__inUseObjects.indexOf(obj)) > -1)
this.__inUseObjects.splice(index, 1);
} else {
this.removeObject(obj);
}
validate(obj)
Validates an object in this pool.
THIS SHOULD BE OVERRIDDEN TO VALIDATE
- Parameters:
- {*} obj
- the object to validate.
return true;
Documentation generated by JsDoc Toolkit 2.4.0 on Tue Jan 31 2012 16:14:12 GMT-0600 (CST)