Save This Page
Home » openjdk-7 » sun » net » httpserver » [javadoc | source]
    1   /*
    2    * Copyright (c) 2005, 2010, 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 com.sun.net.httpserver;
   29   import com.sun.net.httpserver.spi;
   30   import java.util.logging.Logger;
   31   import java.security.PrivilegedAction;
   32   
   33   /**
   34    * Parameters that users will not likely need to set
   35    * but are useful for debugging
   36    */
   37   
   38   class ServerConfig {
   39   
   40       static int clockTick;
   41   
   42       static final int DEFAULT_CLOCK_TICK = 10000 ; // 10 sec.
   43   
   44       /* These values must be a reasonable multiple of clockTick */
   45       static final long DEFAULT_IDLE_INTERVAL = 30 ; // 5 min
   46       static final int DEFAULT_MAX_IDLE_CONNECTIONS = 200 ;
   47   
   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;
   51   
   52       static final long DEFAULT_DRAIN_AMOUNT = 64 * 1024;
   53   
   54       static long idleInterval;
   55       static long drainAmount;    // max # of bytes to drain from an inputstream
   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;
   62       static boolean debug = false;
   63   
   64       static {
   65   
   66           idleInterval = ((Long)java.security.AccessController.doPrivileged(
   67                   new sun.security.action.GetLongAction(
   68                   "sun.net.httpserver.idleInterval",
   69                   DEFAULT_IDLE_INTERVAL))).longValue() * 1000;
   70   
   71           clockTick = ((Integer)java.security.AccessController.doPrivileged(
   72                   new sun.security.action.GetIntegerAction(
   73                   "sun.net.httpserver.clockTick",
   74                   DEFAULT_CLOCK_TICK))).intValue();
   75   
   76           maxIdleConnections = ((Integer)java.security.AccessController.doPrivileged(
   77                   new sun.security.action.GetIntegerAction(
   78                   "sun.net.httpserver.maxIdleConnections",
   79                   DEFAULT_MAX_IDLE_CONNECTIONS))).intValue();
   80   
   81           drainAmount = ((Long)java.security.AccessController.doPrivileged(
   82                   new sun.security.action.GetLongAction(
   83                   "sun.net.httpserver.drainAmount",
   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();
  100   
  101           debug = ((Boolean)java.security.AccessController.doPrivileged(
  102                   new sun.security.action.GetBooleanAction(
  103                   "sun.net.httpserver.debug"))).booleanValue();
  104       }
  105   
  106   
  107       static void checkLegacyProperties (final Logger logger) {
  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           );
  142       }
  143   
  144       static boolean debugEnabled () {
  145           return debug;
  146       }
  147   
  148       static long getIdleInterval () {
  149           return idleInterval;
  150       }
  151   
  152       static int getClockTick () {
  153           return clockTick;
  154       }
  155   
  156       static int getMaxIdleConnections () {
  157           return maxIdleConnections;
  158       }
  159   
  160       static long getDrainAmount () {
  161           return drainAmount;
  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       }
  175   }

Save This Page
Home » openjdk-7 » sun » net » httpserver » [javadoc | source]