1/* 2 * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/params/ConnPerRouteBean.java $ 3 * $Revision: 652947 $ 4 * $Date: 2008-05-02 16:15:40 -0700 (Fri, 02 May 2008) $ 5 * 6 * ==================================================================== 7 * 8 * Licensed to the Apache Software Foundation (ASF) under one or more 9 * contributor license agreements. See the NOTICE file distributed with 10 * this work for additional information regarding copyright ownership. 11 * The ASF licenses this file to You under the Apache License, Version 2.0 12 * (the "License"); you may not use this file except in compliance with 13 * the License. You may obtain a copy of the License at 14 * 15 * http://www.apache.org/licenses/LICENSE-2.0 16 * 17 * Unless required by applicable law or agreed to in writing, software 18 * distributed under the License is distributed on an "AS IS" BASIS, 19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 * See the License for the specific language governing permissions and 21 * limitations under the License. 22 * ==================================================================== 23 * 24 * This software consists of voluntary contributions made by many 25 * individuals on behalf of the Apache Software Foundation. For more 26 * information on the Apache Software Foundation, please see 27 * <http://www.apache.org/>. 28 * 29 */ 30 31package org.apache.http.conn.params; 32 33import java.util.HashMap; 34import java.util.Map; 35 36import org.apache.http.conn.routing.HttpRoute; 37 38/** 39 * This class maintains a map of HTTP routes to maximum number of connections allowed 40 * for those routes. This class can be used by pooling 41 * {@link org.apache.http.conn.ClientConnectionManager connection managers} for 42 * a fine-grained control of connections on a per route basis. 43 * 44 * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a> 45 * 46 * @version $Revision: 652947 $ 47 * 48 * @since 4.0 49 * 50 * @deprecated Please use {@link java.net.URL#openConnection} instead. 51 * Please visit <a href="http://android-developers.blogspot.com/2011/09/androids-http-clients.html">this webpage</a> 52 * for further details. 53 */ 54@Deprecated 55public final class ConnPerRouteBean implements ConnPerRoute { 56 57 /** The default maximum number of connections allowed per host */ 58 public static final int DEFAULT_MAX_CONNECTIONS_PER_ROUTE = 2; // Per RFC 2616 sec 8.1.4 59 60 private final Map<HttpRoute, Integer> maxPerHostMap; 61 62 private int defaultMax; 63 64 public ConnPerRouteBean(int defaultMax) { 65 super(); 66 this.maxPerHostMap = new HashMap<HttpRoute, Integer>(); 67 setDefaultMaxPerRoute(defaultMax); 68 } 69 70 public ConnPerRouteBean() { 71 this(DEFAULT_MAX_CONNECTIONS_PER_ROUTE); 72 } 73 74 public int getDefaultMax() { 75 return this.defaultMax; 76 } 77 78 public void setDefaultMaxPerRoute(int max) { 79 if (max < 1) { 80 throw new IllegalArgumentException 81 ("The maximum must be greater than 0."); 82 } 83 this.defaultMax = max; 84 } 85 86 public void setMaxForRoute(final HttpRoute route, int max) { 87 if (route == null) { 88 throw new IllegalArgumentException 89 ("HTTP route may not be null."); 90 } 91 if (max < 1) { 92 throw new IllegalArgumentException 93 ("The maximum must be greater than 0."); 94 } 95 this.maxPerHostMap.put(route, Integer.valueOf(max)); 96 } 97 98 public int getMaxForRoute(final HttpRoute route) { 99 if (route == null) { 100 throw new IllegalArgumentException 101 ("HTTP route may not be null."); 102 } 103 Integer max = this.maxPerHostMap.get(route); 104 if (max != null) { 105 return max.intValue(); 106 } else { 107 return this.defaultMax; 108 } 109 } 110 111 public void setMaxForRoutes(final Map<HttpRoute, Integer> map) { 112 if (map == null) { 113 return; 114 } 115 this.maxPerHostMap.clear(); 116 this.maxPerHostMap.putAll(map); 117 } 118 119} 120