KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > web > connector > coyote > PECoyoteConnector


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
24 package com.sun.enterprise.web.connector.coyote;
25
26 import com.sun.enterprise.web.connector.extension.GrizzlyConfig;
27 import java.lang.reflect.Method JavaDoc;
28 import java.util.logging.Level JavaDoc;
29 import java.util.logging.Logger JavaDoc;
30 import org.apache.catalina.Request;
31 import org.apache.catalina.Response;
32 import org.apache.coyote.tomcat5.CoyoteConnector;
33 import org.apache.coyote.tomcat5.CoyoteResponse;
34 import org.apache.coyote.tomcat5.Constants;
35
36 import org.apache.catalina.LifecycleException;
37
38 public class PECoyoteConnector extends CoyoteConnector{
39
40     private static final String JavaDoc USE_COYOTE_CONNECTOR =
41                 "com.sun.enterprise.web.connector.useCoyoteConnector";
42
43     private static final String JavaDoc GRIZZLY_CONNECTOR =
44                 "com.sun.enterprise.web.connector.grizzly.GrizzlyHttpProtocol";
45
46    
47     /**
48      * Are we recycling objects
49      */

50     protected boolean recycleObjects;
51     
52     
53      /**
54      * The number of acceptor threads.
55      */

56     protected int maxAcceptWorkerThreads;
57     
58     
59     /**
60      * The number of reader threads.
61      */

62     protected int maxReadWorkerThreads;
63     
64     
65     /**
66      * The request timeout value used by the processor threads.
67      */

68     protected int processorWorkerThreadsTimeout;
69     
70     
71     /**
72      * The increment number used by the processor threads.
73      */

74     protected int minProcessorWorkerThreadsIncrement;
75     
76     
77     /**
78      * The size of the accept queue.
79      */

80     protected int minAcceptQueueLength;
81     
82     
83     /**
84      * The size of the read queue
85      */

86     protected int minReadQueueLength;
87     
88     
89     /**
90      * The size of the processor queue.
91      */

92     protected int minProcessorQueueLength;
93     
94     
95     /**
96      * Use direct or non direct byte buffer.
97      */

98     protected boolean useDirectByteBuffer;
99     
100     
101     // Are we using the NIO Connector or the CoyoteConnector
102
private boolean coyoteOn = false;
103     
104     /*
105      * Number of seconds before idle keep-alive connections expire
106      */

107     private int keepAliveTimeoutInSeconds;
108
109     /*
110      * Number of keep-alive threads
111      */

112     private int keepAliveThreadCount;
113
114     /*
115      * Specifies whether response chunking is enabled/disabled
116      */

117     private boolean chunkingDisabled;
118
119     /**
120      * Maximum pending connection before refusing requests.
121      */

122     private int queueSizeInBytes = 4096;
123   
124     /**
125      * Server socket backlog.
126      */

127     protected int ssBackLog = 4096;
128     
129     
130     /**
131      * Set the number of <code>Selector</code> used by Grizzly.
132      */

133     public int selectorReadThreadsCount = 0;
134     
135       
136     /**
137      * The default response-type
138      */

139     protected String JavaDoc defaultResponseType = Constants.DEFAULT_RESPONSE_TYPE;
140
141
142     /**
143      * The forced response-type
144      */

145     protected String JavaDoc forcedResponseType = Constants.DEFAULT_RESPONSE_TYPE;
146     
147     /**
148      * The monitoring classes used to gather stats.
149      */

150     private GrizzlyConfig grizzlyMonitor;
151     
152     
153     /**
154      * The JMX domain.
155      */

156     private String JavaDoc domain;
157     
158     
159     /**
160      * The root folder where application are deployed
161      */

162     private String JavaDoc rootFolder = "";
163     
164     
165     /**
166      * The http-listener name
167      */

168     private String JavaDoc name;
169     // ------------------------------------------------- FileCache support --//
170

171     /**
172      * Timeout before remove the static resource from the cache.
173      */

174     private int secondsMaxAge = -1;
175     
176     
177     /**
178      * The maximum entries in the <code>fileCache</code>
179      */

180     private int maxCacheEntries = 1024;
181     
182  
183     /**
184      * The maximum size of a cached resources.
185      */

186     private long minEntrySize = 2048;
187             
188                
189     /**
190      * The maximum size of a cached resources.
191      */

192     private long maxEntrySize = 537600;
193     
194     
195     /**
196      * The maximum cached bytes
197      */

198     private long maxLargeFileCacheSize = 10485760;
199  
200     
201     /**
202      * The maximum cached bytes
203      */

204     private long maxSmallFileCacheSize = 1048576;
205     
206     
207     /**
208      * Is the FileCache enabled.
209      */

210     private boolean fileCacheEnabled = true;
211     
212     
213     /**
214      * Is the large FileCache enabled.
215      */

216     private boolean isLargeFileCacheEnabled = true;
217     
218     
219     /**
220      * The logger used by the <code>ProtocolHandler</code>
221      */

222     private Logger JavaDoc logger;
223
224     // ----------------------------------------------------------------------//
225

226     
227     public PECoyoteConnector() {
228         boolean coyoteOn = false;
229         if (System.getProperty(USE_COYOTE_CONNECTOR) != null){
230             coyoteOn =
231                    Boolean.valueOf(System.getProperty(USE_COYOTE_CONNECTOR))
232                                                                .booleanValue();
233         }
234         
235         // By default, turn on the Coyote Connector
236
if (!coyoteOn)
237             setProtocolHandlerClassName(GRIZZLY_CONNECTOR);
238     }
239     
240
241     /**
242      * Enables or disables chunked encoding for any responses returned by this
243      * Connector.
244      *
245      * @param chunkingDisabled true if chunking is to be disabled, false
246      * otherwise
247      */

248     public void setChunkingDisabled(boolean chunkingDisabled) {
249         this.chunkingDisabled = chunkingDisabled;
250     }
251
252
253     /**
254      * @return true if chunking is disabled on this Connector, and false
255      * otherwise
256      */

257     public boolean isChunkingDisabled() {
258         return this.chunkingDisabled;
259     }
260
261
262     /**
263      * Create (or allocate) and return a Request object suitable for
264      * specifying the contents of a Request to the responsible Container.
265      */

266     public Request createRequest() {
267         
268         PwcCoyoteRequest request = new PwcCoyoteRequest();
269         request.setConnector(this);
270         return (request);
271
272     }
273
274
275     /**
276      * Creates and returns Response object.
277      *
278      * @return Response object
279      */

280     public Response createResponse() {
281
282         CoyoteResponse response = new CoyoteResponse(isChunkingDisabled());
283         response.setConnector(this);
284         return (response);
285
286     }
287
288
289     /**
290      * Gets the number of seconds before a keep-alive connection that has
291      * been idle times out and is closed.
292      *
293      * @return Keep-alive timeout in number of seconds
294      */

295     public int getKeepAliveTimeoutInSeconds() {
296         return keepAliveTimeoutInSeconds;
297     }
298
299
300     /**
301      * Sets the number of seconds before a keep-alive connection that has
302      * been idle times out and is closed.
303      *
304      * @param timeout Keep-alive timeout in number of seconds
305      */

306     public void setKeepAliveTimeoutInSeconds(int timeout) {
307         keepAliveTimeoutInSeconds = timeout;
308         setProperty("keepAliveTimeoutInSeconds", String.valueOf(timeout));
309     }
310
311
312     /**
313      * Gets the number of keep-alive threads.
314      *
315      * @return Number of keep-alive threads
316      */

317     public int getKeepAliveThreadCount() {
318         return keepAliveThreadCount;
319     }
320
321
322     /**
323      * Sets the number of keep-alive threads.
324      *
325      * @param threadCount Number of keep-alive threads
326      */

327     public void setKeepAliveThreadCount(int threadCount) {
328         keepAliveThreadCount = threadCount;
329         setProperty("keepAliveThreadCount", String.valueOf(threadCount));
330     }
331
332
333     /**
334      * Set the maximum pending connection this <code>Connector</code>
335      * can handle.
336      */

337     public void setQueueSizeInBytes(int queueSizeInBytes){
338         this.queueSizeInBytes = queueSizeInBytes;
339         setProperty("queueSizeInBytes", queueSizeInBytes);
340     }
341
342
343     /**
344      * Return the maximum pending connection.
345      */

346     public int getQueueSizeInBytes(){
347         return queueSizeInBytes;
348     }
349
350  
351     /**
352      * Set the <code>SocketServer</code> backlog.
353      */

354     public void setSocketServerBacklog(int ssBackLog){
355         this.ssBackLog = ssBackLog;
356         setProperty("socketServerBacklog", ssBackLog);
357     }
358
359
360     /**
361      * Return the maximum pending connection.
362      */

363     public int getSocketServerBacklog(){
364         return ssBackLog;
365     }
366
367     
368     /**
369      * Set the <code>recycle-tasks</code> used by this <code>Selector</code>
370      */

371     public void setRecycleObjects(boolean recycleObjects){
372         this.recycleObjects= recycleObjects;
373         setProperty("recycleObjects",
374                     String.valueOf(recycleObjects));
375     }
376     
377     
378     /**
379      * Return the <code>recycle-tasks</code> used by this
380      * <code>Selector</code>
381      */

382     public boolean getRecycleObjects(){
383         return recycleObjects;
384     }
385    
386    
387     /**
388      * Set the <code>reader-thread</code> from domian.xml.
389      */

390     public void setMaxReadWorkerThreads(int maxReadWorkerThreads){
391         this.maxReadWorkerThreads = maxReadWorkerThreads;
392         setProperty("maxReadWorkerThreads",
393                     String.valueOf(maxReadWorkerThreads));
394     }
395     
396     
397     /**
398      * Return the <code>read-thread</code> used by this <code>Selector</code>
399      */

400     public int getMaxReadWorkerThreads(){
401         return maxReadWorkerThreads;
402     }
403
404     
405     /**
406      * Set the <code>reader-thread</code> from domian.xml.
407      */

408     public void setMaxAcceptWorkerThreads(int maxAcceptWorkerThreads){
409         this.maxAcceptWorkerThreads = maxAcceptWorkerThreads;
410         setProperty("maxAcceptWorkerThreads",
411                     String.valueOf(maxAcceptWorkerThreads));
412     }
413     
414     
415     /**
416      * Return the <code>read-thread</code> used by this <code>Selector</code>
417      */

418     public int getMaxAcceptWorkerThreads(){
419         return maxAcceptWorkerThreads;
420     }
421     
422     
423     /**
424      * Set the <code>acceptor-queue-length</code> value
425      * on this <code>Selector</code>
426      */

427     public void setMinAcceptQueueLength(int minAcceptQueueLength){
428         this.minAcceptQueueLength = minAcceptQueueLength;
429         setProperty("minAcceptQueueLength",
430                     String.valueOf(minAcceptQueueLength));
431     }
432  
433     
434     /**
435      * Return the <code>acceptor-queue-length</code> value
436      * on this <code>Selector</code>
437      */

438     public int getMinAcceptQueueLength(){
439         return minAcceptQueueLength;
440     }
441     
442     
443     /**
444      * Set the <code>reader-queue-length</code> value
445      * on this <code>Selector</code>
446      */

447     public void setMinReadQueueLength(int minReadQueueLength){
448         this.minReadQueueLength = minReadQueueLength;
449         setProperty("minReadQueueLength",
450                     String.valueOf(minReadQueueLength));
451     }
452     
453     
454     /**
455      * Return the <code>reader-queue-length</code> value
456      * on this <code>Selector</code>
457      */

458     public int getMinReadQueueLength(){
459         return minReadQueueLength;
460     }
461     
462     
463     /**
464      * Set the <code>processor-queue-length</code> value
465      * on this <code>Selector</code>
466      */

467     public void setMinProcessorQueueLength(int minProcessorQueueLength){
468         this.minProcessorQueueLength = minProcessorQueueLength;
469         setProperty("minProcessorQueueLength",
470                     String.valueOf(minProcessorQueueLength));
471     }
472     
473     
474     /**
475      * Return the <code>processor-queue-length</code> value
476      * on this <code>Selector</code>
477      */

478     public int getMinProcessorQueueLength(){
479         return minProcessorQueueLength;
480     }
481     
482     
483     /**
484      * Set the <code>use-nio-non-blocking</code> by this <code>Selector</code>
485      */

486     public void setUseDirectByteBuffer(boolean useDirectByteBuffer){
487         this.useDirectByteBuffer = useDirectByteBuffer;
488         setProperty("useDirectByteBuffer",
489                     String.valueOf(useDirectByteBuffer));
490     }
491     
492     
493     /**
494      * Return the <code>use-nio-non-blocking</code> used by this
495      * <code>Selector</code>
496      */

497     public boolean getUseDirectByteBuffer(){
498         return useDirectByteBuffer;
499     }
500
501     
502     public void setProcessorWorkerThreadsTimeout(int timeout){
503         this.processorWorkerThreadsTimeout = timeout;
504         setProperty("processorWorkerThreadsTimeout",
505                     String.valueOf(timeout));
506     }
507     
508     
509     public int getProcessorWorkerThreadsTimeout(){
510         return processorWorkerThreadsTimeout;
511     }
512     
513     
514     public void setProcessorWorkerThreadsIncrement(int increment){
515         this.minProcessorWorkerThreadsIncrement = increment;
516         setProperty("processorThreadsIncrement",
517                     String.valueOf(increment));
518     }
519     
520     
521     public int getMinProcessorWorkerThreadsIncrement(){
522         return minProcessorWorkerThreadsIncrement;
523     }
524  
525     public void setSelectorReadThreadsCount(int selectorReadThreadsCount){
526         setProperty("selectorReadThreadsCount",
527                      String.valueOf(selectorReadThreadsCount));
528     }
529     
530     
531     /**
532      * Set the default response type used. Specified as a semi-colon
533      * delimited string consisting of content-type, encoding,
534      * language, charset
535      */

536     public void setDefaultResponseType(String JavaDoc defaultResponseType){
537         this.defaultResponseType = defaultResponseType;
538         setProperty("defaultResponseType", defaultResponseType);
539     }
540
541
542     /**
543      * Return the default response type used
544      */

545     public String JavaDoc getDefaultResponseType(){
546          return defaultResponseType;
547     }
548     
549     
550     /**
551      * Set the forced response type used. The response type to be forced
552      * if the content served cannot be matched by any of the MIME mappings
553      * for extensions. Specified as a semi-colon delimited string consisting of
554      * content-type, encoding, language, charset
555      */

556     public void setForcedResponseType(String JavaDoc forcedResponseType){
557         this.forcedResponseType = forcedResponseType;
558         setProperty("forcedResponseType", forcedResponseType);
559     }
560     
561         
562     /**
563      * Return the default response type used
564      */

565     public String JavaDoc getForcedResponseType(){
566         return forcedResponseType;
567     }
568     
569     
570     /**
571      * Set the domain of this object.
572      */

573     public void setDomain(String JavaDoc domain){
574         this.domain = domain;
575     }
576     
577     
578     public void start() throws LifecycleException {
579         super.start();
580         if ( grizzlyMonitor != null ) {
581             grizzlyMonitor.initConfig();
582             grizzlyMonitor.registerMonitoringLevelEvents();
583         }
584     }
585     
586     
587     public void stop() throws LifecycleException {
588         super.stop();
589         if ( grizzlyMonitor != null ) {
590             grizzlyMonitor.unregisterMonitoringLevelEvents();
591         }
592     }
593    //------------------------------------------------- FileCache config -----/
594

595    
596     /**
597      * The timeout in seconds before remove a <code>FileCacheEntry</code>
598      * from the <code>fileCache</code>
599      */

600     public void setSecondsMaxAge(int sMaxAges){
601         secondsMaxAge = sMaxAges;
602         setProperty("secondsMaxAge", String.valueOf(secondsMaxAge));
603     }
604     
605     
606     /**
607      * Set the maximum entries this cache can contains.
608      */

609     public void setMaxCacheEntries(int mEntries){
610         maxCacheEntries = mEntries;
611         setProperty("maxCacheEntries", String.valueOf(maxCacheEntries));
612     }
613
614     
615     /**
616      * Return the maximum entries this cache can contains.
617      */

618     public int getMaxCacheEntries(){
619         return maxCacheEntries;
620     }
621     
622     
623     /**
624      * Set the maximum size a <code>FileCacheEntry</code> can have.
625      */

626     public void setMinEntrySize(long mSize){
627         minEntrySize = mSize;
628         setProperty("minEntrySize", String.valueOf(minEntrySize));
629     }
630     
631     
632     /**
633      * Get the maximum size a <code>FileCacheEntry</code> can have.
634      */

635     public long getMinEntrySize(){
636         return minEntrySize;
637     }
638      
639     
640     /**
641      * Set the maximum size a <code>FileCacheEntry</code> can have.
642      */

643     public void setMaxEntrySize(long mEntrySize){
644         maxEntrySize = mEntrySize;
645         setProperty("maxEntrySize", String.valueOf(maxEntrySize));
646     }
647     
648     
649     /**
650      * Get the maximum size a <code>FileCacheEntry</code> can have.
651      */

652     public long getMaxEntrySize(){
653         return maxEntrySize;
654     }
655     
656     
657     /**
658      * Set the maximum cache size
659      */

660     public void setMaxLargeCacheSize(long mCacheSize){
661         maxLargeFileCacheSize = mCacheSize;
662         setProperty("maxLargeFileCacheSize",
663                 String.valueOf(maxLargeFileCacheSize));
664     }
665
666     
667     /**
668      * Get the maximum cache size
669      */

670     public long getMaxLargeCacheSize(){
671         return maxLargeFileCacheSize;
672     }
673     
674     
675     /**
676      * Set the maximum cache size
677      */

678     public void setMaxSmallCacheSize(long mCacheSize){
679         maxSmallFileCacheSize = mCacheSize;
680         setProperty("maxSmallFileCacheSize",
681                 String.valueOf(maxSmallFileCacheSize));
682     }
683     
684     
685     /**
686      * Get the maximum cache size
687      */

688     public long getMaxSmallCacheSize(){
689         return maxSmallFileCacheSize;
690     }
691
692     
693     /**
694      * Is the fileCache enabled.
695      */

696     public boolean isFileCacheEnabled(){
697         return fileCacheEnabled;
698     }
699
700     
701     /**
702      * Is the file caching mechanism enabled.
703      */

704     public void setFileCacheEnabled(boolean fileCacheEnabled){
705         this.fileCacheEnabled = fileCacheEnabled;
706         setProperty("fileCacheEnabled",String.valueOf(fileCacheEnabled));
707     }
708    
709     
710     /**
711      * Is the large file cache support enabled.
712      */

713     public void setLargeFileCacheEnabled(boolean isLargeEnabled){
714         this.isLargeFileCacheEnabled = isLargeEnabled;
715         setProperty("largeFileCacheEnabled",
716                 String.valueOf(isLargeFileCacheEnabled));
717     }
718    
719     
720     /**
721      * Is the large file cache support enabled.
722      */

723     public boolean getLargeFileCacheEnabled(){
724         return isLargeFileCacheEnabled;
725     }
726
727     // --------------------------------------------------------------------//
728

729     
730     /**
731      * Set the documenr root folder
732      */

733     public void setWebAppRootPath(String JavaDoc rootFolder){
734         this.rootFolder = rootFolder;
735         setProperty("webAppRootPath",rootFolder);
736     }
737     
738     
739     /**
740      * Return the folder's root where application are deployed.
741      */

742     public String JavaDoc getWebAppRootPath(){
743         return rootFolder;
744     }
745     
746     
747     /**
748      * Set the <code>Logger</code> of the <code>ProtocolHandler</code> instance
749      * used by this class.
750      */

751     public void setLogger(Logger JavaDoc logger){
752         this.logger = logger;
753     }
754     
755     
756     /**
757      * Initialize this connector.
758      */

759     public void initialize() throws LifecycleException{
760         super.initialize();
761         
762         if ( !getProtocolHandler().getClass()
763                 .getName().equals(GRIZZLY_CONNECTOR)){
764             return;
765         }
766  
767         // Set the monitoring.
768
grizzlyMonitor = new GrizzlyConfig(domain,getPort());
769  
770         // Set the logger
771
try{
772             Method JavaDoc loggerMethod = getProtocolHandler().getClass().getMethod
773                    ("setLogger", new Class JavaDoc[]{java.util.logging.Logger JavaDoc.class});
774             loggerMethod.invoke(getProtocolHandler(), new Object JavaDoc[]{logger});
775         } catch(Exception JavaDoc ex) {
776             logger.log(Level.WARNING,
777                     "Unable to set logger on " + getProtocolHandler(), ex);
778         }
779     }
780     
781     
782     /**
783      * Set the name of this connector.
784      */

785     public void setName(String JavaDoc name){
786         this.name = name;
787     }
788     
789     
790     /**
791      * Get the name of this connector;
792      */

793     public String JavaDoc getName(){
794         return name;
795     }
796 }
797
798
Popular Tags