michael@0: /* michael@0: * ==================================================================== michael@0: * michael@0: * Licensed to the Apache Software Foundation (ASF) under one or more michael@0: * contributor license agreements. See the NOTICE file distributed with michael@0: * this work for additional information regarding copyright ownership. michael@0: * The ASF licenses this file to You under the Apache License, Version 2.0 michael@0: * (the "License"); you may not use this file except in compliance with michael@0: * the License. You may obtain a copy of the License at michael@0: * michael@0: * http://www.apache.org/licenses/LICENSE-2.0 michael@0: * michael@0: * Unless required by applicable law or agreed to in writing, software michael@0: * distributed under the License is distributed on an "AS IS" BASIS, michael@0: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. michael@0: * See the License for the specific language governing permissions and michael@0: * limitations under the License. michael@0: * ==================================================================== michael@0: * michael@0: * This software consists of voluntary contributions made by many michael@0: * individuals on behalf of the Apache Software Foundation. For more michael@0: * information on the Apache Software Foundation, please see michael@0: * . michael@0: * michael@0: */ michael@0: michael@0: package ch.boye.httpclientandroidlib.conn.params; michael@0: michael@0: import ch.boye.httpclientandroidlib.annotation.Immutable; michael@0: michael@0: import ch.boye.httpclientandroidlib.conn.routing.HttpRoute; michael@0: import ch.boye.httpclientandroidlib.impl.conn.tsccm.ThreadSafeClientConnManager; michael@0: import ch.boye.httpclientandroidlib.params.CoreConnectionPNames; michael@0: import ch.boye.httpclientandroidlib.params.HttpConnectionParams; michael@0: import ch.boye.httpclientandroidlib.params.HttpParams; michael@0: michael@0: /** michael@0: * An adaptor for manipulating HTTP connection management michael@0: * parameters in {@link HttpParams}. michael@0: * michael@0: * @since 4.0 michael@0: * michael@0: * @see ConnManagerPNames michael@0: * @deprecated replaced by methods in {@link HttpConnectionParams} and {@link ThreadSafeClientConnManager}. michael@0: * See individual method descriptions for details michael@0: */ michael@0: @Deprecated michael@0: @Immutable michael@0: public final class ConnManagerParams implements ConnManagerPNames { michael@0: michael@0: /** The default maximum number of connections allowed overall */ michael@0: public static final int DEFAULT_MAX_TOTAL_CONNECTIONS = 20; michael@0: michael@0: /** michael@0: * Returns the timeout in milliseconds used when retrieving a michael@0: * {@link ch.boye.httpclientandroidlib.conn.ManagedClientConnection} from the michael@0: * {@link ch.boye.httpclientandroidlib.conn.ClientConnectionManager}. michael@0: * michael@0: * @return timeout in milliseconds. michael@0: * michael@0: * @deprecated use {@link HttpConnectionParams#getConnectionTimeout(HttpParams)} michael@0: */ michael@0: @Deprecated michael@0: public static long getTimeout(final HttpParams params) { michael@0: if (params == null) { michael@0: throw new IllegalArgumentException("HTTP parameters may not be null"); michael@0: } michael@0: Long param = (Long) params.getParameter(TIMEOUT); michael@0: if (param != null) { michael@0: return param.longValue(); michael@0: } michael@0: return params.getIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 0); michael@0: } michael@0: michael@0: /** michael@0: * Sets the timeout in milliseconds used when retrieving a michael@0: * {@link ch.boye.httpclientandroidlib.conn.ManagedClientConnection} from the michael@0: * {@link ch.boye.httpclientandroidlib.conn.ClientConnectionManager}. michael@0: * michael@0: * @param timeout the timeout in milliseconds michael@0: * michael@0: * @deprecated use {@link HttpConnectionParams#setConnectionTimeout(HttpParams, int)} michael@0: */ michael@0: @Deprecated michael@0: public static void setTimeout(final HttpParams params, long timeout) { michael@0: if (params == null) { michael@0: throw new IllegalArgumentException("HTTP parameters may not be null"); michael@0: } michael@0: params.setLongParameter(TIMEOUT, timeout); michael@0: } michael@0: michael@0: /** The default maximum number of connections allowed per host */ michael@0: private static final ConnPerRoute DEFAULT_CONN_PER_ROUTE = new ConnPerRoute() { michael@0: michael@0: public int getMaxForRoute(HttpRoute route) { michael@0: return ConnPerRouteBean.DEFAULT_MAX_CONNECTIONS_PER_ROUTE; michael@0: } michael@0: michael@0: }; michael@0: michael@0: /** michael@0: * Sets lookup interface for maximum number of connections allowed per route. michael@0: * michael@0: * @param params HTTP parameters michael@0: * @param connPerRoute lookup interface for maximum number of connections allowed michael@0: * per route michael@0: * michael@0: * @deprecated use {@link ThreadSafeClientConnManager#setMaxForRoute(ch.boye.httpclientandroidlib.conn.routing.HttpRoute, int)} michael@0: */ michael@0: @Deprecated michael@0: public static void setMaxConnectionsPerRoute(final HttpParams params, michael@0: final ConnPerRoute connPerRoute) { michael@0: if (params == null) { michael@0: throw new IllegalArgumentException michael@0: ("HTTP parameters must not be null."); michael@0: } michael@0: params.setParameter(MAX_CONNECTIONS_PER_ROUTE, connPerRoute); michael@0: } michael@0: michael@0: /** michael@0: * Returns lookup interface for maximum number of connections allowed per route. michael@0: * michael@0: * @param params HTTP parameters michael@0: * michael@0: * @return lookup interface for maximum number of connections allowed per route. michael@0: * michael@0: * @deprecated use {@link ThreadSafeClientConnManager#getMaxForRoute(ch.boye.httpclientandroidlib.conn.routing.HttpRoute)} michael@0: */ michael@0: @Deprecated michael@0: public static ConnPerRoute getMaxConnectionsPerRoute(final HttpParams params) { michael@0: if (params == null) { michael@0: throw new IllegalArgumentException michael@0: ("HTTP parameters must not be null."); michael@0: } michael@0: ConnPerRoute connPerRoute = (ConnPerRoute) params.getParameter(MAX_CONNECTIONS_PER_ROUTE); michael@0: if (connPerRoute == null) { michael@0: connPerRoute = DEFAULT_CONN_PER_ROUTE; michael@0: } michael@0: return connPerRoute; michael@0: } michael@0: michael@0: /** michael@0: * Sets the maximum number of connections allowed. michael@0: * michael@0: * @param params HTTP parameters michael@0: * @param maxTotalConnections The maximum number of connections allowed. michael@0: * michael@0: * @deprecated use {@link ThreadSafeClientConnManager#setMaxTotal(int)} michael@0: */ michael@0: @Deprecated michael@0: public static void setMaxTotalConnections( michael@0: final HttpParams params, michael@0: int maxTotalConnections) { michael@0: if (params == null) { michael@0: throw new IllegalArgumentException michael@0: ("HTTP parameters must not be null."); michael@0: } michael@0: params.setIntParameter(MAX_TOTAL_CONNECTIONS, maxTotalConnections); michael@0: } michael@0: michael@0: /** michael@0: * Gets the maximum number of connections allowed. michael@0: * michael@0: * @param params HTTP parameters michael@0: * michael@0: * @return The maximum number of connections allowed. michael@0: * michael@0: * @deprecated use {@link ThreadSafeClientConnManager#getMaxTotal()} michael@0: */ michael@0: @Deprecated michael@0: public static int getMaxTotalConnections( michael@0: final HttpParams params) { michael@0: if (params == null) { michael@0: throw new IllegalArgumentException michael@0: ("HTTP parameters must not be null."); michael@0: } michael@0: return params.getIntParameter(MAX_TOTAL_CONNECTIONS, DEFAULT_MAX_TOTAL_CONNECTIONS); michael@0: } michael@0: michael@0: }