1 /* 2 * ==================================================================== 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * ==================================================================== 20 * 21 * This software consists of voluntary contributions made by many 22 * individuals on behalf of the Apache Software Foundation. For more 23 * information on the Apache Software Foundation, please see 24 * <http://www.apache.org/>. 25 * 26 */ 27 package org.apache.http.conn.params; 28 29 import org.apache.http.annotation.Contract; 30 import org.apache.http.annotation.ThreadingBehavior; 31 import org.apache.http.conn.routing.HttpRoute; 32 import org.apache.http.params.HttpParams; 33 import org.apache.http.util.Args; 34 35 /** 36 * An adaptor for manipulating HTTP connection management 37 * parameters in {@link HttpParams}. 38 * 39 * @since 4.0 40 * 41 * @see ConnManagerPNames 42 * 43 * @deprecated (4.1) use configuration methods of the specific connection manager implementation. 44 */ 45 @Deprecated 46 @Contract(threading = ThreadingBehavior.IMMUTABLE) 47 public final class ConnManagerParams implements ConnManagerPNames { 48 49 /** The default maximum number of connections allowed overall */ 50 public static final int DEFAULT_MAX_TOTAL_CONNECTIONS = 20; 51 52 /** 53 * Returns the timeout in milliseconds used when retrieving a 54 * {@link org.apache.http.conn.ManagedClientConnection} from the 55 * {@link org.apache.http.conn.ClientConnectionManager}. 56 * 57 * @return timeout in milliseconds. 58 * 59 * @deprecated (4.1) use {@link 60 * org.apache.http.params.HttpConnectionParams#getConnectionTimeout(HttpParams)} 61 */ 62 @Deprecated 63 public static long getTimeout(final HttpParams params) { 64 Args.notNull(params, "HTTP parameters"); 65 return params.getLongParameter(TIMEOUT, 0); 66 } 67 68 /** 69 * Sets the timeout in milliseconds used when retrieving a 70 * {@link org.apache.http.conn.ManagedClientConnection} from the 71 * {@link org.apache.http.conn.ClientConnectionManager}. 72 * 73 * @param timeout the timeout in milliseconds 74 * 75 * @deprecated (4.1) use {@link 76 * org.apache.http.params.HttpConnectionParams#setConnectionTimeout(HttpParams, int)} 77 */ 78 @Deprecated 79 public static void setTimeout(final HttpParams params, final long timeout) { 80 Args.notNull(params, "HTTP parameters"); 81 params.setLongParameter(TIMEOUT, timeout); 82 } 83 84 /** The default maximum number of connections allowed per host */ 85 private static final ConnPerRouteonnPerRoute">ConnPerRoute DEFAULT_CONN_PER_ROUTE = new ConnPerRoute() { 86 87 @Override 88 public int getMaxForRoute(final HttpRoute route) { 89 return ConnPerRouteBean.DEFAULT_MAX_CONNECTIONS_PER_ROUTE; 90 } 91 92 }; 93 94 /** 95 * Sets lookup interface for maximum number of connections allowed per route. 96 * 97 * @param params HTTP parameters 98 * @param connPerRoute lookup interface for maximum number of connections allowed 99 * per route 100 */ 101 public static void setMaxConnectionsPerRoute(final HttpParams params, 102 final ConnPerRoute connPerRoute) { 103 Args.notNull(params, "HTTP parameters"); 104 params.setParameter(MAX_CONNECTIONS_PER_ROUTE, connPerRoute); 105 } 106 107 /** 108 * Returns lookup interface for maximum number of connections allowed per route. 109 * 110 * @param params HTTP parameters 111 * 112 * @return lookup interface for maximum number of connections allowed per route. 113 */ 114 public static ConnPerRoute getMaxConnectionsPerRoute(final HttpParams params) { 115 Args.notNull(params, "HTTP parameters"); 116 ConnPerRoute../org/apache/http/conn/params/ConnPerRoute.html#ConnPerRoute">ConnPerRoute connPerRoute = (ConnPerRoute) params.getParameter(MAX_CONNECTIONS_PER_ROUTE); 117 if (connPerRoute == null) { 118 connPerRoute = DEFAULT_CONN_PER_ROUTE; 119 } 120 return connPerRoute; 121 } 122 123 /** 124 * Sets the maximum number of connections allowed. 125 * 126 * @param params HTTP parameters 127 * @param maxTotalConnections The maximum number of connections allowed. 128 */ 129 public static void setMaxTotalConnections( 130 final HttpParams params, 131 final int maxTotalConnections) { 132 Args.notNull(params, "HTTP parameters"); 133 params.setIntParameter(MAX_TOTAL_CONNECTIONS, maxTotalConnections); 134 } 135 136 /** 137 * Gets the maximum number of connections allowed. 138 * 139 * @param params HTTP parameters 140 * 141 * @return The maximum number of connections allowed. 142 */ 143 public static int getMaxTotalConnections( 144 final HttpParams params) { 145 Args.notNull(params, "HTTP parameters"); 146 return params.getIntParameter(MAX_TOTAL_CONNECTIONS, DEFAULT_MAX_TOTAL_CONNECTIONS); 147 } 148 149 }