FileDocCategorySizeDatePackage
SimplePool.javaAPI DocExample1648Thu Nov 08 00:22:36 GMT 2001com.ora.rmibook.chapter12.pool.simple

SimplePool

public class SimplePool extends Object implements Pool

Fields Summary
private int
_maximumIndex
private int
_currentPosition
private PoolHelper
_helper
private Object[]
_availableObjects
Constructors Summary
public SimplePool(int startingSize, int maximumSize, PoolHelper helper)

        _maximumIndex = maximumSize - 1;
        _helper = helper;
        buildInitialObjects(startingSize, maximumSize);
    
Methods Summary
private voidbuildInitialObjects(int startingSize, int maximumSize)

        _availableObjects = new Object[maximumSize];
        int counter;

        for (counter = 0; counter < startingSize; counter++) {
            _availableObjects[counter] = _helper.create();
        }
        _currentPosition = startingSize - 1;
    
public synchronized java.lang.ObjectgetObject()

        if (_currentPosition == -1) {
            return _helper.create();
        }
        return getObjectFromArray();
    
private java.lang.ObjectgetObjectFromArray()

        Object returnValue = _availableObjects[_currentPosition];

        _availableObjects[_currentPosition] = null;
        _currentPosition--;
        return returnValue;
    
public synchronized voidreturnObject(java.lang.Object object)

        if (_currentPosition == _maximumIndex) {
            _helper.dispose(object);
            return;
        }
        if (!_helper.isObjectStillValid(object)) {
            _helper.dispose(object);
            return;
        }
        _currentPosition++;
        _availableObjects[_currentPosition] = object;