Return-Path: X-Original-To: apmail-commons-notifications-archive@minotaur.apache.org Delivered-To: apmail-commons-notifications-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id CDD461883B for ; Sun, 31 May 2015 22:24:08 +0000 (UTC) Received: (qmail 53509 invoked by uid 500); 31 May 2015 22:24:08 -0000 Delivered-To: apmail-commons-notifications-archive@commons.apache.org Received: (qmail 53454 invoked by uid 500); 31 May 2015 22:24:08 -0000 Mailing-List: contact notifications-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list notifications@commons.apache.org Received: (qmail 53199 invoked by uid 99); 31 May 2015 22:24:08 -0000 Received: from eris.apache.org (HELO hades.apache.org) (140.211.11.105) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 31 May 2015 22:24:08 +0000 Received: from hades.apache.org (localhost [127.0.0.1]) by hades.apache.org (ASF Mail Server at hades.apache.org) with ESMTP id 803B2AC03CA for ; Sun, 31 May 2015 22:24:08 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r953350 [31/37] - in /websites/production/commons/content/proper/commons-pool: api-2.4.1/ api-2.4.1/org/ api-2.4.1/org/apache/ api-2.4.1/org/apache/commons/ api-2.4.1/org/apache/commons/pool2/ api-2.4.1/org/apache/commons/pool2/class-use/ a... Date: Sun, 31 May 2015 22:24:05 -0000 To: notifications@commons.apache.org From: psteitz@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20150531222408.803B2AC03CA@hades.apache.org> Added: websites/production/commons/content/proper/commons-pool/api-2.4.1/src-html/org/apache/commons/pool2/impl/DefaultPooledObject.html ============================================================================== --- websites/production/commons/content/proper/commons-pool/api-2.4.1/src-html/org/apache/commons/pool2/impl/DefaultPooledObject.html (added) +++ websites/production/commons/content/proper/commons-pool/api-2.4.1/src-html/org/apache/commons/pool2/impl/DefaultPooledObject.html Sun May 31 22:24:03 2015 @@ -0,0 +1,396 @@ + + + +Source code + + + +
+
001/*
+002 * Licensed to the Apache Software Foundation (ASF) under one or more
+003 * contributor license agreements.  See the NOTICE file distributed with
+004 * this work for additional information regarding copyright ownership.
+005 * The ASF licenses this file to You under the Apache License, Version 2.0
+006 * (the "License"); you may not use this file except in compliance with
+007 * the License.  You may obtain a copy of the License at
+008 *
+009 *      http://www.apache.org/licenses/LICENSE-2.0
+010 *
+011 * Unless required by applicable law or agreed to in writing, software
+012 * distributed under the License is distributed on an "AS IS" BASIS,
+013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+014 * See the License for the specific language governing permissions and
+015 * limitations under the License.
+016 */
+017package org.apache.commons.pool2.impl;
+018
+019import java.io.PrintWriter;
+020import java.text.SimpleDateFormat;
+021import java.util.Date;
+022import java.util.Deque;
+023
+024import org.apache.commons.pool2.PooledObject;
+025import org.apache.commons.pool2.PooledObjectState;
+026import org.apache.commons.pool2.TrackedUse;
+027
+028/**
+029 * This wrapper is used to track the additional information, such as state, for
+030 * the pooled objects.
+031 * <p>
+032 * This class is intended to be thread-safe.
+033 *
+034 * @param <T> the type of object in the pool
+035 *
+036 * @version $Revision: $
+037 *
+038 * @since 2.0
+039 */
+040public class DefaultPooledObject<T> implements PooledObject<T> {
+041
+042    private final T object;
+043    private PooledObjectState state = PooledObjectState.IDLE; // @GuardedBy("this") to ensure transitions are valid
+044    private final long createTime = System.currentTimeMillis();
+045    private volatile long lastBorrowTime = createTime;
+046    private volatile long lastUseTime = createTime;
+047    private volatile long lastReturnTime = createTime;
+048    private volatile boolean logAbandoned = false;
+049    private volatile Exception borrowedBy = null;
+050    private volatile Exception usedBy = null;
+051    private volatile long borrowedCount = 0;
+052
+053    /**
+054     * Create a new instance that wraps the provided object so that the pool can
+055     * track the state of the pooled object.
+056     *
+057     * @param object The object to wrap
+058     */
+059    public DefaultPooledObject(T object) {
+060        this.object = object;
+061    }
+062
+063    @Override
+064    public T getObject() {
+065        return object;
+066    }
+067
+068    @Override
+069    public long getCreateTime() {
+070        return createTime;
+071    }
+072
+073    @Override
+074    public long getActiveTimeMillis() {
+075        // Take copies to avoid threading issues
+076        long rTime = lastReturnTime;
+077        long bTime = lastBorrowTime;
+078
+079        if (rTime > bTime) {
+080            return rTime - bTime;
+081        } else {
+082            return System.currentTimeMillis() - bTime;
+083        }
+084    }
+085
+086    @Override
+087    public long getIdleTimeMillis() {
+088        final long elapsed = System.currentTimeMillis() - lastReturnTime;
+089     // elapsed may be negative if:
+090     // - another thread updates lastReturnTime during the calculation window
+091     // - System.currentTimeMillis() is not monotonic (e.g. system time is set back)
+092     return elapsed >= 0 ? elapsed : 0;
+093    }
+094
+095    @Override
+096    public long getLastBorrowTime() {
+097        return lastBorrowTime;
+098    }
+099
+100    @Override
+101    public long getLastReturnTime() {
+102        return lastReturnTime;
+103    }
+104
+105    /**
+106     * Get the number of times this object has been borrowed.
+107     * @return The number of times this object has been borrowed.
+108     * @since 2.1
+109     */
+110    public long getBorrowedCount() {
+111        return borrowedCount;
+112    }
+113
+114    /**
+115     * Return an estimate of the last time this object was used.  If the class
+116     * of the pooled object implements {@link TrackedUse}, what is returned is
+117     * the maximum of {@link TrackedUse#getLastUsed()} and
+118     * {@link #getLastBorrowTime()}; otherwise this method gives the same
+119     * value as {@link #getLastBorrowTime()}.
+120     *
+121     * @return the last time this object was used
+122     */
+123    @Override
+124    public long getLastUsedTime() {
+125        if (object instanceof TrackedUse) {
+126            return Math.max(((TrackedUse) object).getLastUsed(), lastUseTime);
+127        } else {
+128            return lastUseTime;
+129        }
+130    }
+131
+132    @Override
+133    public int compareTo(PooledObject<T> other) {
+134        final long lastActiveDiff = this.getLastReturnTime() - other.getLastReturnTime();
+135        if (lastActiveDiff == 0) {
+136            // Make sure the natural ordering is broadly consistent with equals
+137            // although this will break down if distinct objects have the same
+138            // identity hash code.
+139            // see java.lang.Comparable Javadocs
+140            return System.identityHashCode(this) - System.identityHashCode(other);
+141        }
+142        // handle int overflow
+143        return (int)Math.min(Math.max(lastActiveDiff, Integer.MIN_VALUE), Integer.MAX_VALUE);
+144    }
+145
+146    @Override
+147    public String toString() {
+148        StringBuilder result = new StringBuilder();
+149        result.append("Object: ");
+150        result.append(object.toString());
+151        result.append(", State: ");
+152        synchronized (this) {
+153            result.append(state.toString());
+154        }
+155        return result.toString();
+156        // TODO add other attributes
+157    }
+158
+159    @Override
+160    public synchronized boolean startEvictionTest() {
+161        if (state == PooledObjectState.IDLE) {
+162            state = PooledObjectState.EVICTION;
+163            return true;
+164        }
+165
+166        return false;
+167    }
+168
+169    @Override
+170    public synchronized boolean endEvictionTest(
+171            Deque<PooledObject<T>> idleQueue) {
+172        if (state == PooledObjectState.EVICTION) {
+173            state = PooledObjectState.IDLE;
+174            return true;
+175        } else if (state == PooledObjectState.EVICTION_RETURN_TO_HEAD) {
+176            state = PooledObjectState.IDLE;
+177            if (!idleQueue.offerFirst(this)) {
+178                // TODO - Should never happen
+179            }
+180        }
+181
+182        return false;
+183    }
+184
+185    /**
+186     * Allocates the object.
+187     *
+188     * @return {@code true} if the original state was {@link PooledObjectState#IDLE IDLE}
+189     */
+190    @Override
+191    public synchronized boolean allocate() {
+192        if (state == PooledObjectState.IDLE) {
+193            state = PooledObjectState.ALLOCATED;
+194            lastBorrowTime = System.currentTimeMillis();
+195            lastUseTime = lastBorrowTime;
+196            borrowedCount++;
+197            if (logAbandoned) {
+198                borrowedBy = new AbandonedObjectCreatedException();
+199            }
+200            return true;
+201        } else if (state == PooledObjectState.EVICTION) {
+202            // TODO Allocate anyway and ignore eviction test
+203            state = PooledObjectState.EVICTION_RETURN_TO_HEAD;
+204            return false;
+205        }
+206        // TODO if validating and testOnBorrow == true then pre-allocate for
+207        // performance
+208        return false;
+209    }
+210
+211    /**
+212     * Deallocates the object and sets it {@link PooledObjectState#IDLE IDLE}
+213     * if it is currently {@link PooledObjectState#ALLOCATED ALLOCATED}.
+214     *
+215     * @return {@code true} if the state was {@link PooledObjectState#ALLOCATED ALLOCATED}
+216     */
+217    @Override
+218    public synchronized boolean deallocate() {
+219        if (state == PooledObjectState.ALLOCATED ||
+220                state == PooledObjectState.RETURNING) {
+221            state = PooledObjectState.IDLE;
+222            lastReturnTime = System.currentTimeMillis();
+223            borrowedBy = null;
+224            return true;
+225        }
+226
+227        return false;
+228    }
+229
+230    /**
+231     * Sets the state to {@link PooledObjectState#INVALID INVALID}
+232     */
+233    @Override
+234    public synchronized void invalidate() {
+235        state = PooledObjectState.INVALID;
+236    }
+237
+238    @Override
+239    public void use() {
+240        lastUseTime = System.currentTimeMillis();
+241        usedBy = new Exception("The last code to use this object was:");
+242    }
+243
+244    @Override
+245    public void printStackTrace(PrintWriter writer) {
+246        Exception borrowedByCopy = this.borrowedBy;
+247        if (borrowedByCopy != null) {
+248            borrowedByCopy.printStackTrace(writer);
+249        }
+250        Exception usedByCopy = this.usedBy;
+251        if (usedByCopy != null) {
+252            usedByCopy.printStackTrace(writer);
+253        }
+254    }
+255
+256    /**
+257     * Returns the state of this object.
+258     * @return state
+259     */
+260    @Override
+261    public synchronized PooledObjectState getState() {
+262        return state;
+263    }
+264
+265    /**
+266     * Marks the pooled object as abandoned.
+267     */
+268    @Override
+269    public synchronized void markAbandoned() {
+270        state = PooledObjectState.ABANDONED;
+271    }
+272
+273    /**
+274     * Marks the object as returning to the pool.
+275     */
+276    @Override
+277    public synchronized void markReturning() {
+278        state = PooledObjectState.RETURNING;
+279    }
+280
+281    @Override
+282    public void setLogAbandoned(boolean logAbandoned) {
+283        this.logAbandoned = logAbandoned;
+284    }
+285
+286    /**
+287     * Used to track how an object was obtained from the pool (the stack trace
+288     * of the exception will show which code borrowed the object) and when the
+289     * object was borrowed.
+290     */
+291    static class AbandonedObjectCreatedException extends Exception {
+292
+293        private static final long serialVersionUID = 7398692158058772916L;
+294
+295        /** Date format */
+296        //@GuardedBy("format")
+297        private static final SimpleDateFormat format = new SimpleDateFormat
+298            ("'Pooled object created' yyyy-MM-dd HH:mm:ss Z " +
+299             "'by the following code has not been returned to the pool:'");
+300
+301        private final long _createdTime;
+302
+303        /**
+304         * Create a new instance.
+305         * <p>
+306         * @see Exception#Exception()
+307         */
+308        public AbandonedObjectCreatedException() {
+309            super();
+310            _createdTime = System.currentTimeMillis();
+311        }
+312
+313        // Override getMessage to avoid creating objects and formatting
+314        // dates unless the log message will actually be used.
+315        @Override
+316        public String getMessage() {
+317            String msg;
+318            synchronized(format) {
+319                msg = format.format(new Date(_createdTime));
+320            }
+321            return msg;
+322        }
+323    }
+324}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ + Propchange: websites/production/commons/content/proper/commons-pool/api-2.4.1/src-html/org/apache/commons/pool2/impl/DefaultPooledObject.html ------------------------------------------------------------------------------ svn:eol-style = native Added: websites/production/commons/content/proper/commons-pool/api-2.4.1/src-html/org/apache/commons/pool2/impl/DefaultPooledObjectInfo.html ============================================================================== --- websites/production/commons/content/proper/commons-pool/api-2.4.1/src-html/org/apache/commons/pool2/impl/DefaultPooledObjectInfo.html (added) +++ websites/production/commons/content/proper/commons-pool/api-2.4.1/src-html/org/apache/commons/pool2/impl/DefaultPooledObjectInfo.html Sun May 31 22:24:03 2015 @@ -0,0 +1,175 @@ + + + +Source code + + + +
+
001/*
+002 * Licensed to the Apache Software Foundation (ASF) under one or more
+003 * contributor license agreements.  See the NOTICE file distributed with
+004 * this work for additional information regarding copyright ownership.
+005 * The ASF licenses this file to You under the Apache License, Version 2.0
+006 * (the "License"); you may not use this file except in compliance with
+007 * the License.  You may obtain a copy of the License at
+008 *
+009 *      http://www.apache.org/licenses/LICENSE-2.0
+010 *
+011 * Unless required by applicable law or agreed to in writing, software
+012 * distributed under the License is distributed on an "AS IS" BASIS,
+013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+014 * See the License for the specific language governing permissions and
+015 * limitations under the License.
+016 */
+017package org.apache.commons.pool2.impl;
+018
+019import java.io.PrintWriter;
+020import java.io.StringWriter;
+021import java.text.SimpleDateFormat;
+022
+023import org.apache.commons.pool2.PooledObject;
+024
+025/**
+026 * Implementation of object that is used to provide information on pooled
+027 * objects via JMX.
+028 *
+029 * @since 2.0
+030 */
+031public class DefaultPooledObjectInfo implements DefaultPooledObjectInfoMBean {
+032
+033    private final PooledObject<?> pooledObject;
+034
+035    /**
+036     * Create a new instance for the given pooled object.
+037     *
+038     * @param pooledObject The pooled object that this instance will represent
+039     */
+040    public DefaultPooledObjectInfo(PooledObject<?> pooledObject) {
+041        this.pooledObject = pooledObject;
+042    }
+043
+044    @Override
+045    public long getCreateTime() {
+046        return pooledObject.getCreateTime();
+047    }
+048
+049    @Override
+050    public String getCreateTimeFormatted() {
+051        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z");
+052        return sdf.format(Long.valueOf(pooledObject.getCreateTime()));
+053    }
+054
+055    @Override
+056    public long getLastBorrowTime() {
+057        return pooledObject.getLastBorrowTime();
+058    }
+059
+060    @Override
+061    public String getLastBorrowTimeFormatted() {
+062        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z");
+063        return sdf.format(Long.valueOf(pooledObject.getLastBorrowTime()));
+064    }
+065
+066    @Override
+067    public String getLastBorrowTrace() {
+068        StringWriter sw = new StringWriter();
+069        pooledObject.printStackTrace(new PrintWriter(sw));
+070        return sw.toString();
+071    }
+072
+073    @Override
+074    public long getLastReturnTime() {
+075        return pooledObject.getLastReturnTime();
+076    }
+077
+078    @Override
+079    public String getLastReturnTimeFormatted() {
+080        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z");
+081        return sdf.format(Long.valueOf(pooledObject.getLastReturnTime()));
+082    }
+083
+084    @Override
+085    public String getPooledObjectType() {
+086        return pooledObject.getObject().getClass().getName();
+087    }
+088
+089    @Override
+090    public String getPooledObjectToString() {
+091        return pooledObject.getObject().toString();
+092    }
+093
+094    @Override
+095    public long getBorrowedCount() {
+096        // TODO Simplify this once getBorrowedCount has been added to PooledObject
+097        if (pooledObject instanceof DefaultPooledObject) {
+098            return ((DefaultPooledObject<?>) pooledObject).getBorrowedCount();
+099        } else {
+100            return -1;
+101        }
+102    }
+103}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ + Propchange: websites/production/commons/content/proper/commons-pool/api-2.4.1/src-html/org/apache/commons/pool2/impl/DefaultPooledObjectInfo.html ------------------------------------------------------------------------------ svn:eol-style = native Added: websites/production/commons/content/proper/commons-pool/api-2.4.1/src-html/org/apache/commons/pool2/impl/DefaultPooledObjectInfoMBean.html ============================================================================== --- websites/production/commons/content/proper/commons-pool/api-2.4.1/src-html/org/apache/commons/pool2/impl/DefaultPooledObjectInfoMBean.html (added) +++ websites/production/commons/content/proper/commons-pool/api-2.4.1/src-html/org/apache/commons/pool2/impl/DefaultPooledObjectInfoMBean.html Sun May 31 22:24:03 2015 @@ -0,0 +1,187 @@ + + + +Source code + + + +
+
001/*
+002 * Licensed to the Apache Software Foundation (ASF) under one or more
+003 * contributor license agreements.  See the NOTICE file distributed with
+004 * this work for additional information regarding copyright ownership.
+005 * The ASF licenses this file to You under the Apache License, Version 2.0
+006 * (the "License"); you may not use this file except in compliance with
+007 * the License.  You may obtain a copy of the License at
+008 *
+009 *      http://www.apache.org/licenses/LICENSE-2.0
+010 *
+011 * Unless required by applicable law or agreed to in writing, software
+012 * distributed under the License is distributed on an "AS IS" BASIS,
+013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+014 * See the License for the specific language governing permissions and
+015 * limitations under the License.
+016 */
+017package org.apache.commons.pool2.impl;
+018
+019/**
+020 * The interface that defines the information about pooled objects that will be
+021 * exposed via JMX.
+022 *
+023 * NOTE: This interface exists only to define those attributes and methods that
+024 *       will be made available via JMX. It must not be implemented by clients
+025 *       as it is subject to change between major, minor and patch version
+026 *       releases of commons pool. Clients that implement this interface may
+027 *       not, therefore, be able to upgrade to a new minor or patch release
+028 *       without requiring code changes.
+029 *
+030 * @since 2.0
+031 */
+032public interface DefaultPooledObjectInfoMBean {
+033    /**
+034     * Obtain the time (using the same basis as
+035     * {@link System#currentTimeMillis()}) that pooled object was created.
+036     *
+037     * @return The creation time for the pooled object
+038     */
+039    long getCreateTime();
+040
+041    /**
+042     * Obtain the time that pooled object was created.
+043     *
+044     * @return The creation time for the pooled object formated as
+045     *         <code>yyyy-MM-dd HH:mm:ss Z</code>
+046     */
+047    String getCreateTimeFormatted();
+048
+049    /**
+050     * Obtain the time (using the same basis as
+051     * {@link System#currentTimeMillis()}) the polled object was last borrowed.
+052     *
+053     * @return The time the pooled object was last borrowed
+054     */
+055    long getLastBorrowTime();
+056
+057    /**
+058     * Obtain the time that pooled object was last borrowed.
+059     *
+060     * @return The last borrowed time for the pooled object formated as
+061     *         <code>yyyy-MM-dd HH:mm:ss Z</code>
+062     */
+063    String getLastBorrowTimeFormatted();
+064
+065    /**
+066     * Obtain the stack trace recorded when the pooled object was last borrowed.
+067     *
+068     * @return The stack trace showing which code last borrowed the pooled
+069     *         object
+070     */
+071    String getLastBorrowTrace();
+072
+073
+074    /**
+075     * Obtain the time (using the same basis as
+076     * {@link System#currentTimeMillis()})the wrapped object was last returned.
+077     *
+078     * @return The time the object was last returned
+079     */
+080    long getLastReturnTime();
+081
+082    /**
+083     * Obtain the time that pooled object was last returned.
+084     *
+085     * @return The last returned time for the pooled object formated as
+086     *         <code>yyyy-MM-dd HH:mm:ss Z</code>
+087     */
+088    String getLastReturnTimeFormatted();
+089
+090    /**
+091     * Obtain the name of the class of the pooled object.
+092     *
+093     * @return The pooled object's class name
+094     *
+095     * @see Class#getName()
+096     */
+097    String getPooledObjectType();
+098
+099    /**
+100     * Provides a String form of the wrapper for debug purposes. The format is
+101     * not fixed and may change at any time.
+102     *
+103     * @return A string representation of the pooled object
+104     *
+105     * @see Object#toString()
+106     */
+107    String getPooledObjectToString();
+108
+109    /**
+110     * Get the number of times this object has been borrowed.
+111     * @return The number of times this object has been borrowed.
+112     * @since 2.1
+113     */
+114    long getBorrowedCount();
+115}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ + Propchange: websites/production/commons/content/proper/commons-pool/api-2.4.1/src-html/org/apache/commons/pool2/impl/DefaultPooledObjectInfoMBean.html ------------------------------------------------------------------------------ svn:eol-style = native Added: websites/production/commons/content/proper/commons-pool/api-2.4.1/src-html/org/apache/commons/pool2/impl/EvictionConfig.html ============================================================================== --- websites/production/commons/content/proper/commons-pool/api-2.4.1/src-html/org/apache/commons/pool2/impl/EvictionConfig.html (added) +++ websites/production/commons/content/proper/commons-pool/api-2.4.1/src-html/org/apache/commons/pool2/impl/EvictionConfig.html Sun May 31 22:24:03 2015 @@ -0,0 +1,173 @@ + + + +Source code + + + +
+
001/*
+002 * Licensed to the Apache Software Foundation (ASF) under one or more
+003 * contributor license agreements.  See the NOTICE file distributed with
+004 * this work for additional information regarding copyright ownership.
+005 * The ASF licenses this file to You under the Apache License, Version 2.0
+006 * (the "License"); you may not use this file except in compliance with
+007 * the License.  You may obtain a copy of the License at
+008 *
+009 *      http://www.apache.org/licenses/LICENSE-2.0
+010 *
+011 * Unless required by applicable law or agreed to in writing, software
+012 * distributed under the License is distributed on an "AS IS" BASIS,
+013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+014 * See the License for the specific language governing permissions and
+015 * limitations under the License.
+016 */
+017package org.apache.commons.pool2.impl;
+018
+019/**
+020 * This class is used by pool implementations to pass configuration information
+021 * to {@link EvictionPolicy} instances. The {@link EvictionPolicy} may also have
+022 * its own specific configuration attributes.
+023 * <p>
+024 * This class is immutable and thread-safe.
+025 *
+026 * @version $Revision: $
+027 *
+028 * @since 2.0
+029 */
+030public class EvictionConfig {
+031
+032    private final long idleEvictTime;
+033    private final long idleSoftEvictTime;
+034    private final int minIdle;
+035
+036
+037    /**
+038     * Create a new eviction configuration with the specified parameters.
+039     * Instances are immutable.
+040     *
+041     * @param poolIdleEvictTime Expected to be provided by
+042     *        {@link BaseGenericObjectPool#getMinEvictableIdleTimeMillis()}
+043     * @param poolIdleSoftEvictTime Expected to be provided by
+044     *        {@link BaseGenericObjectPool#getSoftMinEvictableIdleTimeMillis()}
+045     * @param minIdle Expected to be provided by
+046     *        {@link GenericObjectPool#getMinIdle()} or
+047     *        {@link GenericKeyedObjectPool#getMinIdlePerKey()}
+048     */
+049    public EvictionConfig(long poolIdleEvictTime, long poolIdleSoftEvictTime,
+050            int minIdle) {
+051        if (poolIdleEvictTime > 0) {
+052            idleEvictTime = poolIdleEvictTime;
+053        } else {
+054            idleEvictTime = Long.MAX_VALUE;
+055        }
+056        if (poolIdleSoftEvictTime > 0) {
+057            idleSoftEvictTime = poolIdleSoftEvictTime;
+058        } else {
+059            idleSoftEvictTime  = Long.MAX_VALUE;
+060        }
+061        this.minIdle = minIdle;
+062    }
+063
+064    /**
+065     * Obtain the {@code idleEvictTime} for this eviction configuration
+066     * instance.
+067     * <p>
+068     * How the evictor behaves based on this value will be determined by the
+069     * configured {@link EvictionPolicy}.
+070     *
+071     * @return The {@code idleEvictTime} in milliseconds
+072     */
+073    public long getIdleEvictTime() {
+074        return idleEvictTime;
+075    }
+076
+077    /**
+078     * Obtain the {@code idleSoftEvictTime} for this eviction configuration
+079     * instance.
+080     * <p>
+081     * How the evictor behaves based on this value will be determined by the
+082     * configured {@link EvictionPolicy}.
+083     *
+084     * @return The (@code idleSoftEvictTime} in milliseconds
+085     */
+086    public long getIdleSoftEvictTime() {
+087        return idleSoftEvictTime;
+088    }
+089
+090    /**
+091     * Obtain the {@code minIdle} for this eviction configuration instance.
+092     * <p>
+093     * How the evictor behaves based on this value will be determined by the
+094     * configured {@link EvictionPolicy}.
+095     *
+096     * @return The {@code minIdle}
+097     */
+098    public int getMinIdle() {
+099        return minIdle;
+100    }
+101}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ + Propchange: websites/production/commons/content/proper/commons-pool/api-2.4.1/src-html/org/apache/commons/pool2/impl/EvictionConfig.html ------------------------------------------------------------------------------ svn:eol-style = native Added: websites/production/commons/content/proper/commons-pool/api-2.4.1/src-html/org/apache/commons/pool2/impl/EvictionPolicy.html ============================================================================== --- websites/production/commons/content/proper/commons-pool/api-2.4.1/src-html/org/apache/commons/pool2/impl/EvictionPolicy.html (added) +++ websites/production/commons/content/proper/commons-pool/api-2.4.1/src-html/org/apache/commons/pool2/impl/EvictionPolicy.html Sun May 31 22:24:03 2015 @@ -0,0 +1,119 @@ + + + +Source code + + + +
+
001/*
+002 * Licensed to the Apache Software Foundation (ASF) under one or more
+003 * contributor license agreements.  See the NOTICE file distributed with
+004 * this work for additional information regarding copyright ownership.
+005 * The ASF licenses this file to You under the Apache License, Version 2.0
+006 * (the "License"); you may not use this file except in compliance with
+007 * the License.  You may obtain a copy of the License at
+008 *
+009 *      http://www.apache.org/licenses/LICENSE-2.0
+010 *
+011 * Unless required by applicable law or agreed to in writing, software
+012 * distributed under the License is distributed on an "AS IS" BASIS,
+013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+014 * See the License for the specific language governing permissions and
+015 * limitations under the License.
+016 */
+017package org.apache.commons.pool2.impl;
+018
+019import org.apache.commons.pool2.PooledObject;
+020
+021/**
+022 * To provide a custom eviction policy (i.e. something other than {@link
+023 * DefaultEvictionPolicy} for a pool, users must provide an implementation of
+024 * this interface that provides the required eviction policy.
+025 *
+026 * @param <T> the type of objects in the pool
+027 *
+028 * @version $Revision: $
+029 *
+030 * @since 2.0
+031 */
+032public interface EvictionPolicy<T> {
+033
+034    /**
+035     * This method is called to test if an idle object in the pool should be
+036     * evicted or not.
+037     *
+038     * @param config    The pool configuration settings related to eviction
+039     * @param underTest The pooled object being tested for eviction
+040     * @param idleCount The current number of idle objects in the pool including
+041     *                      the object under test
+042     * @return <code>true</code> if the object should be evicted, otherwise
+043     *             <code>false</code>
+044     */
+045    boolean evict(EvictionConfig config, PooledObject<T> underTest,
+046            int idleCount);
+047}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ + Propchange: websites/production/commons/content/proper/commons-pool/api-2.4.1/src-html/org/apache/commons/pool2/impl/EvictionPolicy.html ------------------------------------------------------------------------------ svn:eol-style = native