jdk/src/share/classes/sun/net/httpserver/ServerConfig.java
changeset 7271 17d3fc18872d
parent 5506 202f599c92aa
child 7537 b7d2d2428f31
equal deleted inserted replaced
7186:7f5fe8985263 7271:17d3fc18872d
    25 
    25 
    26 package sun.net.httpserver;
    26 package sun.net.httpserver;
    27 
    27 
    28 import com.sun.net.httpserver.*;
    28 import com.sun.net.httpserver.*;
    29 import com.sun.net.httpserver.spi.*;
    29 import com.sun.net.httpserver.spi.*;
       
    30 import java.util.logging.Logger;
       
    31 import java.security.PrivilegedAction;
    30 
    32 
    31 /**
    33 /**
    32  * Parameters that users will not likely need to set
    34  * Parameters that users will not likely need to set
    33  * but are useful for debugging
    35  * but are useful for debugging
    34  */
    36  */
    35 
    37 
    36 class ServerConfig {
    38 class ServerConfig {
    37 
    39 
    38     static int clockTick;
    40     static int clockTick;
    39 
    41 
    40     static int defaultClockTick = 10000 ; // 10 sec.
    42     static final int DEFAULT_CLOCK_TICK = 10000 ; // 10 sec.
    41 
    43 
    42     /* These values must be a reasonable multiple of clockTick */
    44     /* These values must be a reasonable multiple of clockTick */
    43     static long defaultReadTimeout = 20 ; // 20 sec.
    45     static final long DEFAULT_IDLE_INTERVAL = 300 ; // 5 min
    44     static long defaultWriteTimeout = 60 ; // 60 sec.
    46     static final int DEFAULT_MAX_IDLE_CONNECTIONS = 200 ;
    45     static long defaultIdleInterval = 300 ; // 5 min
       
    46     static long defaultSelCacheTimeout = 120 ;  // seconds
       
    47     static int defaultMaxIdleConnections = 200 ;
       
    48 
    47 
    49     static long defaultDrainAmount = 64 * 1024;
    48     static final long DEFAULT_MAX_REQ_TIME = -1; // default: forever
       
    49     static final long DEFAULT_MAX_RSP_TIME = -1; // default: forever
       
    50     static final long DEFAULT_TIMER_MILLIS = 1000;
    50 
    51 
    51     static long readTimeout;
    52     static final long DEFAULT_DRAIN_AMOUNT = 64 * 1024;
    52     static long writeTimeout;
    53 
    53     static long idleInterval;
    54     static long idleInterval;
    54     static long selCacheTimeout;
       
    55     static long drainAmount;    // max # of bytes to drain from an inputstream
    55     static long drainAmount;    // max # of bytes to drain from an inputstream
    56     static int maxIdleConnections;
    56     static int maxIdleConnections;
       
    57 
       
    58     // max time a request or response is allowed to take
       
    59     static long maxReqTime;
       
    60     static long maxRspTime;
       
    61     static long timerMillis;
    57     static boolean debug = false;
    62     static boolean debug = false;
    58 
    63 
    59     static {
    64     static {
    60 
    65 
    61         idleInterval = ((Long)java.security.AccessController.doPrivileged(
    66         idleInterval = ((Long)java.security.AccessController.doPrivileged(
    62                 new sun.security.action.GetLongAction(
    67                 new sun.security.action.GetLongAction(
    63                 "sun.net.httpserver.idleInterval",
    68                 "sun.net.httpserver.idleInterval",
    64                 defaultIdleInterval))).longValue() * 1000;
    69                 DEFAULT_IDLE_INTERVAL))).longValue() * 1000;
    65 
    70 
    66         clockTick = ((Integer)java.security.AccessController.doPrivileged(
    71         clockTick = ((Integer)java.security.AccessController.doPrivileged(
    67                 new sun.security.action.GetIntegerAction(
    72                 new sun.security.action.GetIntegerAction(
    68                 "sun.net.httpserver.clockTick",
    73                 "sun.net.httpserver.clockTick",
    69                 defaultClockTick))).intValue();
    74                 DEFAULT_CLOCK_TICK))).intValue();
    70 
    75 
    71         maxIdleConnections = ((Integer)java.security.AccessController.doPrivileged(
    76         maxIdleConnections = ((Integer)java.security.AccessController.doPrivileged(
    72                 new sun.security.action.GetIntegerAction(
    77                 new sun.security.action.GetIntegerAction(
    73                 "sun.net.httpserver.maxIdleConnections",
    78                 "sun.net.httpserver.maxIdleConnections",
    74                 defaultMaxIdleConnections))).intValue();
    79                 DEFAULT_MAX_IDLE_CONNECTIONS))).intValue();
    75 
       
    76         readTimeout = ((Long)java.security.AccessController.doPrivileged(
       
    77                 new sun.security.action.GetLongAction(
       
    78                 "sun.net.httpserver.readTimeout",
       
    79                 defaultReadTimeout))).longValue()* 1000;
       
    80 
       
    81         selCacheTimeout = ((Long)java.security.AccessController.doPrivileged(
       
    82                 new sun.security.action.GetLongAction(
       
    83                 "sun.net.httpserver.selCacheTimeout",
       
    84                 defaultSelCacheTimeout))).longValue()* 1000;
       
    85 
       
    86         writeTimeout = ((Long)java.security.AccessController.doPrivileged(
       
    87                 new sun.security.action.GetLongAction(
       
    88                 "sun.net.httpserver.writeTimeout",
       
    89                 defaultWriteTimeout))).longValue()* 1000;
       
    90 
    80 
    91         drainAmount = ((Long)java.security.AccessController.doPrivileged(
    81         drainAmount = ((Long)java.security.AccessController.doPrivileged(
    92                 new sun.security.action.GetLongAction(
    82                 new sun.security.action.GetLongAction(
    93                 "sun.net.httpserver.drainAmount",
    83                 "sun.net.httpserver.drainAmount",
    94                 defaultDrainAmount))).longValue();
    84                 DEFAULT_DRAIN_AMOUNT))).longValue();
       
    85 
       
    86         maxReqTime = ((Long)java.security.AccessController.doPrivileged(
       
    87                 new sun.security.action.GetLongAction(
       
    88                 "sun.net.httpserver.maxReqTime",
       
    89                 DEFAULT_MAX_REQ_TIME))).longValue();
       
    90 
       
    91         maxRspTime = ((Long)java.security.AccessController.doPrivileged(
       
    92                 new sun.security.action.GetLongAction(
       
    93                 "sun.net.httpserver.maxRspTime",
       
    94                 DEFAULT_MAX_RSP_TIME))).longValue();
       
    95 
       
    96         timerMillis = ((Long)java.security.AccessController.doPrivileged(
       
    97                 new sun.security.action.GetLongAction(
       
    98                 "sun.net.httpserver.timerMillis",
       
    99                 DEFAULT_TIMER_MILLIS))).longValue();
    95 
   100 
    96         debug = ((Boolean)java.security.AccessController.doPrivileged(
   101         debug = ((Boolean)java.security.AccessController.doPrivileged(
    97                 new sun.security.action.GetBooleanAction(
   102                 new sun.security.action.GetBooleanAction(
    98                 "sun.net.httpserver.debug"))).booleanValue();
   103                 "sun.net.httpserver.debug"))).booleanValue();
    99     }
   104     }
   100 
   105 
   101     static long getReadTimeout () {
       
   102         return readTimeout;
       
   103     }
       
   104 
   106 
   105     static long getSelCacheTimeout () {
   107     static void checkLegacyProperties (final Logger logger) {
   106         return selCacheTimeout;
   108 
       
   109         // legacy properties that are no longer used
       
   110         // print a warning to logger if they are set.
       
   111 
       
   112         java.security.AccessController.doPrivileged(
       
   113             new PrivilegedAction<Void>() {
       
   114                 public Void run () {
       
   115                     if (System.getProperty("sun.net.httpserver.readTimeout")
       
   116                                                 !=null)
       
   117                     {
       
   118                         logger.warning ("sun.net.httpserver.readTimeout "+
       
   119                             "property is no longer used. "+
       
   120                             "Use sun.net.httpserver.maxReqTime instead."
       
   121                         );
       
   122                     }
       
   123                     if (System.getProperty("sun.net.httpserver.writeTimeout")
       
   124                                                 !=null)
       
   125                     {
       
   126                         logger.warning ("sun.net.httpserver.writeTimeout "+
       
   127                             "property is no longer used. Use "+
       
   128                             "sun.net.httpserver.maxRspTime instead."
       
   129                         );
       
   130                     }
       
   131                     if (System.getProperty("sun.net.httpserver.selCacheTimeout")
       
   132                                                 !=null)
       
   133                     {
       
   134                         logger.warning ("sun.net.httpserver.selCacheTimeout "+
       
   135                             "property is no longer used."
       
   136                         );
       
   137                     }
       
   138                     return null;
       
   139                 }
       
   140             }
       
   141         );
   107     }
   142     }
   108 
   143 
   109     static boolean debugEnabled () {
   144     static boolean debugEnabled () {
   110         return debug;
   145         return debug;
   111     }
   146     }
   120 
   155 
   121     static int getMaxIdleConnections () {
   156     static int getMaxIdleConnections () {
   122         return maxIdleConnections;
   157         return maxIdleConnections;
   123     }
   158     }
   124 
   159 
   125     static long getWriteTimeout () {
       
   126         return writeTimeout;
       
   127     }
       
   128 
       
   129     static long getDrainAmount () {
   160     static long getDrainAmount () {
   130         return drainAmount;
   161         return drainAmount;
   131     }
   162     }
       
   163 
       
   164     static long getMaxReqTime () {
       
   165         return maxReqTime;
       
   166     }
       
   167 
       
   168     static long getMaxRspTime () {
       
   169         return maxRspTime;
       
   170     }
       
   171 
       
   172     static long getTimerMillis () {
       
   173         return timerMillis;
       
   174     }
   132 }
   175 }