View Javadoc

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  
28  package org.apache.http.nio.params;
29  
30  import org.apache.http.impl.nio.reactor.IOReactorConfig;
31  import org.apache.http.params.HttpParams;
32  
33  /**
34   * Utility class for accessing I/O reactor parameters in {@link HttpParams}.
35   *
36   * @since 4.0
37   *
38   * @see NIOReactorPNames
39   *
40   * @deprecated (4.2) use {@link IOReactorConfig}
41   */
42  @Deprecated
43  public final class NIOReactorParams implements NIOReactorPNames {
44  
45      private NIOReactorParams() {
46          super();
47      }
48  
49      /**
50       * Obtains the value of {@link NIOReactorPNames#CONTENT_BUFFER_SIZE} parameter.
51       * If not set, defaults to <code>4096</code>.
52       *
53       * @param params HTTP parameters.
54       * @return content buffer size.
55       */
56      public static int getContentBufferSize(final HttpParams params) {
57          if (params == null) {
58              throw new IllegalArgumentException("HTTP parameters may not be null");
59          }
60          return params.getIntParameter(CONTENT_BUFFER_SIZE, 4096);
61      }
62  
63      /**
64       * Sets value of the {@link NIOReactorPNames#CONTENT_BUFFER_SIZE} parameter.
65       *
66       * @param params HTTP parameters.
67       * @param size content buffer size.
68       */
69      public static void setContentBufferSize(final HttpParams params, int size) {
70          if (params == null) {
71              throw new IllegalArgumentException("HTTP parameters may not be null");
72          }
73          params.setIntParameter(CONTENT_BUFFER_SIZE, size);
74      }
75  
76      /**
77       * Obtains the value of {@link NIOReactorPNames#SELECT_INTERVAL} parameter.
78       * If not set, defaults to <code>1000</code>.
79       *
80       * @param params HTTP parameters.
81       * @return I/O select interval in milliseconds.
82       */
83      public static long getSelectInterval(final HttpParams params) {
84          if (params == null) {
85              throw new IllegalArgumentException("HTTP parameters may not be null");
86          }
87          return params.getLongParameter(SELECT_INTERVAL, 1000);
88      }
89  
90      /**
91       * Sets value of the {@link NIOReactorPNames#SELECT_INTERVAL} parameter.
92       *
93       * @param params HTTP parameters.
94       * @param ms I/O select interval in milliseconds.
95       */
96      public static void setSelectInterval(final HttpParams params, long ms) {
97          if (params == null) {
98              throw new IllegalArgumentException("HTTP parameters may not be null");
99          }
100         params.setLongParameter(SELECT_INTERVAL, ms);
101     }
102 
103     /**
104      * Obtains the value of {@link NIOReactorPNames#GRACE_PERIOD} parameter.
105      * If not set, defaults to <code>500</code>.
106      *
107      * @param params HTTP parameters.
108      * @return shutdown grace period in milliseconds.
109      */
110     public static long getGracePeriod(final HttpParams params) {
111         if (params == null) {
112             throw new IllegalArgumentException("HTTP parameters may not be null");
113         }
114         return params.getLongParameter(GRACE_PERIOD, 500);
115     }
116 
117     /**
118      * Sets value of the {@link NIOReactorPNames#GRACE_PERIOD} parameter.
119      *
120      * @param params HTTP parameters.
121      * @param ms shutdown grace period in milliseconds.
122      */
123     public static void setGracePeriod(final HttpParams params, long ms) {
124         if (params == null) {
125             throw new IllegalArgumentException("HTTP parameters may not be null");
126         }
127         params.setLongParameter(GRACE_PERIOD, ms);
128     }
129 
130     /**
131      * Obtains the value of {@link NIOReactorPNames#INTEREST_OPS_QUEUEING} parameter.
132      * If not set, defaults to <code>false</code>.
133      *
134      * @param params HTTP parameters.
135      * @return interest ops queuing flag.
136      *
137      * @since 4.1
138      */
139     public static boolean getInterestOpsQueueing(final HttpParams params) {
140         if (params == null) {
141             throw new IllegalArgumentException("HTTP parameters may not be null");
142         }
143         return params.getBooleanParameter(INTEREST_OPS_QUEUEING, false);
144     }
145 
146     /**
147      * Sets value of the {@link NIOReactorPNames#INTEREST_OPS_QUEUEING} parameter.
148      *
149      * @param params HTTP parameters.
150      * @param interestOpsQueueing interest ops queuing.
151      *
152      * @since 4.1
153      */
154     public static void setInterestOpsQueueing(
155             final HttpParams params, boolean interestOpsQueueing) {
156         if (params == null) {
157             throw new IllegalArgumentException("HTTP parameters may not be null");
158         }
159         params.setBooleanParameter(INTEREST_OPS_QUEUEING, interestOpsQueueing);
160     }
161 
162 }