Examples of ObjectTimestampPair


Examples of org.apache.commons.pool.impl.GenericKeyedObjectPool.ObjectTimestampPair

                _evictionCursor = (_pool.cursor(_lifo ? _pool.size() : 0));
            }
        }

        for (int i=0,m=getNumTests();i<m;i++) {
            final ObjectTimestampPair pair;
            synchronized (this) {
                if ((_lifo && !_evictionCursor.hasPrevious()) ||
                        !_lifo && !_evictionCursor.hasNext()) {
                    _evictionCursor.close();
                    _evictionCursor = _pool.cursor(_lifo ? _pool.size() : 0);
View Full Code Here

Examples of org.apache.commons.pool.impl.GenericKeyedObjectPool.ObjectTimestampPair

        buf.append("Idle: ").append(getNumIdle()).append("\n");
        buf.append("Idle Objects:\n");
        Iterator it = _pool.iterator();
        long time = System.currentTimeMillis();
        while(it.hasNext()) {
            ObjectTimestampPair pair = (ObjectTimestampPair)(it.next());
            buf.append("\t").append(pair.value).append("\t").append(time - pair.tstamp).append("\n");
        }
        return buf.toString();
    }
View Full Code Here

Examples of org.apache.commons.pool.impl.GenericKeyedObjectPool.ObjectTimestampPair

    public synchronized Object borrowObject() throws Exception {
        assertOpen();
        long starttime = System.currentTimeMillis();
        for(;;) {
            ObjectTimestampPair pair = null;

            // if there are any sleeping, just grab one of those
            try {
                pair = (ObjectTimestampPair)(_pool.removeFirst());
            } catch(NoSuchElementException e) {
                ; /* ignored */
            }

            // otherwise
            if(null == pair) {
                // check if we can create one
                // (note we know that the num sleeping is 0, else we wouldn't be here)
                if(_maxActive < 0 || _numActive < _maxActive) {
                    // allow new object to be created
                } else {
                    // the pool is exhausted
                    switch(_whenExhaustedAction) {
                        case WHEN_EXHAUSTED_GROW:
                            // allow new object to be created
                            break;
                        case WHEN_EXHAUSTED_FAIL:
                            throw new NoSuchElementException("Pool exhausted");
                        case WHEN_EXHAUSTED_BLOCK:
                            try {
                                if(_maxWait <= 0) {
                                    wait();
                                } else {
                                    // this code may be executed again after a notify then continue cycle
                                    // so, need to calculate the amount of time to wait
                                    final long elapsed = (System.currentTimeMillis() - starttime);
                                    final long waitTime = _maxWait - elapsed;
                                    if (waitTime > 0)
                                    {
                                        wait(waitTime);
                                    }
                                }
                            } catch(InterruptedException e) {
                                // ignored
                            }
                            if(_maxWait > 0 && ((System.currentTimeMillis() - starttime) >= _maxWait)) {
                                throw new NoSuchElementException("Timeout waiting for idle object");
                            } else {
                                continue; // keep looping
                            }
                        default:
                            throw new IllegalArgumentException("WhenExhaustedAction property " + _whenExhaustedAction + " not recognized.");
                    }
                }
            }
            _numActive++;

            // create new object when needed
            boolean newlyCreated = false;
            if(null == pair) {
                try {
                    Object obj = _factory.makeObject();
                    pair = new ObjectTimestampPair(obj);
                    newlyCreated = true;
                } finally {
                    if (!newlyCreated) {
                        // object cannot be created
                        _numActive--;
View Full Code Here

Examples of org.apache.commons.pool.impl.GenericKeyedObjectPool.ObjectTimestampPair

            _numActive--;
        }
        if((_maxIdle >= 0) && (_pool.size() >= _maxIdle)) {
            shouldDestroy = true;
        } else if(success) {
            _pool.addLast(new ObjectTimestampPair(obj));
        }
        notifyAll(); // _numActive has changed

        if(shouldDestroy) {
            try {
View Full Code Here

Examples of org.apache.commons.pool.impl.GenericKeyedObjectPool.ObjectTimestampPair

            for(int i=0,m=getNumTests();i<m;i++) {
                if(!iter.hasPrevious()) {
                    iter = _pool.listIterator(_pool.size());
                }
                boolean removeObject = false;
                final ObjectTimestampPair pair = (ObjectTimestampPair)(iter.previous());
                final long idleTimeMilis = System.currentTimeMillis() - pair.tstamp;
                if ((_minEvictableIdleTimeMillis > 0)
                        && (idleTimeMilis > _minEvictableIdleTimeMillis)) {
                    removeObject = true;
                } else if ((_softMinEvictableIdleTimeMillis > 0)
View Full Code Here

Examples of org.apache.commons.pool.impl.GenericKeyedObjectPool.ObjectTimestampPair

        buf.append("Idle: ").append(getNumIdle()).append("\n");
        buf.append("Idle Objects:\n");
        Iterator it = _pool.iterator();
        long time = System.currentTimeMillis();
        while(it.hasNext()) {
            ObjectTimestampPair pair = (ObjectTimestampPair)(it.next());
            buf.append("\t").append(pair.value).append("\t").append(time - pair.tstamp).append("\n");
        }
        return buf.toString();
    }
View Full Code Here

Examples of org.apache.commons.pool.impl.GenericKeyedObjectPool.ObjectTimestampPair

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

    public Object borrowObject() throws Exception {
        long starttime = System.currentTimeMillis();
        for(;;) {
            ObjectTimestampPair pair = null;
           
            synchronized (this) {
                assertOpen();
                // if there are any sleeping, just grab one of those
                try {
                    pair = (ObjectTimestampPair)(_pool.removeFirst());
                } catch(NoSuchElementException e) {
                    ; /* ignored */
                }
   
                // otherwise
                if(null == pair) {
                    // check if we can create one
                    // (note we know that the num sleeping is 0, else we wouldn't be here)
                    if(_maxActive < 0 || _numActive < _maxActive) {
                        // allow new object to be created
                    } else {
                        // the pool is exhausted
                        switch(_whenExhaustedAction) {
                            case WHEN_EXHAUSTED_GROW:
                                // allow new object to be created
                                break;
                            case WHEN_EXHAUSTED_FAIL:
                                throw new NoSuchElementException("Pool exhausted");
                            case WHEN_EXHAUSTED_BLOCK:
                                try {
                                    if(_maxWait <= 0) {
                                        wait();
                                    } else {
                                        // this code may be executed again after a notify then continue cycle
                                        // so, need to calculate the amount of time to wait
                                        final long elapsed = (System.currentTimeMillis() - starttime);
                                        final long waitTime = _maxWait - elapsed;
                                        if (waitTime > 0)
                                        {
                                            wait(waitTime);
                                        }
                                    }
                                } catch(InterruptedException e) {
                                    Thread.currentThread().interrupt();
                                    throw e;
                                }
                                if(_maxWait > 0 && ((System.currentTimeMillis() - starttime) >= _maxWait)) {
                                    throw new NoSuchElementException("Timeout waiting for idle object");
                                } else {
                                    continue; // keep looping
                                }
                            default:
                                throw new IllegalArgumentException("WhenExhaustedAction property " + _whenExhaustedAction + " not recognized.");
                        }
                    }
                }
                _numActive++;
            }

            // create new object when needed
            boolean newlyCreated = false;
            if(null == pair) {
                try {
                    Object obj = _factory.makeObject();
                    pair = new ObjectTimestampPair(obj);
                    newlyCreated = true;
                } finally {
                    if (!newlyCreated) {
                        // object cannot be created
                        synchronized (this) {
View Full Code Here

Examples of org.apache.commons.pool.impl.GenericKeyedObjectPool.ObjectTimestampPair

                    shouldDestroy = true;
                } else if(success) {
                    // borrowObject always takes the first element from the queue,
                    // so for LIFO, push on top, FIFO add to end
                    if (_lifo) {
                        _pool.addFirst(new ObjectTimestampPair(obj));
                    } else {
                        _pool.addLast(new ObjectTimestampPair(obj));
                    }
                }
            }
        }
View Full Code Here

Examples of org.apache.commons.pool.impl.GenericKeyedObjectPool.ObjectTimestampPair

                        !_lifo && !_evictionCursor.hasNext()) {
                    _evictionCursor.close();
                    _evictionCursor = _pool.cursor(_lifo ? _pool.size() : 0);
                }
                boolean removeObject = false;
                final ObjectTimestampPair pair = _lifo ?
                    (ObjectTimestampPair) _evictionCursor.previous() :
                    (ObjectTimestampPair) _evictionCursor.next();
                final long idleTimeMilis = System.currentTimeMillis() - pair.tstamp;
                if ((_minEvictableIdleTimeMillis > 0)
                        && (idleTimeMilis > _minEvictableIdleTimeMillis)) {
View Full Code Here

Examples of org.apache.commons.pool.impl.GenericKeyedObjectPool.ObjectTimestampPair

        buf.append("Idle: ").append(getNumIdle()).append("\n");
        buf.append("Idle Objects:\n");
        Iterator it = _pool.iterator();
        long time = System.currentTimeMillis();
        while(it.hasNext()) {
            ObjectTimestampPair pair = (ObjectTimestampPair)(it.next());
            buf.append("\t").append(pair.value).append("\t").append(time - pair.tstamp).append("\n");
        }
        return buf.toString();
    }
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.