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.params.HttpParams;
31  import org.apache.http.util.Args;
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 org.apache.http.impl.nio.reactor.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}.
52       *
53       * @param params HTTP parameters.
54       * @return content buffer size.
55       */
56      public static int getContentBufferSize(final HttpParams params) {
57          Args.notNull(params, "HTTP parameters");
58          return params.getIntParameter(CONTENT_BUFFER_SIZE, 4096);
59      }
60  
61      /**
62       * Sets value of the {@link NIOReactorPNames#CONTENT_BUFFER_SIZE} parameter.
63       *
64       * @param params HTTP parameters.
65       * @param size content buffer size.
66       */
67      public static void setContentBufferSize(final HttpParams params, final int size) {
68          Args.notNull(params, "HTTP parameters");
69          params.setIntParameter(CONTENT_BUFFER_SIZE, size);
70      }
71  
72      /**
73       * Obtains the value of {@link NIOReactorPNames#SELECT_INTERVAL} parameter.
74       * If not set, defaults to {@code 1000}.
75       *
76       * @param params HTTP parameters.
77       * @return I/O select interval in milliseconds.
78       */
79      public static long getSelectInterval(final HttpParams params) {
80          Args.notNull(params, "HTTP parameters");
81          return params.getLongParameter(SELECT_INTERVAL, 1000);
82      }
83  
84      /**
85       * Sets value of the {@link NIOReactorPNames#SELECT_INTERVAL} parameter.
86       *
87       * @param params HTTP parameters.
88       * @param ms I/O select interval in milliseconds.
89       */
90      public static void setSelectInterval(final HttpParams params, final long ms) {
91          Args.notNull(params, "HTTP parameters");
92          params.setLongParameter(SELECT_INTERVAL, ms);
93      }
94  
95      /**
96       * Obtains the value of {@link NIOReactorPNames#GRACE_PERIOD} parameter.
97       * If not set, defaults to {@code 500}.
98       *
99       * @param params HTTP parameters.
100      * @return shutdown grace period in milliseconds.
101      */
102     public static long getGracePeriod(final HttpParams params) {
103         Args.notNull(params, "HTTP parameters");
104         return params.getLongParameter(GRACE_PERIOD, 500);
105     }
106 
107     /**
108      * Sets value of the {@link NIOReactorPNames#GRACE_PERIOD} parameter.
109      *
110      * @param params HTTP parameters.
111      * @param ms shutdown grace period in milliseconds.
112      */
113     public static void setGracePeriod(final HttpParams params, final long ms) {
114         Args.notNull(params, "HTTP parameters");
115         params.setLongParameter(GRACE_PERIOD, ms);
116     }
117 
118     /**
119      * Obtains the value of {@link NIOReactorPNames#INTEREST_OPS_QUEUEING} parameter.
120      * If not set, defaults to {@code false}.
121      *
122      * @param params HTTP parameters.
123      * @return interest ops queuing flag.
124      *
125      * @since 4.1
126      */
127     public static boolean getInterestOpsQueueing(final HttpParams params) {
128         Args.notNull(params, "HTTP parameters");
129         return params.getBooleanParameter(INTEREST_OPS_QUEUEING, false);
130     }
131 
132     /**
133      * Sets value of the {@link NIOReactorPNames#INTEREST_OPS_QUEUEING} parameter.
134      *
135      * @param params HTTP parameters.
136      * @param interestOpsQueueing interest ops queuing.
137      *
138      * @since 4.1
139      */
140     public static void setInterestOpsQueueing(
141             final HttpParams params, final boolean interestOpsQueueing) {
142         Args.notNull(params, "HTTP parameters");
143         params.setBooleanParameter(INTEREST_OPS_QUEUEING, interestOpsQueueing);
144     }
145 
146 }