michael@0: /*
michael@0: * ====================================================================
michael@0: * Licensed to the Apache Software Foundation (ASF) under one
michael@0: * or more contributor license agreements. See the NOTICE file
michael@0: * distributed with this work for additional information
michael@0: * regarding copyright ownership. The ASF licenses this file
michael@0: * to you under the Apache License, Version 2.0 (the
michael@0: * "License"); you may not use this file except in compliance
michael@0: * with 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,
michael@0: * software distributed under the License is distributed on an
michael@0: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
michael@0: * KIND, either express or implied. See the License for the
michael@0: * specific language governing permissions and limitations
michael@0: * 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.params;
michael@0:
michael@0: /**
michael@0: * Utility class for accessing connection parameters in {@link HttpParams}.
michael@0: *
michael@0: * @since 4.0
michael@0: */
michael@0: public final class HttpConnectionParams implements CoreConnectionPNames {
michael@0:
michael@0: private HttpConnectionParams() {
michael@0: super();
michael@0: }
michael@0:
michael@0: /**
michael@0: * Obtains value of the {@link CoreConnectionPNames#SO_TIMEOUT} parameter.
michael@0: * If not set, defaults to 0
.
michael@0: *
michael@0: * @param params HTTP parameters.
michael@0: * @return SO_TIMEOUT.
michael@0: */
michael@0: public static int getSoTimeout(final HttpParams params) {
michael@0: if (params == null) {
michael@0: throw new IllegalArgumentException("HTTP parameters may not be null");
michael@0: }
michael@0: return params.getIntParameter(CoreConnectionPNames.SO_TIMEOUT, 0);
michael@0: }
michael@0:
michael@0: /**
michael@0: * Sets value of the {@link CoreConnectionPNames#SO_TIMEOUT} parameter.
michael@0: *
michael@0: * @param params HTTP parameters.
michael@0: * @param timeout SO_TIMEOUT.
michael@0: */
michael@0: public static void setSoTimeout(final HttpParams params, int timeout) {
michael@0: if (params == null) {
michael@0: throw new IllegalArgumentException("HTTP parameters may not be null");
michael@0: }
michael@0: params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, timeout);
michael@0:
michael@0: }
michael@0:
michael@0: /**
michael@0: * Obtains value of the {@link CoreConnectionPNames#SO_REUSEADDR} parameter.
michael@0: * If not set, defaults to false
.
michael@0: *
michael@0: * @param params HTTP parameters.
michael@0: * @return SO_REUSEADDR.
michael@0: *
michael@0: * @since 4.1
michael@0: */
michael@0: public static boolean getSoReuseaddr(final HttpParams params) {
michael@0: if (params == null) {
michael@0: throw new IllegalArgumentException("HTTP parameters may not be null");
michael@0: }
michael@0: return params.getBooleanParameter(CoreConnectionPNames.SO_REUSEADDR, false);
michael@0: }
michael@0:
michael@0: /**
michael@0: * Sets value of the {@link CoreConnectionPNames#SO_REUSEADDR} parameter.
michael@0: *
michael@0: * @param params HTTP parameters.
michael@0: * @param reuseaddr SO_REUSEADDR.
michael@0: *
michael@0: * @since 4.1
michael@0: */
michael@0: public static void setSoReuseaddr(final HttpParams params, boolean reuseaddr) {
michael@0: if (params == null) {
michael@0: throw new IllegalArgumentException("HTTP parameters may not be null");
michael@0: }
michael@0: params.setBooleanParameter(CoreConnectionPNames.SO_REUSEADDR, reuseaddr);
michael@0: }
michael@0:
michael@0: /**
michael@0: * Obtains value of the {@link CoreConnectionPNames#TCP_NODELAY} parameter.
michael@0: * If not set, defaults to true
.
michael@0: *
michael@0: * @param params HTTP parameters.
michael@0: * @return Nagle's algorithm flag
michael@0: */
michael@0: public static boolean getTcpNoDelay(final HttpParams params) {
michael@0: if (params == null) {
michael@0: throw new IllegalArgumentException("HTTP parameters may not be null");
michael@0: }
michael@0: return params.getBooleanParameter
michael@0: (CoreConnectionPNames.TCP_NODELAY, true);
michael@0: }
michael@0:
michael@0: /**
michael@0: * Sets value of the {@link CoreConnectionPNames#TCP_NODELAY} parameter.
michael@0: *
michael@0: * @param params HTTP parameters.
michael@0: * @param value Nagle's algorithm flag
michael@0: */
michael@0: public static void setTcpNoDelay(final HttpParams params, boolean value) {
michael@0: if (params == null) {
michael@0: throw new IllegalArgumentException("HTTP parameters may not be null");
michael@0: }
michael@0: params.setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, value);
michael@0: }
michael@0:
michael@0: /**
michael@0: * Obtains value of the {@link CoreConnectionPNames#SOCKET_BUFFER_SIZE}
michael@0: * parameter. If not set, defaults to -1
.
michael@0: *
michael@0: * @param params HTTP parameters.
michael@0: * @return socket buffer size
michael@0: */
michael@0: public static int getSocketBufferSize(final HttpParams params) {
michael@0: if (params == null) {
michael@0: throw new IllegalArgumentException("HTTP parameters may not be null");
michael@0: }
michael@0: return params.getIntParameter
michael@0: (CoreConnectionPNames.SOCKET_BUFFER_SIZE, -1);
michael@0: }
michael@0:
michael@0: /**
michael@0: * Sets value of the {@link CoreConnectionPNames#SOCKET_BUFFER_SIZE}
michael@0: * parameter.
michael@0: *
michael@0: * @param params HTTP parameters.
michael@0: * @param size socket buffer size
michael@0: */
michael@0: public static void setSocketBufferSize(final HttpParams params, int size) {
michael@0: if (params == null) {
michael@0: throw new IllegalArgumentException("HTTP parameters may not be null");
michael@0: }
michael@0: params.setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, size);
michael@0: }
michael@0:
michael@0: /**
michael@0: * Obtains value of the {@link CoreConnectionPNames#SO_LINGER} parameter.
michael@0: * If not set, defaults to -1
.
michael@0: *
michael@0: * @param params HTTP parameters.
michael@0: * @return SO_LINGER.
michael@0: */
michael@0: public static int getLinger(final HttpParams params) {
michael@0: if (params == null) {
michael@0: throw new IllegalArgumentException("HTTP parameters may not be null");
michael@0: }
michael@0: return params.getIntParameter(CoreConnectionPNames.SO_LINGER, -1);
michael@0: }
michael@0:
michael@0: /**
michael@0: * Sets value of the {@link CoreConnectionPNames#SO_LINGER} parameter.
michael@0: *
michael@0: * @param params HTTP parameters.
michael@0: * @param value SO_LINGER.
michael@0: */
michael@0: public static void setLinger(final HttpParams params, int value) {
michael@0: if (params == null) {
michael@0: throw new IllegalArgumentException("HTTP parameters may not be null");
michael@0: }
michael@0: params.setIntParameter(CoreConnectionPNames.SO_LINGER, value);
michael@0: }
michael@0:
michael@0: /**
michael@0: * Obtains value of the {@link CoreConnectionPNames#CONNECTION_TIMEOUT}
michael@0: * parameter. If not set, defaults to 0
.
michael@0: *
michael@0: * @param params HTTP parameters.
michael@0: * @return connect timeout.
michael@0: */
michael@0: public static int getConnectionTimeout(final HttpParams params) {
michael@0: if (params == null) {
michael@0: throw new IllegalArgumentException("HTTP parameters may not be null");
michael@0: }
michael@0: return params.getIntParameter
michael@0: (CoreConnectionPNames.CONNECTION_TIMEOUT, 0);
michael@0: }
michael@0:
michael@0: /**
michael@0: * Sets value of the {@link CoreConnectionPNames#CONNECTION_TIMEOUT}
michael@0: * parameter.
michael@0: *
michael@0: * @param params HTTP parameters.
michael@0: * @param timeout connect timeout.
michael@0: */
michael@0: public static void setConnectionTimeout(final HttpParams params, int timeout) {
michael@0: if (params == null) {
michael@0: throw new IllegalArgumentException("HTTP parameters may not be null");
michael@0: }
michael@0: params.setIntParameter
michael@0: (CoreConnectionPNames.CONNECTION_TIMEOUT, timeout);
michael@0: }
michael@0:
michael@0: /**
michael@0: * Obtains value of the {@link CoreConnectionPNames#STALE_CONNECTION_CHECK}
michael@0: * parameter. If not set, defaults to true
.
michael@0: *
michael@0: * @param params HTTP parameters.
michael@0: * @return stale connection check flag.
michael@0: */
michael@0: public static boolean isStaleCheckingEnabled(final HttpParams params) {
michael@0: if (params == null) {
michael@0: throw new IllegalArgumentException("HTTP parameters may not be null");
michael@0: }
michael@0: return params.getBooleanParameter
michael@0: (CoreConnectionPNames.STALE_CONNECTION_CHECK, true);
michael@0: }
michael@0:
michael@0: /**
michael@0: * Sets value of the {@link CoreConnectionPNames#STALE_CONNECTION_CHECK}
michael@0: * parameter.
michael@0: *
michael@0: * @param params HTTP parameters.
michael@0: * @param value stale connection check flag.
michael@0: */
michael@0: public static void setStaleCheckingEnabled(final HttpParams params, boolean value) {
michael@0: if (params == null) {
michael@0: throw new IllegalArgumentException("HTTP parameters may not be null");
michael@0: }
michael@0: params.setBooleanParameter
michael@0: (CoreConnectionPNames.STALE_CONNECTION_CHECK, value);
michael@0: }
michael@0:
michael@0: }