Examples of CursorableLinkedList


Examples of org.apache.commons.collections.CursorableLinkedList

        _totalIdle = 0;
        notifyAll();
    }

    public synchronized void clear(Object key) {
        CursorableLinkedList pool = (CursorableLinkedList)(_poolMap.remove(key));
        if(null == pool) {
            return;
        } else {
            _poolList.remove(key);
            Iterator it = pool.iterator();
            while(it.hasNext()) {
                try {
                    _factory.destroyObject(key,((ObjectTimestampPair)(it.next())).value);
                } catch(Exception e) {
                    // ignore error, keep destroying the rest
View Full Code Here

Examples of org.apache.commons.collections.CursorableLinkedList

    }

    public void returnObject(Object key, Object obj) throws Exception {

        // grab the pool (list) of objects associated with the given key
        CursorableLinkedList pool = null;
        synchronized(this) {
            pool = (CursorableLinkedList)(_poolMap.get(key));
            // if it doesn't exist, create it
            if(null == pool) {
                pool = new CursorableLinkedList();
                _poolMap.put(key, pool);
                _poolList.add(key);
            }
        }

        // if we need to validate this object, do so
        boolean success = true; // whether or not this object passed validation
        if((_testOnReturn && !_factory.validateObject(key, obj))) {
            success = false;
            try {
                _factory.destroyObject(key, obj);
            } catch(Exception e) {
                // ignored
            }
        } else {
            try {
                _factory.passivateObject(key, obj);
            } catch(Exception e) {
                success = false;
            }
        }

        boolean shouldDestroy = false;
        synchronized(this) {
            // subtract one from the total and keyed active counts
            _totalActive--;
            Integer active = (Integer)(_activeMap.get(key));
            if(null == active) {
                // do nothing, either null or zero is OK
            } else if(active.intValue() <= 1) {
                _activeMap.remove(key);
            } else {
                _activeMap.put(key, new Integer(active.intValue() - 1));
            }
            // if there's no space in the pool, flag the object
            // for destruction
            // else if we passivated succesfully, return it to the pool
            if(_maxIdle > 0 && (pool.size() >= _maxIdle)) {
                shouldDestroy = true;
            } else if(success) {
                pool.addFirst(new ObjectTimestampPair(obj));
                _totalIdle++;
            }
            notifyAll();
        }
View Full Code Here

Examples of org.apache.commons.collections.CursorableLinkedList

                                // if we don't have an object cursor
                                if(null == objcursor) {
                                    // if the keycursor has a next value, then use it
                                    if(keycursor.hasNext()) {
                                        key = keycursor.next();
                                        CursorableLinkedList pool = (CursorableLinkedList)(_poolMap.get(key));
                                        objcursor = pool.cursor(pool.size());
                                    } else {
                                        // else close the key cursor and loop back around
                                        if(null != keycursor) {
                                            keycursor.close();
                                            keycursor = _poolList.cursor();
View Full Code Here

Examples of org.apache.commons.collections.CursorableLinkedList

        _timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis;
        _numTestsPerEvictionRun = numTestsPerEvictionRun;
        _minEvictableIdleTimeMillis = minEvictableIdleTimeMillis;
        _testWhileIdle = testWhileIdle;

        _pool = new CursorableLinkedList();
        if(_timeBetweenEvictionRunsMillis > 0) {
            _evictor = new Evictor();
            Thread t = new Thread(_evictor);
            t.setDaemon(true);
            t.start();
View Full Code Here

Examples of org.apache.commons.collections.CursorableLinkedList

        _timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis;
        _numTestsPerEvictionRun = numTestsPerEvictionRun;
        _minEvictableIdleTimeMillis = minEvictableIdleTimeMillis;
        _testWhileIdle = testWhileIdle;

        _pool = new CursorableLinkedList();
        if(_timeBetweenEvictionRunsMillis > 0) {
            _evictor = new Evictor();
            Thread t = new Thread(_evictor);
            t.setDaemon(true);
            t.start();
View Full Code Here

Examples of org.apache.commons.collections.CursorableLinkedList

        _minEvictableIdleTimeMillis = minEvictableIdleTimeMillis;
        _testWhileIdle = testWhileIdle;

        _poolMap = new HashMap();
        _activeMap = new HashMap();
        _poolList = new CursorableLinkedList();

        if(_timeBetweenEvictionRunsMillis > 0) {
            _evictor = new Evictor();
            Thread t = new Thread(_evictor);
            t.setDaemon(true);
View Full Code Here

Examples of org.apache.commons.collections.CursorableLinkedList

    //-- ObjectPool methods ------------------------------------------

    public synchronized Object borrowObject(Object key) throws Exception {
        long starttime = System.currentTimeMillis();
        for(;;) {
            CursorableLinkedList pool = (CursorableLinkedList)(_poolMap.get(key));
            if(null == pool) {
                pool = new CursorableLinkedList();
                _poolMap.put(key,pool);
                _poolList.add(key);
            }
            ObjectTimestampPair pair = null;
            // if there are any sleeping, just grab one of those
            try {
                pair = (ObjectTimestampPair)(pool.removeFirst());
                if(null != pair) {
                    _totalIdle--;
                }
            } catch(NoSuchElementException e) { /* ignored */
            }
View Full Code Here

Examples of org.apache.commons.collections.CursorableLinkedList

    public synchronized void clear() {
        Iterator keyiter = _poolList.iterator();
        while(keyiter.hasNext()) {
            Object key = keyiter.next();
            CursorableLinkedList list = (CursorableLinkedList)(_poolMap.get(key));
            Iterator it = list.iterator();
            while(it.hasNext()) {
                try {
                    _factory.destroyObject(key,((ObjectTimestampPair)(it.next())).value);
                } catch(Exception e) {
                    // ignore error, keep destroying the rest
View Full Code Here

Examples of org.apache.commons.collections.CursorableLinkedList

        _totalIdle = 0;
        notifyAll();
    }

    public synchronized void clear(Object key) {
        CursorableLinkedList pool = (CursorableLinkedList)(_poolMap.remove(key));
        if(null == pool) {
            return;
        } else {
            _poolList.remove(key);
            Iterator it = pool.iterator();
            while(it.hasNext()) {
                try {
                    _factory.destroyObject(key,((ObjectTimestampPair)(it.next())).value);
                } catch(Exception e) {
                    // ignore error, keep destroying the rest
View Full Code Here

Examples of org.apache.commons.collections.CursorableLinkedList

    }

    public void returnObject(Object key, Object obj) throws Exception {

        // grab the pool (list) of objects associated with the given key
        CursorableLinkedList pool = null;
        synchronized(this) {
            pool = (CursorableLinkedList)(_poolMap.get(key));
            // if it doesn't exist, create it
            if(null == pool) {
                pool = new CursorableLinkedList();
                _poolMap.put(key, pool);
                _poolList.add(key);
            }
        }

        // if we need to validate this object, do so
        boolean success = true; // whether or not this object passed validation
        if((_testOnReturn && !_factory.validateObject(key, obj))) {
            success = false;
            try {
                _factory.destroyObject(key, obj);
            } catch(Exception e) {
                // ignored
            }
        } else {
            try {
                _factory.passivateObject(key, obj);
            } catch(Exception e) {
                success = false;
            }
        }

        boolean shouldDestroy = false;
        synchronized(this) {
            // subtract one from the total and keyed active counts
            _totalActive--;
            Integer active = (Integer)(_activeMap.get(key));
            if(null == active) {
                // do nothing, either null or zero is OK
            } else if(active.intValue() <= 1) {
                _activeMap.remove(key);
            } else {
                _activeMap.put(key, new Integer(active.intValue() - 1));
            }
            // if there's no space in the pool, flag the object
            // for destruction
            // else if we passivated succesfully, return it to the pool
            if(_maxIdle > 0 && (pool.size() >= _maxIdle)) {
                shouldDestroy = true;
            } else if(success) {
                pool.addFirst(new ObjectTimestampPair(obj));
                _totalIdle++;
            }
            notifyAll();
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.