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 | * Licensed to the Apache Software Foundation (ASF) under one |
michael@0 | 4 | * or more contributor license agreements. See the NOTICE file |
michael@0 | 5 | * distributed with this work for additional information |
michael@0 | 6 | * regarding copyright ownership. The ASF licenses this file |
michael@0 | 7 | * to you under the Apache License, Version 2.0 (the |
michael@0 | 8 | * "License"); you may not use this file except in compliance |
michael@0 | 9 | * with 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, |
michael@0 | 14 | * software distributed under the License is distributed on an |
michael@0 | 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
michael@0 | 16 | * KIND, either express or implied. See the License for the |
michael@0 | 17 | * specific language governing permissions and limitations |
michael@0 | 18 | * under the License. |
michael@0 | 19 | * ==================================================================== |
michael@0 | 20 | * |
michael@0 | 21 | * This software consists of voluntary contributions made by many |
michael@0 | 22 | * individuals on behalf of the Apache Software Foundation. For more |
michael@0 | 23 | * information on the Apache Software Foundation, please see |
michael@0 | 24 | * <http://www.apache.org/>. |
michael@0 | 25 | * |
michael@0 | 26 | */ |
michael@0 | 27 | |
michael@0 | 28 | package ch.boye.httpclientandroidlib.params; |
michael@0 | 29 | |
michael@0 | 30 | /** |
michael@0 | 31 | * Utility class for accessing connection parameters in {@link HttpParams}. |
michael@0 | 32 | * |
michael@0 | 33 | * @since 4.0 |
michael@0 | 34 | */ |
michael@0 | 35 | public final class HttpConnectionParams implements CoreConnectionPNames { |
michael@0 | 36 | |
michael@0 | 37 | private HttpConnectionParams() { |
michael@0 | 38 | super(); |
michael@0 | 39 | } |
michael@0 | 40 | |
michael@0 | 41 | /** |
michael@0 | 42 | * Obtains value of the {@link CoreConnectionPNames#SO_TIMEOUT} parameter. |
michael@0 | 43 | * If not set, defaults to <code>0</code>. |
michael@0 | 44 | * |
michael@0 | 45 | * @param params HTTP parameters. |
michael@0 | 46 | * @return SO_TIMEOUT. |
michael@0 | 47 | */ |
michael@0 | 48 | public static int getSoTimeout(final HttpParams params) { |
michael@0 | 49 | if (params == null) { |
michael@0 | 50 | throw new IllegalArgumentException("HTTP parameters may not be null"); |
michael@0 | 51 | } |
michael@0 | 52 | return params.getIntParameter(CoreConnectionPNames.SO_TIMEOUT, 0); |
michael@0 | 53 | } |
michael@0 | 54 | |
michael@0 | 55 | /** |
michael@0 | 56 | * Sets value of the {@link CoreConnectionPNames#SO_TIMEOUT} parameter. |
michael@0 | 57 | * |
michael@0 | 58 | * @param params HTTP parameters. |
michael@0 | 59 | * @param timeout SO_TIMEOUT. |
michael@0 | 60 | */ |
michael@0 | 61 | public static void setSoTimeout(final HttpParams params, int timeout) { |
michael@0 | 62 | if (params == null) { |
michael@0 | 63 | throw new IllegalArgumentException("HTTP parameters may not be null"); |
michael@0 | 64 | } |
michael@0 | 65 | params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, timeout); |
michael@0 | 66 | |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | /** |
michael@0 | 70 | * Obtains value of the {@link CoreConnectionPNames#SO_REUSEADDR} parameter. |
michael@0 | 71 | * If not set, defaults to <code>false</code>. |
michael@0 | 72 | * |
michael@0 | 73 | * @param params HTTP parameters. |
michael@0 | 74 | * @return SO_REUSEADDR. |
michael@0 | 75 | * |
michael@0 | 76 | * @since 4.1 |
michael@0 | 77 | */ |
michael@0 | 78 | public static boolean getSoReuseaddr(final HttpParams params) { |
michael@0 | 79 | if (params == null) { |
michael@0 | 80 | throw new IllegalArgumentException("HTTP parameters may not be null"); |
michael@0 | 81 | } |
michael@0 | 82 | return params.getBooleanParameter(CoreConnectionPNames.SO_REUSEADDR, false); |
michael@0 | 83 | } |
michael@0 | 84 | |
michael@0 | 85 | /** |
michael@0 | 86 | * Sets value of the {@link CoreConnectionPNames#SO_REUSEADDR} parameter. |
michael@0 | 87 | * |
michael@0 | 88 | * @param params HTTP parameters. |
michael@0 | 89 | * @param reuseaddr SO_REUSEADDR. |
michael@0 | 90 | * |
michael@0 | 91 | * @since 4.1 |
michael@0 | 92 | */ |
michael@0 | 93 | public static void setSoReuseaddr(final HttpParams params, boolean reuseaddr) { |
michael@0 | 94 | if (params == null) { |
michael@0 | 95 | throw new IllegalArgumentException("HTTP parameters may not be null"); |
michael@0 | 96 | } |
michael@0 | 97 | params.setBooleanParameter(CoreConnectionPNames.SO_REUSEADDR, reuseaddr); |
michael@0 | 98 | } |
michael@0 | 99 | |
michael@0 | 100 | /** |
michael@0 | 101 | * Obtains value of the {@link CoreConnectionPNames#TCP_NODELAY} parameter. |
michael@0 | 102 | * If not set, defaults to <code>true</code>. |
michael@0 | 103 | * |
michael@0 | 104 | * @param params HTTP parameters. |
michael@0 | 105 | * @return Nagle's algorithm flag |
michael@0 | 106 | */ |
michael@0 | 107 | public static boolean getTcpNoDelay(final HttpParams params) { |
michael@0 | 108 | if (params == null) { |
michael@0 | 109 | throw new IllegalArgumentException("HTTP parameters may not be null"); |
michael@0 | 110 | } |
michael@0 | 111 | return params.getBooleanParameter |
michael@0 | 112 | (CoreConnectionPNames.TCP_NODELAY, true); |
michael@0 | 113 | } |
michael@0 | 114 | |
michael@0 | 115 | /** |
michael@0 | 116 | * Sets value of the {@link CoreConnectionPNames#TCP_NODELAY} parameter. |
michael@0 | 117 | * |
michael@0 | 118 | * @param params HTTP parameters. |
michael@0 | 119 | * @param value Nagle's algorithm flag |
michael@0 | 120 | */ |
michael@0 | 121 | public static void setTcpNoDelay(final HttpParams params, boolean value) { |
michael@0 | 122 | if (params == null) { |
michael@0 | 123 | throw new IllegalArgumentException("HTTP parameters may not be null"); |
michael@0 | 124 | } |
michael@0 | 125 | params.setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, value); |
michael@0 | 126 | } |
michael@0 | 127 | |
michael@0 | 128 | /** |
michael@0 | 129 | * Obtains value of the {@link CoreConnectionPNames#SOCKET_BUFFER_SIZE} |
michael@0 | 130 | * parameter. If not set, defaults to <code>-1</code>. |
michael@0 | 131 | * |
michael@0 | 132 | * @param params HTTP parameters. |
michael@0 | 133 | * @return socket buffer size |
michael@0 | 134 | */ |
michael@0 | 135 | public static int getSocketBufferSize(final HttpParams params) { |
michael@0 | 136 | if (params == null) { |
michael@0 | 137 | throw new IllegalArgumentException("HTTP parameters may not be null"); |
michael@0 | 138 | } |
michael@0 | 139 | return params.getIntParameter |
michael@0 | 140 | (CoreConnectionPNames.SOCKET_BUFFER_SIZE, -1); |
michael@0 | 141 | } |
michael@0 | 142 | |
michael@0 | 143 | /** |
michael@0 | 144 | * Sets value of the {@link CoreConnectionPNames#SOCKET_BUFFER_SIZE} |
michael@0 | 145 | * parameter. |
michael@0 | 146 | * |
michael@0 | 147 | * @param params HTTP parameters. |
michael@0 | 148 | * @param size socket buffer size |
michael@0 | 149 | */ |
michael@0 | 150 | public static void setSocketBufferSize(final HttpParams params, int size) { |
michael@0 | 151 | if (params == null) { |
michael@0 | 152 | throw new IllegalArgumentException("HTTP parameters may not be null"); |
michael@0 | 153 | } |
michael@0 | 154 | params.setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, size); |
michael@0 | 155 | } |
michael@0 | 156 | |
michael@0 | 157 | /** |
michael@0 | 158 | * Obtains value of the {@link CoreConnectionPNames#SO_LINGER} parameter. |
michael@0 | 159 | * If not set, defaults to <code>-1</code>. |
michael@0 | 160 | * |
michael@0 | 161 | * @param params HTTP parameters. |
michael@0 | 162 | * @return SO_LINGER. |
michael@0 | 163 | */ |
michael@0 | 164 | public static int getLinger(final HttpParams params) { |
michael@0 | 165 | if (params == null) { |
michael@0 | 166 | throw new IllegalArgumentException("HTTP parameters may not be null"); |
michael@0 | 167 | } |
michael@0 | 168 | return params.getIntParameter(CoreConnectionPNames.SO_LINGER, -1); |
michael@0 | 169 | } |
michael@0 | 170 | |
michael@0 | 171 | /** |
michael@0 | 172 | * Sets value of the {@link CoreConnectionPNames#SO_LINGER} parameter. |
michael@0 | 173 | * |
michael@0 | 174 | * @param params HTTP parameters. |
michael@0 | 175 | * @param value SO_LINGER. |
michael@0 | 176 | */ |
michael@0 | 177 | public static void setLinger(final HttpParams params, int value) { |
michael@0 | 178 | if (params == null) { |
michael@0 | 179 | throw new IllegalArgumentException("HTTP parameters may not be null"); |
michael@0 | 180 | } |
michael@0 | 181 | params.setIntParameter(CoreConnectionPNames.SO_LINGER, value); |
michael@0 | 182 | } |
michael@0 | 183 | |
michael@0 | 184 | /** |
michael@0 | 185 | * Obtains value of the {@link CoreConnectionPNames#CONNECTION_TIMEOUT} |
michael@0 | 186 | * parameter. If not set, defaults to <code>0</code>. |
michael@0 | 187 | * |
michael@0 | 188 | * @param params HTTP parameters. |
michael@0 | 189 | * @return connect timeout. |
michael@0 | 190 | */ |
michael@0 | 191 | public static int getConnectionTimeout(final HttpParams params) { |
michael@0 | 192 | if (params == null) { |
michael@0 | 193 | throw new IllegalArgumentException("HTTP parameters may not be null"); |
michael@0 | 194 | } |
michael@0 | 195 | return params.getIntParameter |
michael@0 | 196 | (CoreConnectionPNames.CONNECTION_TIMEOUT, 0); |
michael@0 | 197 | } |
michael@0 | 198 | |
michael@0 | 199 | /** |
michael@0 | 200 | * Sets value of the {@link CoreConnectionPNames#CONNECTION_TIMEOUT} |
michael@0 | 201 | * parameter. |
michael@0 | 202 | * |
michael@0 | 203 | * @param params HTTP parameters. |
michael@0 | 204 | * @param timeout connect timeout. |
michael@0 | 205 | */ |
michael@0 | 206 | public static void setConnectionTimeout(final HttpParams params, int timeout) { |
michael@0 | 207 | if (params == null) { |
michael@0 | 208 | throw new IllegalArgumentException("HTTP parameters may not be null"); |
michael@0 | 209 | } |
michael@0 | 210 | params.setIntParameter |
michael@0 | 211 | (CoreConnectionPNames.CONNECTION_TIMEOUT, timeout); |
michael@0 | 212 | } |
michael@0 | 213 | |
michael@0 | 214 | /** |
michael@0 | 215 | * Obtains value of the {@link CoreConnectionPNames#STALE_CONNECTION_CHECK} |
michael@0 | 216 | * parameter. If not set, defaults to <code>true</code>. |
michael@0 | 217 | * |
michael@0 | 218 | * @param params HTTP parameters. |
michael@0 | 219 | * @return stale connection check flag. |
michael@0 | 220 | */ |
michael@0 | 221 | public static boolean isStaleCheckingEnabled(final HttpParams params) { |
michael@0 | 222 | if (params == null) { |
michael@0 | 223 | throw new IllegalArgumentException("HTTP parameters may not be null"); |
michael@0 | 224 | } |
michael@0 | 225 | return params.getBooleanParameter |
michael@0 | 226 | (CoreConnectionPNames.STALE_CONNECTION_CHECK, true); |
michael@0 | 227 | } |
michael@0 | 228 | |
michael@0 | 229 | /** |
michael@0 | 230 | * Sets value of the {@link CoreConnectionPNames#STALE_CONNECTION_CHECK} |
michael@0 | 231 | * parameter. |
michael@0 | 232 | * |
michael@0 | 233 | * @param params HTTP parameters. |
michael@0 | 234 | * @param value stale connection check flag. |
michael@0 | 235 | */ |
michael@0 | 236 | public static void setStaleCheckingEnabled(final HttpParams params, boolean value) { |
michael@0 | 237 | if (params == null) { |
michael@0 | 238 | throw new IllegalArgumentException("HTTP parameters may not be null"); |
michael@0 | 239 | } |
michael@0 | 240 | params.setBooleanParameter |
michael@0 | 241 | (CoreConnectionPNames.STALE_CONNECTION_CHECK, value); |
michael@0 | 242 | } |
michael@0 | 243 | |
michael@0 | 244 | } |