src/jdk.httpserver/share/classes/sun/net/httpserver/ServerConfig.java
changeset 47216 71c04702a3d5
parent 41592 855537e5ad9c
equal deleted inserted replaced
47215:4ebc2e2fb97c 47216:71c04702a3d5
       
     1 /*
       
     2  * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.  Oracle designates this
       
     8  * particular file as subject to the "Classpath" exception as provided
       
     9  * by Oracle in the LICENSE file that accompanied this code.
       
    10  *
       
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    14  * version 2 for more details (a copy is included in the LICENSE file that
       
    15  * accompanied this code).
       
    16  *
       
    17  * You should have received a copy of the GNU General Public License version
       
    18  * 2 along with this work; if not, write to the Free Software Foundation,
       
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    20  *
       
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    22  * or visit www.oracle.com if you need additional information or have any
       
    23  * questions.
       
    24  */
       
    25 
       
    26 package sun.net.httpserver;
       
    27 
       
    28 import java.lang.System.Logger;
       
    29 import java.lang.System.Logger.Level;
       
    30 import java.security.PrivilegedAction;
       
    31 
       
    32 /**
       
    33  * Parameters that users will not likely need to set
       
    34  * but are useful for debugging
       
    35  */
       
    36 
       
    37 class ServerConfig {
       
    38 
       
    39     private static final int DEFAULT_CLOCK_TICK = 10000 ; // 10 sec.
       
    40 
       
    41     /* These values must be a reasonable multiple of clockTick */
       
    42     private static final long DEFAULT_IDLE_INTERVAL = 30 ; // 5 min
       
    43     private static final int DEFAULT_MAX_IDLE_CONNECTIONS = 200 ;
       
    44 
       
    45     private static final long DEFAULT_MAX_REQ_TIME = -1; // default: forever
       
    46     private static final long DEFAULT_MAX_RSP_TIME = -1; // default: forever
       
    47     private static final long DEFAULT_TIMER_MILLIS = 1000;
       
    48     private static final int  DEFAULT_MAX_REQ_HEADERS = 200;
       
    49     private static final long DEFAULT_DRAIN_AMOUNT = 64 * 1024;
       
    50 
       
    51     private static int clockTick;
       
    52     private static long idleInterval;
       
    53     // The maximum number of bytes to drain from an inputstream
       
    54     private static long drainAmount;
       
    55     private static int maxIdleConnections;
       
    56     // The maximum number of request headers allowable
       
    57     private static int maxReqHeaders;
       
    58     // max time a request or response is allowed to take
       
    59     private static long maxReqTime;
       
    60     private static long maxRspTime;
       
    61     private static long timerMillis;
       
    62     private static boolean debug;
       
    63 
       
    64     // the value of the TCP_NODELAY socket-level option
       
    65     private static boolean noDelay;
       
    66 
       
    67     static {
       
    68         java.security.AccessController.doPrivileged(
       
    69             new PrivilegedAction<Void>() {
       
    70                 @Override
       
    71                 public Void run () {
       
    72                     idleInterval = Long.getLong("sun.net.httpserver.idleInterval",
       
    73                             DEFAULT_IDLE_INTERVAL) * 1000;
       
    74 
       
    75                     clockTick = Integer.getInteger("sun.net.httpserver.clockTick",
       
    76                             DEFAULT_CLOCK_TICK);
       
    77 
       
    78                     maxIdleConnections = Integer.getInteger(
       
    79                             "sun.net.httpserver.maxIdleConnections",
       
    80                             DEFAULT_MAX_IDLE_CONNECTIONS);
       
    81 
       
    82                     drainAmount = Long.getLong("sun.net.httpserver.drainAmount",
       
    83                             DEFAULT_DRAIN_AMOUNT);
       
    84 
       
    85                     maxReqHeaders = Integer.getInteger(
       
    86                             "sun.net.httpserver.maxReqHeaders",
       
    87                             DEFAULT_MAX_REQ_HEADERS);
       
    88 
       
    89                     maxReqTime = Long.getLong("sun.net.httpserver.maxReqTime",
       
    90                             DEFAULT_MAX_REQ_TIME);
       
    91 
       
    92                     maxRspTime = Long.getLong("sun.net.httpserver.maxRspTime",
       
    93                             DEFAULT_MAX_RSP_TIME);
       
    94 
       
    95                     timerMillis = Long.getLong("sun.net.httpserver.timerMillis",
       
    96                             DEFAULT_TIMER_MILLIS);
       
    97 
       
    98                     debug = Boolean.getBoolean("sun.net.httpserver.debug");
       
    99 
       
   100                     noDelay = Boolean.getBoolean("sun.net.httpserver.nodelay");
       
   101 
       
   102                     return null;
       
   103                 }
       
   104             });
       
   105 
       
   106     }
       
   107 
       
   108     static void checkLegacyProperties(final Logger logger) {
       
   109 
       
   110         // legacy properties that are no longer used
       
   111         // print a warning to logger if they are set.
       
   112 
       
   113         java.security.AccessController.doPrivileged(
       
   114             new PrivilegedAction<Void>() {
       
   115                 public Void run () {
       
   116                     if (System.getProperty("sun.net.httpserver.readTimeout")
       
   117                                                 !=null)
       
   118                     {
       
   119                         logger.log (Level.WARNING,
       
   120                             "sun.net.httpserver.readTimeout "+
       
   121                             "property is no longer used. "+
       
   122                             "Use sun.net.httpserver.maxReqTime instead."
       
   123                         );
       
   124                     }
       
   125                     if (System.getProperty("sun.net.httpserver.writeTimeout")
       
   126                                                 !=null)
       
   127                     {
       
   128                         logger.log (Level.WARNING,
       
   129                             "sun.net.httpserver.writeTimeout "+
       
   130                             "property is no longer used. Use "+
       
   131                             "sun.net.httpserver.maxRspTime instead."
       
   132                         );
       
   133                     }
       
   134                     if (System.getProperty("sun.net.httpserver.selCacheTimeout")
       
   135                                                 !=null)
       
   136                     {
       
   137                         logger.log (Level.WARNING,
       
   138                             "sun.net.httpserver.selCacheTimeout "+
       
   139                             "property is no longer used."
       
   140                         );
       
   141                     }
       
   142                     return null;
       
   143                 }
       
   144             }
       
   145         );
       
   146     }
       
   147 
       
   148     static boolean debugEnabled() {
       
   149         return debug;
       
   150     }
       
   151 
       
   152     static long getIdleInterval() {
       
   153         return idleInterval;
       
   154     }
       
   155 
       
   156     static int getClockTick() {
       
   157         return clockTick;
       
   158     }
       
   159 
       
   160     static int getMaxIdleConnections() {
       
   161         return maxIdleConnections;
       
   162     }
       
   163 
       
   164     static long getDrainAmount() {
       
   165         return drainAmount;
       
   166     }
       
   167 
       
   168     static int getMaxReqHeaders() {
       
   169         return maxReqHeaders;
       
   170     }
       
   171 
       
   172     static long getMaxReqTime() {
       
   173         return maxReqTime;
       
   174     }
       
   175 
       
   176     static long getMaxRspTime() {
       
   177         return maxRspTime;
       
   178     }
       
   179 
       
   180     static long getTimerMillis() {
       
   181         return timerMillis;
       
   182     }
       
   183 
       
   184     static boolean noDelay() {
       
   185         return noDelay;
       
   186     }
       
   187 }