KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > web > connector > grizzly > SelectorThreadConfig


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.enterprise.web.connector.grizzly;
24
25 import java.util.StringTokenizer JavaDoc;
26 import java.util.logging.Level JavaDoc;
27 import com.sun.enterprise.web.connector.grizzly.AsyncHandler;
28
29 public class SelectorThreadConfig{
30     /**
31      * System property for the selector timeout value.
32      */

33     private static final String JavaDoc SELECTOR_TIMEOUT =
34                 "com.sun.enterprise.web.connector.grizzly.selector.timeout";
35
36     
37     /**
38      * The minimum number of threads used when creating a new
39      * <code>Pipeline</code>
40      */

41     private static final String JavaDoc MIN_THREAD=
42                "com.sun.enterprise.web.connector.grizzly.minWorkerThreads";
43     
44     
45     /**
46      * Property used to turn on/off NIO blocking mode.
47      */

48     private final static String JavaDoc NON_BLOCKING_MODE=
49                    "com.sun.enterprise.web.connector.grizzly.useNioNonBlocking";
50
51     /**
52      * Property used to turn on/off NIO blocking mode.
53      */

54     private final static String JavaDoc DISPLAY_CONFIGURATION=
55                 "com.sun.enterprise.web.connector.grizzly.displayConfiguration";
56
57
58     private final static String JavaDoc MAX_KEEP_ALIVE_REQUEST =
59                "com.sun.enterprise.web.connector.grizzly.maxKeepAliveRequests";
60
61
62     /**
63      * Is the <code>ByteBuffer</code> used by the <code>ReadTask</code> use
64      * direct <code>ByteBuffer</code> or not.
65      */

66     private final static String JavaDoc DIRECT_BYTE_BUFFER_READ =
67                "com.sun.enterprise.web.connector.grizzly.useDirectByteBuffer";
68  
69     /**
70      * Always attach a <code>ProcessorTask</code> when creating
71      * a <code>ReadTask</code>
72      */

73     private final static String JavaDoc PIPELINE_CLASS =
74                "com.sun.enterprise.web.connector.grizzly.pipelineClass";
75
76     private final static String JavaDoc MAX_SELECTOR_READ_THREAD=
77                "com.sun.enterprise.web.connector.grizzly.maxSelectorReadThread";
78     private final static String JavaDoc HTTP_HEADER_BUFFER_SIZE =
79                "com.sun.enterprise.web.connector.grizzly.maxHttpHeaderSize";
80     
81     private final static String JavaDoc BYTE_BUFFER_VIEW =
82                "com.sun.enterprise.web.connector.grizzly.useByteBufferView";
83
84     private final static String JavaDoc ALGORITHM_CLASS_NAME=
85         "com.sun.enterprise.web.connector.grizzly.algorithmClassName";
86     
87     private final static String JavaDoc MAX_SELECTOR =
88         "com.sun.enterprise.web.connector.grizzly.maxSelectors";
89     
90     private final static String JavaDoc FACTORY_TIMEOUT =
91         "com.sun.enterprise.web.connector.grizzly.factoryTimeout";
92     
93     
94     private final static String JavaDoc ASYNCH_HANDLER_CLASS =
95         "com.sun.enterprise.web.connector.grizzly.asyncHandlerClass";
96     
97     private final static String JavaDoc ASYNCH_HANDLER_PORT =
98         "com.sun.enterprise.web.connector.grizzly.asyncHandler.ports";
99     // --------------------------------------------------------- Static -----//
100

101
102    /**
103      * Read systems properties and configure the <code>SelectorThread</code>.
104      */

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 JavaDoc 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 JavaDoc 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 JavaDoc ports = System.getProperty(ASYNCH_HANDLER_PORT);
139             StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(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 JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc 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     /**
221      * Configure properties on <code>SelectorThread</code>
222      */

223     public static void configure(SelectorThread selectorThread){
224         configureProperties(selectorThread);
225     }
226
227     
228     private static Object JavaDoc loadClassAndInstanciate(String JavaDoc className){
229          try{
230             Class JavaDoc clazz = Class.forName(className);
231             return clazz.newInstance();
232         } catch (Throwable JavaDoc ex){
233             SelectorThread.logger().log(Level.SEVERE,ex.getMessage()
234                 + ":" + className, ex);
235         }
236         return null;
237         
238     }
239
240 }
241
Popular Tags