1 23 package com.sun.enterprise.web.connector.grizzly; 24 25 import java.util.StringTokenizer ; 26 import java.util.logging.Level ; 27 import com.sun.enterprise.web.connector.grizzly.AsyncHandler; 28 29 public class SelectorThreadConfig{ 30 33 private static final String SELECTOR_TIMEOUT = 34 "com.sun.enterprise.web.connector.grizzly.selector.timeout"; 35 36 37 41 private static final String MIN_THREAD= 42 "com.sun.enterprise.web.connector.grizzly.minWorkerThreads"; 43 44 45 48 private final static String NON_BLOCKING_MODE= 49 "com.sun.enterprise.web.connector.grizzly.useNioNonBlocking"; 50 51 54 private final static String DISPLAY_CONFIGURATION= 55 "com.sun.enterprise.web.connector.grizzly.displayConfiguration"; 56 57 58 private final static String MAX_KEEP_ALIVE_REQUEST = 59 "com.sun.enterprise.web.connector.grizzly.maxKeepAliveRequests"; 60 61 62 66 private final static String DIRECT_BYTE_BUFFER_READ = 67 "com.sun.enterprise.web.connector.grizzly.useDirectByteBuffer"; 68 69 73 private final static String PIPELINE_CLASS = 74 "com.sun.enterprise.web.connector.grizzly.pipelineClass"; 75 76 private final static String MAX_SELECTOR_READ_THREAD= 77 "com.sun.enterprise.web.connector.grizzly.maxSelectorReadThread"; 78 private final static String HTTP_HEADER_BUFFER_SIZE = 79 "com.sun.enterprise.web.connector.grizzly.maxHttpHeaderSize"; 80 81 private final static String BYTE_BUFFER_VIEW = 82 "com.sun.enterprise.web.connector.grizzly.useByteBufferView"; 83 84 private final static String ALGORITHM_CLASS_NAME= 85 "com.sun.enterprise.web.connector.grizzly.algorithmClassName"; 86 87 private final static String MAX_SELECTOR = 88 "com.sun.enterprise.web.connector.grizzly.maxSelectors"; 89 90 private final static String FACTORY_TIMEOUT = 91 "com.sun.enterprise.web.connector.grizzly.factoryTimeout"; 92 93 94 private final static String ASYNCH_HANDLER_CLASS = 95 "com.sun.enterprise.web.connector.grizzly.asyncHandlerClass"; 96 97 private final static String ASYNCH_HANDLER_PORT = 98 "com.sun.enterprise.web.connector.grizzly.asyncHandler.ports"; 99 101 102 105 protected static void configureProperties(SelectorThread selectorThread){ 106 if (System.getProperty(SELECTOR_TIMEOUT) != null){ 107 try{ 108 selectorThread.selectorTimeout = 109 Integer.parseInt(System.getProperty(SELECTOR_TIMEOUT)); 110 } catch (NumberFormatException ex){ 111 SelectorThread.logger().log(Level.WARNING, "selectorThread.invalidSelectorTimeout"); 112 } 113 } 114 115 if (System.getProperty(MIN_THREAD) != null){ 116 try{ 117 selectorThread.minWorkerThreads = 118 Integer.parseInt(System.getProperty(MIN_THREAD)); 119 } catch (NumberFormatException ex){ 120 SelectorThread.logger().log(Level.WARNING, "selectorThread.invalidMinThreads"); 121 } 122 } 123 124 if (System.getProperty(NON_BLOCKING_MODE) != null){ 125 selectorThread.useNioNonBlocking = 126 Boolean.valueOf(System.getProperty(NON_BLOCKING_MODE)) 127 .booleanValue(); 128 } 129 130 131 if (System.getProperty(DISPLAY_CONFIGURATION)!= null){ 132 selectorThread.displayConfiguration = 133 Boolean.valueOf(System.getProperty(DISPLAY_CONFIGURATION)) 134 .booleanValue(); 135 } 136 137 if ( System.getProperty(ASYNCH_HANDLER_PORT) != null){ 138 String ports = System.getProperty(ASYNCH_HANDLER_PORT); 139 StringTokenizer st = new StringTokenizer (ports,","); 140 while(st.hasMoreTokens()){ 141 142 if ( st.nextToken() 143 .equals(String.valueOf(selectorThread.getPort())) 144 && System.getProperty(ASYNCH_HANDLER_CLASS)!= null){ 145 146 selectorThread.asyncHandler = (AsyncHandler) 147 loadClassAndInstanciate( 148 System.getProperty(ASYNCH_HANDLER_CLASS)); 149 selectorThread.asyncExecution = true; 150 } 151 } 152 } 153 154 if (System.getProperty(DIRECT_BYTE_BUFFER_READ)!= null){ 155 selectorThread.useDirectByteBuffer = 156 Boolean.valueOf( 157 System.getProperty(DIRECT_BYTE_BUFFER_READ)).booleanValue(); 158 } 159 160 if (System.getProperty(MAX_KEEP_ALIVE_REQUEST) != null){ 161 try{ 162 selectorThread.maxKeepAliveRequests = 163 Integer.parseInt(System.getProperty(MAX_KEEP_ALIVE_REQUEST)); 164 } catch (NumberFormatException ex){ 165 ; 166 } 167 } 168 169 if (System.getProperty(PIPELINE_CLASS)!= null){ 170 selectorThread.pipelineClassName = 171 System.getProperty(PIPELINE_CLASS); 172 } 173 174 if (System.getProperty(ALGORITHM_CLASS_NAME)!= null){ 175 selectorThread.algorithmClassName = 176 System.getProperty(ALGORITHM_CLASS_NAME); 177 } 178 179 if (System.getProperty(BYTE_BUFFER_VIEW)!= null){ 180 selectorThread.useByteBufferView = 181 Boolean.valueOf( 182 System.getProperty(BYTE_BUFFER_VIEW)).booleanValue(); 183 } 184 185 if (System.getProperty(MAX_SELECTOR_READ_THREAD) != null){ 186 try{ 187 selectorThread.selectorReadThreadsCount = 188 Integer.parseInt(System.getProperty(MAX_SELECTOR_READ_THREAD)); 189 } catch (NumberFormatException ex){ 190 ; 191 } 192 } 193 194 if (System.getProperty(MAX_SELECTOR) != null){ 195 try{ 196 SelectorFactory.maxSelectors = 197 Integer.parseInt(System.getProperty(MAX_SELECTOR)); 198 } catch (NumberFormatException ex){ 199 ; 200 } 201 } 202 203 if (System.getProperty(FACTORY_TIMEOUT) != null){ 204 try{ 205 SelectorFactory.timeout = 206 Integer.parseInt(System.getProperty(FACTORY_TIMEOUT)); 207 } catch (NumberFormatException ex){ 208 ; 209 } 210 } 211 212 if (System.getProperty("com.sun.enterprise.web.SubjectDoAs") != null){ 213 org.apache.catalina.security.SecurityUtil.executeUnderSubjectDoAs = 214 Boolean.valueOf(System.getProperty("com.sun.enterprise.web.SubjectDoAs")) 215 .booleanValue(); 216 } 217 } 218 219 220 223 public static void configure(SelectorThread selectorThread){ 224 configureProperties(selectorThread); 225 } 226 227 228 private static Object loadClassAndInstanciate(String className){ 229 try{ 230 Class clazz = Class.forName(className); 231 return clazz.newInstance(); 232 } catch (Throwable ex){ 233 SelectorThread.logger().log(Level.SEVERE,ex.getMessage() 234 + ":" + className, ex); 235 } 236 return null; 237 238 } 239 240 } 241 | Popular Tags |