Wed, 31 Dec 2014 07:22:50 +0100
Correct previous dual key logic pending first delivery installment.
michael@0 | 1 | /* |
michael@0 | 2 | * ==================================================================== |
michael@0 | 3 | * |
michael@0 | 4 | * Licensed to the Apache Software Foundation (ASF) under one or more |
michael@0 | 5 | * contributor license agreements. See the NOTICE file distributed with |
michael@0 | 6 | * this work for additional information regarding copyright ownership. |
michael@0 | 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
michael@0 | 8 | * (the "License"); you may not use this file except in compliance with |
michael@0 | 9 | * the License. You may obtain a copy of the License at |
michael@0 | 10 | * |
michael@0 | 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
michael@0 | 12 | * |
michael@0 | 13 | * Unless required by applicable law or agreed to in writing, software |
michael@0 | 14 | * distributed under the License is distributed on an "AS IS" BASIS, |
michael@0 | 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
michael@0 | 16 | * See the License for the specific language governing permissions and |
michael@0 | 17 | * limitations under the License. |
michael@0 | 18 | * ==================================================================== |
michael@0 | 19 | * |
michael@0 | 20 | * This software consists of voluntary contributions made by many |
michael@0 | 21 | * individuals on behalf of the Apache Software Foundation. For more |
michael@0 | 22 | * information on the Apache Software Foundation, please see |
michael@0 | 23 | * <http://www.apache.org/>. |
michael@0 | 24 | * |
michael@0 | 25 | */ |
michael@0 | 26 | |
michael@0 | 27 | package ch.boye.httpclientandroidlib.conn.params; |
michael@0 | 28 | |
michael@0 | 29 | import ch.boye.httpclientandroidlib.annotation.Immutable; |
michael@0 | 30 | |
michael@0 | 31 | import ch.boye.httpclientandroidlib.conn.routing.HttpRoute; |
michael@0 | 32 | import ch.boye.httpclientandroidlib.impl.conn.tsccm.ThreadSafeClientConnManager; |
michael@0 | 33 | import ch.boye.httpclientandroidlib.params.CoreConnectionPNames; |
michael@0 | 34 | import ch.boye.httpclientandroidlib.params.HttpConnectionParams; |
michael@0 | 35 | import ch.boye.httpclientandroidlib.params.HttpParams; |
michael@0 | 36 | |
michael@0 | 37 | /** |
michael@0 | 38 | * An adaptor for manipulating HTTP connection management |
michael@0 | 39 | * parameters in {@link HttpParams}. |
michael@0 | 40 | * |
michael@0 | 41 | * @since 4.0 |
michael@0 | 42 | * |
michael@0 | 43 | * @see ConnManagerPNames |
michael@0 | 44 | * @deprecated replaced by methods in {@link HttpConnectionParams} and {@link ThreadSafeClientConnManager}. |
michael@0 | 45 | * See individual method descriptions for details |
michael@0 | 46 | */ |
michael@0 | 47 | @Deprecated |
michael@0 | 48 | @Immutable |
michael@0 | 49 | public final class ConnManagerParams implements ConnManagerPNames { |
michael@0 | 50 | |
michael@0 | 51 | /** The default maximum number of connections allowed overall */ |
michael@0 | 52 | public static final int DEFAULT_MAX_TOTAL_CONNECTIONS = 20; |
michael@0 | 53 | |
michael@0 | 54 | /** |
michael@0 | 55 | * Returns the timeout in milliseconds used when retrieving a |
michael@0 | 56 | * {@link ch.boye.httpclientandroidlib.conn.ManagedClientConnection} from the |
michael@0 | 57 | * {@link ch.boye.httpclientandroidlib.conn.ClientConnectionManager}. |
michael@0 | 58 | * |
michael@0 | 59 | * @return timeout in milliseconds. |
michael@0 | 60 | * |
michael@0 | 61 | * @deprecated use {@link HttpConnectionParams#getConnectionTimeout(HttpParams)} |
michael@0 | 62 | */ |
michael@0 | 63 | @Deprecated |
michael@0 | 64 | public static long getTimeout(final HttpParams params) { |
michael@0 | 65 | if (params == null) { |
michael@0 | 66 | throw new IllegalArgumentException("HTTP parameters may not be null"); |
michael@0 | 67 | } |
michael@0 | 68 | Long param = (Long) params.getParameter(TIMEOUT); |
michael@0 | 69 | if (param != null) { |
michael@0 | 70 | return param.longValue(); |
michael@0 | 71 | } |
michael@0 | 72 | return params.getIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 0); |
michael@0 | 73 | } |
michael@0 | 74 | |
michael@0 | 75 | /** |
michael@0 | 76 | * Sets the timeout in milliseconds used when retrieving a |
michael@0 | 77 | * {@link ch.boye.httpclientandroidlib.conn.ManagedClientConnection} from the |
michael@0 | 78 | * {@link ch.boye.httpclientandroidlib.conn.ClientConnectionManager}. |
michael@0 | 79 | * |
michael@0 | 80 | * @param timeout the timeout in milliseconds |
michael@0 | 81 | * |
michael@0 | 82 | * @deprecated use {@link HttpConnectionParams#setConnectionTimeout(HttpParams, int)} |
michael@0 | 83 | */ |
michael@0 | 84 | @Deprecated |
michael@0 | 85 | public static void setTimeout(final HttpParams params, long timeout) { |
michael@0 | 86 | if (params == null) { |
michael@0 | 87 | throw new IllegalArgumentException("HTTP parameters may not be null"); |
michael@0 | 88 | } |
michael@0 | 89 | params.setLongParameter(TIMEOUT, timeout); |
michael@0 | 90 | } |
michael@0 | 91 | |
michael@0 | 92 | /** The default maximum number of connections allowed per host */ |
michael@0 | 93 | private static final ConnPerRoute DEFAULT_CONN_PER_ROUTE = new ConnPerRoute() { |
michael@0 | 94 | |
michael@0 | 95 | public int getMaxForRoute(HttpRoute route) { |
michael@0 | 96 | return ConnPerRouteBean.DEFAULT_MAX_CONNECTIONS_PER_ROUTE; |
michael@0 | 97 | } |
michael@0 | 98 | |
michael@0 | 99 | }; |
michael@0 | 100 | |
michael@0 | 101 | /** |
michael@0 | 102 | * Sets lookup interface for maximum number of connections allowed per route. |
michael@0 | 103 | * |
michael@0 | 104 | * @param params HTTP parameters |
michael@0 | 105 | * @param connPerRoute lookup interface for maximum number of connections allowed |
michael@0 | 106 | * per route |
michael@0 | 107 | * |
michael@0 | 108 | * @deprecated use {@link ThreadSafeClientConnManager#setMaxForRoute(ch.boye.httpclientandroidlib.conn.routing.HttpRoute, int)} |
michael@0 | 109 | */ |
michael@0 | 110 | @Deprecated |
michael@0 | 111 | public static void setMaxConnectionsPerRoute(final HttpParams params, |
michael@0 | 112 | final ConnPerRoute connPerRoute) { |
michael@0 | 113 | if (params == null) { |
michael@0 | 114 | throw new IllegalArgumentException |
michael@0 | 115 | ("HTTP parameters must not be null."); |
michael@0 | 116 | } |
michael@0 | 117 | params.setParameter(MAX_CONNECTIONS_PER_ROUTE, connPerRoute); |
michael@0 | 118 | } |
michael@0 | 119 | |
michael@0 | 120 | /** |
michael@0 | 121 | * Returns lookup interface for maximum number of connections allowed per route. |
michael@0 | 122 | * |
michael@0 | 123 | * @param params HTTP parameters |
michael@0 | 124 | * |
michael@0 | 125 | * @return lookup interface for maximum number of connections allowed per route. |
michael@0 | 126 | * |
michael@0 | 127 | * @deprecated use {@link ThreadSafeClientConnManager#getMaxForRoute(ch.boye.httpclientandroidlib.conn.routing.HttpRoute)} |
michael@0 | 128 | */ |
michael@0 | 129 | @Deprecated |
michael@0 | 130 | public static ConnPerRoute getMaxConnectionsPerRoute(final HttpParams params) { |
michael@0 | 131 | if (params == null) { |
michael@0 | 132 | throw new IllegalArgumentException |
michael@0 | 133 | ("HTTP parameters must not be null."); |
michael@0 | 134 | } |
michael@0 | 135 | ConnPerRoute connPerRoute = (ConnPerRoute) params.getParameter(MAX_CONNECTIONS_PER_ROUTE); |
michael@0 | 136 | if (connPerRoute == null) { |
michael@0 | 137 | connPerRoute = DEFAULT_CONN_PER_ROUTE; |
michael@0 | 138 | } |
michael@0 | 139 | return connPerRoute; |
michael@0 | 140 | } |
michael@0 | 141 | |
michael@0 | 142 | /** |
michael@0 | 143 | * Sets the maximum number of connections allowed. |
michael@0 | 144 | * |
michael@0 | 145 | * @param params HTTP parameters |
michael@0 | 146 | * @param maxTotalConnections The maximum number of connections allowed. |
michael@0 | 147 | * |
michael@0 | 148 | * @deprecated use {@link ThreadSafeClientConnManager#setMaxTotal(int)} |
michael@0 | 149 | */ |
michael@0 | 150 | @Deprecated |
michael@0 | 151 | public static void setMaxTotalConnections( |
michael@0 | 152 | final HttpParams params, |
michael@0 | 153 | int maxTotalConnections) { |
michael@0 | 154 | if (params == null) { |
michael@0 | 155 | throw new IllegalArgumentException |
michael@0 | 156 | ("HTTP parameters must not be null."); |
michael@0 | 157 | } |
michael@0 | 158 | params.setIntParameter(MAX_TOTAL_CONNECTIONS, maxTotalConnections); |
michael@0 | 159 | } |
michael@0 | 160 | |
michael@0 | 161 | /** |
michael@0 | 162 | * Gets the maximum number of connections allowed. |
michael@0 | 163 | * |
michael@0 | 164 | * @param params HTTP parameters |
michael@0 | 165 | * |
michael@0 | 166 | * @return The maximum number of connections allowed. |
michael@0 | 167 | * |
michael@0 | 168 | * @deprecated use {@link ThreadSafeClientConnManager#getMaxTotal()} |
michael@0 | 169 | */ |
michael@0 | 170 | @Deprecated |
michael@0 | 171 | public static int getMaxTotalConnections( |
michael@0 | 172 | final HttpParams params) { |
michael@0 | 173 | if (params == null) { |
michael@0 | 174 | throw new IllegalArgumentException |
michael@0 | 175 | ("HTTP parameters must not be null."); |
michael@0 | 176 | } |
michael@0 | 177 | return params.getIntParameter(MAX_TOTAL_CONNECTIONS, DEFAULT_MAX_TOTAL_CONNECTIONS); |
michael@0 | 178 | } |
michael@0 | 179 | |
michael@0 | 180 | } |