mobile/android/thirdparty/ch/boye/httpclientandroidlib/impl/conn/tsccm/BasicPoolEntry.java

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mobile/android/thirdparty/ch/boye/httpclientandroidlib/impl/conn/tsccm/BasicPoolEntry.java	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,170 @@
     1.4 +/*
     1.5 + * ====================================================================
     1.6 + *
     1.7 + *  Licensed to the Apache Software Foundation (ASF) under one or more
     1.8 + *  contributor license agreements.  See the NOTICE file distributed with
     1.9 + *  this work for additional information regarding copyright ownership.
    1.10 + *  The ASF licenses this file to You under the Apache License, Version 2.0
    1.11 + *  (the "License"); you may not use this file except in compliance with
    1.12 + *  the License.  You may obtain a copy of the License at
    1.13 + *
    1.14 + *      http://www.apache.org/licenses/LICENSE-2.0
    1.15 + *
    1.16 + *  Unless required by applicable law or agreed to in writing, software
    1.17 + *  distributed under the License is distributed on an "AS IS" BASIS,
    1.18 + *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    1.19 + *  See the License for the specific language governing permissions and
    1.20 + *  limitations under the License.
    1.21 + * ====================================================================
    1.22 + *
    1.23 + * This software consists of voluntary contributions made by many
    1.24 + * individuals on behalf of the Apache Software Foundation.  For more
    1.25 + * information on the Apache Software Foundation, please see
    1.26 + * <http://www.apache.org/>.
    1.27 + *
    1.28 + */
    1.29 +
    1.30 +package ch.boye.httpclientandroidlib.impl.conn.tsccm;
    1.31 +
    1.32 +import java.lang.ref.ReferenceQueue;
    1.33 +import java.util.concurrent.TimeUnit;
    1.34 +
    1.35 +import ch.boye.httpclientandroidlib.annotation.NotThreadSafe;
    1.36 +import ch.boye.httpclientandroidlib.conn.OperatedClientConnection;
    1.37 +import ch.boye.httpclientandroidlib.conn.ClientConnectionOperator;
    1.38 +import ch.boye.httpclientandroidlib.conn.routing.HttpRoute;
    1.39 +import ch.boye.httpclientandroidlib.impl.conn.AbstractPoolEntry;
    1.40 +
    1.41 +/**
    1.42 + * Basic implementation of a connection pool entry.
    1.43 + *
    1.44 + * @since 4.0
    1.45 + */
    1.46 +@NotThreadSafe
    1.47 +public class BasicPoolEntry extends AbstractPoolEntry {
    1.48 +
    1.49 +    private final long created;
    1.50 +
    1.51 +    private long updated;
    1.52 +    private long validUntil;
    1.53 +    private long expiry;
    1.54 +
    1.55 +    /**
    1.56 +     * @deprecated do not use
    1.57 +     */
    1.58 +    @Deprecated
    1.59 +    public BasicPoolEntry(ClientConnectionOperator op,
    1.60 +                          HttpRoute route,
    1.61 +                          ReferenceQueue<Object> queue) {
    1.62 +        super(op, route);
    1.63 +        if (route == null) {
    1.64 +            throw new IllegalArgumentException("HTTP route may not be null");
    1.65 +        }
    1.66 +        this.created = System.currentTimeMillis();
    1.67 +        this.validUntil = Long.MAX_VALUE;
    1.68 +        this.expiry = this.validUntil;
    1.69 +    }
    1.70 +
    1.71 +    /**
    1.72 +     * Creates a new pool entry.
    1.73 +     *
    1.74 +     * @param op      the connection operator
    1.75 +     * @param route   the planned route for the connection
    1.76 +     */
    1.77 +    public BasicPoolEntry(ClientConnectionOperator op,
    1.78 +                          HttpRoute route) {
    1.79 +        this(op, route, -1, TimeUnit.MILLISECONDS);
    1.80 +    }
    1.81 +
    1.82 +    /**
    1.83 +     * Creates a new pool entry with a specified maximum lifetime.
    1.84 +     *
    1.85 +     * @param op        the connection operator
    1.86 +     * @param route     the planned route for the connection
    1.87 +     * @param connTTL   maximum lifetime of this entry, <=0 implies "infinity"
    1.88 +     * @param timeunit  TimeUnit of connTTL
    1.89 +     *
    1.90 +     * @since 4.1
    1.91 +     */
    1.92 +    public BasicPoolEntry(ClientConnectionOperator op,
    1.93 +                          HttpRoute route, long connTTL, TimeUnit timeunit) {
    1.94 +        super(op, route);
    1.95 +        if (route == null) {
    1.96 +            throw new IllegalArgumentException("HTTP route may not be null");
    1.97 +        }
    1.98 +        this.created = System.currentTimeMillis();
    1.99 +        if (connTTL > 0) {
   1.100 +            this.validUntil = this.created + timeunit.toMillis(connTTL);
   1.101 +        } else {
   1.102 +            this.validUntil = Long.MAX_VALUE;
   1.103 +        }
   1.104 +        this.expiry = this.validUntil;
   1.105 +    }
   1.106 +
   1.107 +    protected final OperatedClientConnection getConnection() {
   1.108 +        return super.connection;
   1.109 +    }
   1.110 +
   1.111 +    protected final HttpRoute getPlannedRoute() {
   1.112 +        return super.route;
   1.113 +    }
   1.114 +
   1.115 +    @Deprecated
   1.116 +    protected final BasicPoolEntryRef getWeakRef() {
   1.117 +        return null;
   1.118 +    }
   1.119 +
   1.120 +    @Override
   1.121 +    protected void shutdownEntry() {
   1.122 +        super.shutdownEntry();
   1.123 +    }
   1.124 +
   1.125 +    /**
   1.126 +     * @since 4.1
   1.127 +     */
   1.128 +    public long getCreated() {
   1.129 +        return this.created;
   1.130 +    }
   1.131 +
   1.132 +    /**
   1.133 +     * @since 4.1
   1.134 +     */
   1.135 +    public long getUpdated() {
   1.136 +        return this.updated;
   1.137 +    }
   1.138 +
   1.139 +    /**
   1.140 +     * @since 4.1
   1.141 +     */
   1.142 +    public long getExpiry() {
   1.143 +        return this.expiry;
   1.144 +    }
   1.145 +
   1.146 +    public long getValidUntil() {
   1.147 +        return this.validUntil;
   1.148 +    }
   1.149 +
   1.150 +    /**
   1.151 +     * @since 4.1
   1.152 +     */
   1.153 +    public void updateExpiry(long time, TimeUnit timeunit) {
   1.154 +        this.updated = System.currentTimeMillis();
   1.155 +        long newExpiry;
   1.156 +        if (time > 0) {
   1.157 +            newExpiry = this.updated + timeunit.toMillis(time);
   1.158 +        } else {
   1.159 +            newExpiry = Long.MAX_VALUE;
   1.160 +        }
   1.161 +        this.expiry = Math.min(validUntil, newExpiry);
   1.162 +    }
   1.163 +
   1.164 +    /**
   1.165 +     * @since 4.1
   1.166 +     */
   1.167 +    public boolean isExpired(long now) {
   1.168 +        return now >= this.expiry;
   1.169 +    }
   1.170 +
   1.171 +}
   1.172 +
   1.173 +

mercurial