Source Code Cross Referenced for Http11NioProtocol.java in  » Sevlet-Container » apache-tomcat-6.0.14 » org » apache » coyote » http11 » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Sevlet Container » apache tomcat 6.0.14 » org.apache.coyote.http11 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */
017:
018:        package org.apache.coyote.http11;
019:
020:        import java.net.InetAddress;
021:        import java.net.URLEncoder;
022:        import java.util.Hashtable;
023:        import java.util.Iterator;
024:        import java.util.concurrent.ConcurrentHashMap;
025:        import java.util.concurrent.ConcurrentLinkedQueue;
026:        import java.util.concurrent.Executor;
027:        import java.util.concurrent.atomic.AtomicInteger;
028:        import javax.management.MBeanRegistration;
029:        import javax.management.MBeanServer;
030:        import javax.management.ObjectName;
031:
032:        import org.apache.coyote.ActionCode;
033:        import org.apache.coyote.ActionHook;
034:        import org.apache.coyote.Adapter;
035:        import org.apache.coyote.ProtocolHandler;
036:        import org.apache.coyote.RequestGroupInfo;
037:        import org.apache.coyote.RequestInfo;
038:        import org.apache.tomcat.util.modeler.Registry;
039:        import org.apache.tomcat.util.net.NioChannel;
040:        import org.apache.tomcat.util.net.NioEndpoint;
041:        import org.apache.tomcat.util.net.NioEndpoint.Handler;
042:        import org.apache.tomcat.util.net.SSLImplementation;
043:        import org.apache.tomcat.util.net.SecureNioChannel;
044:        import org.apache.tomcat.util.net.SocketStatus;
045:        import org.apache.tomcat.util.res.StringManager;
046:
047:        /**
048:         * Abstract the protocol implementation, including threading, etc.
049:         * Processor is single threaded and specific to stream-based protocols,
050:         * will not fit Jk protocols like JNI.
051:         *
052:         * @author Remy Maucherat
053:         * @author Costin Manolache
054:         * @author Filip Hanik
055:         */
056:        public class Http11NioProtocol implements  ProtocolHandler,
057:                MBeanRegistration {
058:            protected SSLImplementation sslImplementation = null;
059:
060:            public Http11NioProtocol() {
061:                cHandler = new Http11ConnectionHandler(this );
062:                setSoLinger(Constants.DEFAULT_CONNECTION_LINGER);
063:                setSoTimeout(Constants.DEFAULT_CONNECTION_TIMEOUT);
064:                //setServerSoTimeout(Constants.DEFAULT_SERVER_SOCKET_TIMEOUT);
065:                setTcpNoDelay(Constants.DEFAULT_TCP_NO_DELAY);
066:            }
067:
068:            /**
069:             * The string manager for this package.
070:             */
071:            protected static StringManager sm = StringManager
072:                    .getManager(Constants.Package);
073:
074:            /** Pass config info
075:             */
076:            public void setAttribute(String name, Object value) {
077:                if (log.isTraceEnabled())
078:                    log.trace(sm.getString("http11protocol.setattribute", name,
079:                            value));
080:
081:                attributes.put(name, value);
082:            }
083:
084:            public Object getAttribute(String key) {
085:                if (log.isTraceEnabled())
086:                    log.trace(sm.getString("http11protocol.getattribute", key));
087:                return attributes.get(key);
088:            }
089:
090:            public Iterator getAttributeNames() {
091:                return attributes.keySet().iterator();
092:            }
093:
094:            /**
095:             * Set a property.
096:             */
097:            public void setProperty(String name, String value) {
098:                if (name != null
099:                        && (name.startsWith("socket.") || name
100:                                .startsWith("selectorPool."))) {
101:                    ep.setProperty(name, value);
102:                } else {
103:                    ep.setProperty(name, value); //make sure we at least try to set all properties
104:                }
105:                setAttribute(name, value);
106:            }
107:
108:            /**
109:             * Get a property
110:             */
111:            public String getProperty(String name) {
112:                return (String) getAttribute(name);
113:            }
114:
115:            /** The adapter, used to call the connector
116:             */
117:            public void setAdapter(Adapter adapter) {
118:                this .adapter = adapter;
119:            }
120:
121:            public Adapter getAdapter() {
122:                return adapter;
123:            }
124:
125:            /** Start the protocol
126:             */
127:            public void init() throws Exception {
128:                ep.setName(getName());
129:                ep.setHandler(cHandler);
130:
131:                //todo, determine if we even need these
132:                ep.getSocketProperties().setRxBufSize(
133:                        Math.max(ep.getSocketProperties().getRxBufSize(),
134:                                getMaxHttpHeaderSize()));
135:                ep.getSocketProperties().setTxBufSize(
136:                        Math.max(ep.getSocketProperties().getTxBufSize(),
137:                                getMaxHttpHeaderSize()));
138:
139:                try {
140:                    ep.init();
141:                    sslImplementation = SSLImplementation
142:                            .getInstance("org.apache.tomcat.util.net.jsse.JSSEImplementation");
143:                } catch (Exception ex) {
144:                    log.error(
145:                            sm.getString("http11protocol.endpoint.initerror"),
146:                            ex);
147:                    throw ex;
148:                }
149:                if (log.isInfoEnabled())
150:                    log.info(sm.getString("http11protocol.init", getName()));
151:
152:            }
153:
154:            ObjectName tpOname;
155:            ObjectName rgOname;
156:
157:            public void start() throws Exception {
158:                if (this .domain != null) {
159:                    try {
160:                        tpOname = new ObjectName(domain + ":"
161:                                + "type=ThreadPool,name=" + getName());
162:                        Registry.getRegistry(null, null).registerComponent(ep,
163:                                tpOname, null);
164:                    } catch (Exception e) {
165:                        log.error("Can't register threadpool");
166:                    }
167:                    rgOname = new ObjectName(domain
168:                            + ":type=GlobalRequestProcessor,name=" + getName());
169:                    Registry.getRegistry(null, null).registerComponent(
170:                            cHandler.global, rgOname, null);
171:                }
172:
173:                try {
174:                    ep.start();
175:                } catch (Exception ex) {
176:                    log.error(sm
177:                            .getString("http11protocol.endpoint.starterror"),
178:                            ex);
179:                    throw ex;
180:                }
181:                if (log.isInfoEnabled())
182:                    log.info(sm.getString("http11protocol.start", getName()));
183:            }
184:
185:            public void pause() throws Exception {
186:                try {
187:                    ep.pause();
188:                } catch (Exception ex) {
189:                    log.error(sm
190:                            .getString("http11protocol.endpoint.pauseerror"),
191:                            ex);
192:                    throw ex;
193:                }
194:                if (log.isInfoEnabled())
195:                    log.info(sm.getString("http11protocol.pause", getName()));
196:            }
197:
198:            public void resume() throws Exception {
199:                try {
200:                    ep.resume();
201:                } catch (Exception ex) {
202:                    log.error(sm
203:                            .getString("http11protocol.endpoint.resumeerror"),
204:                            ex);
205:                    throw ex;
206:                }
207:                if (log.isInfoEnabled())
208:                    log.info(sm.getString("http11protocol.resume", getName()));
209:            }
210:
211:            public void destroy() throws Exception {
212:                if (log.isInfoEnabled())
213:                    log.info(sm.getString("http11protocol.stop", getName()));
214:                ep.destroy();
215:                if (tpOname != null)
216:                    Registry.getRegistry(null, null).unregisterComponent(
217:                            tpOname);
218:                if (rgOname != null)
219:                    Registry.getRegistry(null, null).unregisterComponent(
220:                            rgOname);
221:            }
222:
223:            // -------------------- Properties--------------------
224:            protected NioEndpoint ep = new NioEndpoint();
225:            protected boolean secure = false;
226:
227:            protected Hashtable attributes = new Hashtable();
228:
229:            private int maxKeepAliveRequests = 100; // as in Apache HTTPD server
230:            private int timeout = 300000; // 5 minutes as in Apache HTTPD server
231:            private int maxSavePostSize = 4 * 1024;
232:            private int maxHttpHeaderSize = 8 * 1024;
233:            protected int processorCache = 200; //max number of Http11NioProcessor objects cached
234:            private int socketCloseDelay = -1;
235:            private boolean disableUploadTimeout = true;
236:            private int socketBuffer = 9000;
237:
238:            private Adapter adapter;
239:            private Http11ConnectionHandler cHandler;
240:
241:            /**
242:             * Compression value.
243:             */
244:            private String compression = "off";
245:            private String noCompressionUserAgents = null;
246:            private String restrictedUserAgents = null;
247:            private String compressableMimeTypes = "text/html,text/xml,text/plain";
248:            private int compressionMinSize = 2048;
249:
250:            private String server;
251:
252:            // -------------------- Pool setup --------------------
253:
254:            public void setPollerThreadCount(int count) {
255:                ep.setPollerThreadCount(count);
256:            }
257:
258:            public int getPollerThreadCount() {
259:                return ep.getPollerThreadCount();
260:            }
261:
262:            public void setSelectorTimeout(long timeout) {
263:                ep.setSelectorTimeout(timeout);
264:            }
265:
266:            public long getSelectorTimeout() {
267:                return ep.getSelectorTimeout();
268:            }
269:
270:            // *
271:            public Executor getExecutor() {
272:                return ep.getExecutor();
273:            }
274:
275:            // *
276:            public void setExecutor(Executor executor) {
277:                ep.setExecutor(executor);
278:            }
279:
280:            public void setUseExecutor(boolean useexec) {
281:                ep.setUseExecutor(useexec);
282:            }
283:
284:            public int getMaxThreads() {
285:                return ep.getMaxThreads();
286:            }
287:
288:            public void setMaxThreads(int maxThreads) {
289:                ep.setMaxThreads(maxThreads);
290:                setAttribute("maxThreads", "" + maxThreads);
291:            }
292:
293:            public void setThreadPriority(int threadPriority) {
294:                ep.setThreadPriority(threadPriority);
295:                setAttribute("threadPriority", "" + threadPriority);
296:            }
297:
298:            public void setAcceptorThreadPriority(int threadPriority) {
299:                ep.setAcceptorThreadPriority(threadPriority);
300:                setAttribute("acceptorThreadPriority", "" + threadPriority);
301:            }
302:
303:            public void setPollerThreadPriority(int threadPriority) {
304:                ep.setPollerThreadPriority(threadPriority);
305:                setAttribute("pollerThreadPriority", "" + threadPriority);
306:            }
307:
308:            public int getThreadPriority() {
309:                return ep.getThreadPriority();
310:            }
311:
312:            public int getAcceptorThreadPriority() {
313:                return ep.getAcceptorThreadPriority();
314:            }
315:
316:            public int getPollerThreadPriority() {
317:                return ep.getThreadPriority();
318:            }
319:
320:            public boolean getUseSendfile() {
321:                return ep.getUseSendfile();
322:            }
323:
324:            public void setUseSendfile(boolean useSendfile) {
325:                ep.setUseSendfile(useSendfile);
326:            }
327:
328:            // -------------------- Tcp setup --------------------
329:
330:            public int getBacklog() {
331:                return ep.getBacklog();
332:            }
333:
334:            public void setBacklog(int i) {
335:                ep.setBacklog(i);
336:                setAttribute("backlog", "" + i);
337:            }
338:
339:            public int getPort() {
340:                return ep.getPort();
341:            }
342:
343:            public void setPort(int port) {
344:                ep.setPort(port);
345:                setAttribute("port", "" + port);
346:            }
347:
348:            public InetAddress getAddress() {
349:                return ep.getAddress();
350:            }
351:
352:            public void setAddress(InetAddress ia) {
353:                ep.setAddress(ia);
354:                setAttribute("address", "" + ia);
355:            }
356:
357:            public String getName() {
358:                String encodedAddr = "";
359:                if (getAddress() != null) {
360:                    encodedAddr = "" + getAddress();
361:                    if (encodedAddr.startsWith("/"))
362:                        encodedAddr = encodedAddr.substring(1);
363:                    encodedAddr = URLEncoder.encode(encodedAddr) + "-";
364:                }
365:                return ("http-" + encodedAddr + ep.getPort());
366:            }
367:
368:            public boolean getTcpNoDelay() {
369:                return ep.getTcpNoDelay();
370:            }
371:
372:            public void setTcpNoDelay(boolean b) {
373:                ep.setTcpNoDelay(b);
374:                setAttribute("tcpNoDelay", "" + b);
375:            }
376:
377:            public boolean getDisableUploadTimeout() {
378:                return disableUploadTimeout;
379:            }
380:
381:            public void setDisableUploadTimeout(boolean isDisabled) {
382:                disableUploadTimeout = isDisabled;
383:            }
384:
385:            public int getSocketBuffer() {
386:                return socketBuffer;
387:            }
388:
389:            public void setSocketBuffer(int valueI) {
390:                socketBuffer = valueI;
391:            }
392:
393:            public String getCompression() {
394:                return compression;
395:            }
396:
397:            public void setCompression(String valueS) {
398:                compression = valueS;
399:                setAttribute("compression", valueS);
400:            }
401:
402:            public int getMaxSavePostSize() {
403:                return maxSavePostSize;
404:            }
405:
406:            public void setMaxSavePostSize(int valueI) {
407:                maxSavePostSize = valueI;
408:                setAttribute("maxSavePostSize", "" + valueI);
409:            }
410:
411:            public int getMaxHttpHeaderSize() {
412:                return maxHttpHeaderSize;
413:            }
414:
415:            public void setMaxHttpHeaderSize(int valueI) {
416:                maxHttpHeaderSize = valueI;
417:                setAttribute("maxHttpHeaderSize", "" + valueI);
418:            }
419:
420:            public String getRestrictedUserAgents() {
421:                return restrictedUserAgents;
422:            }
423:
424:            public void setRestrictedUserAgents(String valueS) {
425:                restrictedUserAgents = valueS;
426:                setAttribute("restrictedUserAgents", valueS);
427:            }
428:
429:            public String getNoCompressionUserAgents() {
430:                return noCompressionUserAgents;
431:            }
432:
433:            public void setNoCompressionUserAgents(String valueS) {
434:                noCompressionUserAgents = valueS;
435:                setAttribute("noCompressionUserAgents", valueS);
436:            }
437:
438:            public String getCompressableMimeType() {
439:                return compressableMimeTypes;
440:            }
441:
442:            public void setCompressableMimeType(String valueS) {
443:                compressableMimeTypes = valueS;
444:                setAttribute("compressableMimeTypes", valueS);
445:            }
446:
447:            public int getCompressionMinSize() {
448:                return compressionMinSize;
449:            }
450:
451:            public void setCompressionMinSize(int valueI) {
452:                compressionMinSize = valueI;
453:                setAttribute("compressionMinSize", "" + valueI);
454:            }
455:
456:            public int getSoLinger() {
457:                return ep.getSoLinger();
458:            }
459:
460:            public void setSoLinger(int i) {
461:                ep.setSoLinger(i);
462:                setAttribute("soLinger", "" + i);
463:            }
464:
465:            public int getSoTimeout() {
466:                return ep.getSoTimeout();
467:            }
468:
469:            public void setSoTimeout(int i) {
470:                ep.setSoTimeout(i);
471:                setAttribute("soTimeout", "" + i);
472:            }
473:
474:            public String getProtocol() {
475:                return getProperty("protocol");
476:            }
477:
478:            public void setProtocol(String k) {
479:                setSecure(true);
480:                setAttribute("protocol", k);
481:            }
482:
483:            public boolean getSecure() {
484:                return secure;
485:            }
486:
487:            public void setSecure(boolean b) {
488:                ep.setSecure(b);
489:                secure = b;
490:                setAttribute("secure", "" + b);
491:            }
492:
493:            public int getMaxKeepAliveRequests() {
494:                return maxKeepAliveRequests;
495:            }
496:
497:            /** Set the maximum number of Keep-Alive requests that we will honor.
498:             */
499:            public void setMaxKeepAliveRequests(int mkar) {
500:                maxKeepAliveRequests = mkar;
501:                setAttribute("maxKeepAliveRequests", "" + mkar);
502:            }
503:
504:            /**
505:             * Return the Keep-Alive policy for the connection.
506:             */
507:            public boolean getKeepAlive() {
508:                return ((maxKeepAliveRequests != 0) && (maxKeepAliveRequests != 1));
509:            }
510:
511:            /**
512:             * Set the keep-alive policy for this connection.
513:             */
514:            public void setKeepAlive(boolean keepAlive) {
515:                if (!keepAlive) {
516:                    setMaxKeepAliveRequests(1);
517:                }
518:            }
519:
520:            public int getSocketCloseDelay() {
521:                return socketCloseDelay;
522:            }
523:
524:            public void setSocketCloseDelay(int d) {
525:                socketCloseDelay = d;
526:                setAttribute("socketCloseDelay", "" + d);
527:            }
528:
529:            public void setServer(String server) {
530:                this .server = server;
531:            }
532:
533:            public String getServer() {
534:                return server;
535:            }
536:
537:            public int getTimeout() {
538:                return timeout;
539:            }
540:
541:            public void setTimeout(int timeouts) {
542:                timeout = timeouts;
543:                setAttribute("timeout", "" + timeouts);
544:            }
545:
546:            public void setProcessorCache(int processorCache) {
547:                this .processorCache = processorCache;
548:            }
549:
550:            public void setOomParachute(int oomParachute) {
551:                ep.setOomParachute(oomParachute);
552:                setAttribute("oomParachute", oomParachute);
553:            }
554:
555:            // --------------------  SSL related properties --------------------
556:
557:            public String getKeystoreFile() {
558:                return ep.getKeystoreFile();
559:            }
560:
561:            public void setKeystoreFile(String s) {
562:                ep.setKeystoreFile(s);
563:            }
564:
565:            public void setKeystore(String s) {
566:                setKeystoreFile(s);
567:            }
568:
569:            public String getKeystore() {
570:                return getKeystoreFile();
571:            }
572:
573:            public String getAlgorithm() {
574:                return ep.getAlgorithm();
575:            }
576:
577:            public void setAlgorithm(String s) {
578:                ep.setAlgorithm(s);
579:            }
580:
581:            public boolean getClientAuth() {
582:                return ep.getClientAuth();
583:            }
584:
585:            public void setClientAuth(boolean b) {
586:                ep.setClientAuth(b);
587:            }
588:
589:            public String getKeystorePass() {
590:                return ep.getKeystorePass();
591:            }
592:
593:            public void setKeystorePass(String s) {
594:                ep.setKeystorePass(s);
595:            }
596:
597:            public void setKeypass(String s) {
598:                setKeystorePass(s);
599:            }
600:
601:            public String getKeypass() {
602:                return getKeystorePass();
603:            }
604:
605:            public String getKeystoreType() {
606:                return ep.getKeystoreType();
607:            }
608:
609:            public void setKeystoreType(String s) {
610:                ep.setKeystoreType(s);
611:            }
612:
613:            public String getSslProtocol() {
614:                return ep.getSslProtocol();
615:            }
616:
617:            public void setSslProtocol(String s) {
618:                ep.setSslProtocol(s);
619:            }
620:
621:            public String getCiphers() {
622:                return ep.getCiphers();
623:            }
624:
625:            public void setCiphers(String s) {
626:                ep.setCiphers(s);
627:            }
628:
629:            public boolean getSSLEnabled() {
630:                return ep.isSSLEnabled();
631:            }
632:
633:            public void setSSLEnabled(boolean SSLEnabled) {
634:                ep.setSSLEnabled(SSLEnabled);
635:            }
636:
637:            // --------------------  Connection handler --------------------
638:
639:            static class Http11ConnectionHandler implements  Handler {
640:
641:                protected Http11NioProtocol proto;
642:                protected static int count = 0;
643:                protected RequestGroupInfo global = new RequestGroupInfo();
644:
645:                protected ConcurrentHashMap<NioChannel, Http11NioProcessor> connections = new ConcurrentHashMap<NioChannel, Http11NioProcessor>();
646:                protected ConcurrentLinkedQueue<Http11NioProcessor> recycledProcessors = new ConcurrentLinkedQueue<Http11NioProcessor>() {
647:                    protected AtomicInteger size = new AtomicInteger(0);
648:
649:                    public boolean offer(Http11NioProcessor processor) {
650:                        boolean offer = proto.processorCache == -1 ? true
651:                                : size.get() < proto.processorCache;
652:                        //avoid over growing our cache or add after we have stopped
653:                        boolean result = false;
654:                        if (offer) {
655:                            result = super .offer(processor);
656:                            if (result) {
657:                                size.incrementAndGet();
658:                            }
659:                        }
660:                        if (!result)
661:                            deregister(processor);
662:                        return result;
663:                    }
664:
665:                    public Http11NioProcessor poll() {
666:                        Http11NioProcessor result = super .poll();
667:                        if (result != null) {
668:                            size.decrementAndGet();
669:                        }
670:                        return result;
671:                    }
672:
673:                    public void clear() {
674:                        Http11NioProcessor next = poll();
675:                        while (next != null) {
676:                            deregister(next);
677:                            next = poll();
678:                        }
679:                        super .clear();
680:                        size.set(0);
681:                    }
682:                };
683:
684:                Http11ConnectionHandler(Http11NioProtocol proto) {
685:                    this .proto = proto;
686:                }
687:
688:                public void releaseCaches() {
689:                    recycledProcessors.clear();
690:                }
691:
692:                public SocketState event(NioChannel socket, SocketStatus status) {
693:                    Http11NioProcessor result = connections.get(socket);
694:
695:                    SocketState state = SocketState.CLOSED;
696:                    if (result != null) {
697:                        if (log.isDebugEnabled())
698:                            log.debug("Http11NioProcessor.error="
699:                                    + result.error);
700:                        // Call the appropriate event
701:                        try {
702:                            state = result.event(status);
703:                        } catch (java.net.SocketException e) {
704:                            // SocketExceptions are normal
705:                            Http11NioProtocol.log
706:                                    .debug(
707:                                            sm
708:                                                    .getString("http11protocol.proto.socketexception.debug"),
709:                                            e);
710:                        } catch (java.io.IOException e) {
711:                            // IOExceptions are normal
712:                            Http11NioProtocol.log
713:                                    .debug(
714:                                            sm
715:                                                    .getString("http11protocol.proto.ioexception.debug"),
716:                                            e);
717:                        }
718:                        // Future developers: if you discover any other
719:                        // rare-but-nonfatal exceptions, catch them here, and log as
720:                        // above.
721:                        catch (Throwable e) {
722:                            // any other exception or error is odd. Here we log it
723:                            // with "ERROR" level, so it will show up even on
724:                            // less-than-verbose logs.
725:                            Http11NioProtocol.log
726:                                    .error(
727:                                            sm
728:                                                    .getString("http11protocol.proto.error"),
729:                                            e);
730:                        } finally {
731:                            if (state != SocketState.LONG) {
732:                                connections.remove(socket);
733:                                recycledProcessors.offer(result);
734:                                if (state == SocketState.OPEN) {
735:                                    socket.getPoller().add(socket);
736:                                }
737:                            } else {
738:                                if (log.isDebugEnabled())
739:                                    log.debug("Keeping processor[" + result);
740:                                socket.getPoller().add(socket);
741:                            }
742:                        }
743:                    }
744:                    return state;
745:                }
746:
747:                public SocketState process(NioChannel socket) {
748:                    Http11NioProcessor processor = null;
749:                    try {
750:                        if (processor == null) {
751:                            processor = recycledProcessors.poll();
752:                        }
753:                        if (processor == null) {
754:                            processor = createProcessor();
755:                        }
756:
757:                        if (processor instanceof  ActionHook) {
758:                            ((ActionHook) processor).action(
759:                                    ActionCode.ACTION_START, null);
760:                        }
761:
762:                        if (proto.ep.getSecure()
763:                                && (proto.sslImplementation != null)) {
764:                            if (socket instanceof  SecureNioChannel) {
765:                                SecureNioChannel ch = (SecureNioChannel) socket;
766:                                processor.setSslSupport(proto.sslImplementation
767:                                        .getSSLSupport(ch.getSslEngine()
768:                                                .getSession()));
769:                            } else
770:                                processor.setSslSupport(null);
771:                        } else {
772:                            processor.setSslSupport(null);
773:                        }
774:
775:                        SocketState state = processor.process(socket);
776:                        if (state == SocketState.LONG) {
777:                            // Associate the connection with the processor. The next request 
778:                            // processed by this thread will use either a new or a recycled
779:                            // processor.
780:                            if (log.isDebugEnabled())
781:                                log.debug("Not recycling ["
782:                                        + processor
783:                                        + "] Comet="
784:                                        + ((NioEndpoint.KeyAttachment) socket
785:                                                .getAttachment(false))
786:                                                .getComet());
787:                            connections.put(socket, processor);
788:                            socket.getPoller().add(socket);
789:                        } else {
790:                            recycledProcessors.offer(processor);
791:                        }
792:                        return state;
793:
794:                    } catch (java.net.SocketException e) {
795:                        // SocketExceptions are normal
796:                        Http11NioProtocol.log
797:                                .debug(
798:                                        sm
799:                                                .getString("http11protocol.proto.socketexception.debug"),
800:                                        e);
801:                    } catch (java.io.IOException e) {
802:                        // IOExceptions are normal
803:                        Http11NioProtocol.log
804:                                .debug(
805:                                        sm
806:                                                .getString("http11protocol.proto.ioexception.debug"),
807:                                        e);
808:                    }
809:                    // Future developers: if you discover any other
810:                    // rare-but-nonfatal exceptions, catch them here, and log as
811:                    // above.
812:                    catch (Throwable e) {
813:                        // any other exception or error is odd. Here we log it
814:                        // with "ERROR" level, so it will show up even on
815:                        // less-than-verbose logs.
816:                        Http11NioProtocol.log.error(sm
817:                                .getString("http11protocol.proto.error"), e);
818:                    }
819:                    recycledProcessors.offer(processor);
820:                    return SocketState.CLOSED;
821:                }
822:
823:                public Http11NioProcessor createProcessor() {
824:                    Http11NioProcessor processor = new Http11NioProcessor(
825:                            proto.ep.getSocketProperties().getRxBufSize(),
826:                            proto.ep.getSocketProperties().getTxBufSize(),
827:                            proto.maxHttpHeaderSize, proto.ep);
828:                    processor.setAdapter(proto.adapter);
829:                    processor
830:                            .setMaxKeepAliveRequests(proto.maxKeepAliveRequests);
831:                    processor.setTimeout(proto.timeout);
832:                    processor
833:                            .setDisableUploadTimeout(proto.disableUploadTimeout);
834:                    processor.setCompression(proto.compression);
835:                    processor.setCompressionMinSize(proto.compressionMinSize);
836:                    processor
837:                            .setNoCompressionUserAgents(proto.noCompressionUserAgents);
838:                    processor
839:                            .setCompressableMimeTypes(proto.compressableMimeTypes);
840:                    processor
841:                            .setRestrictedUserAgents(proto.restrictedUserAgents);
842:                    processor.setSocketBuffer(proto.socketBuffer);
843:                    processor.setMaxSavePostSize(proto.maxSavePostSize);
844:                    processor.setServer(proto.server);
845:                    register(processor);
846:                    return processor;
847:                }
848:
849:                AtomicInteger registerCount = new AtomicInteger(0);
850:
851:                public void register(Http11NioProcessor processor) {
852:                    if (proto.getDomain() != null) {
853:                        synchronized (this ) {
854:                            try {
855:                                registerCount.addAndGet(1);
856:                                if (log.isDebugEnabled())
857:                                    log.debug("Register [" + processor
858:                                            + "] count=" + registerCount.get());
859:                                RequestInfo rp = processor.getRequest()
860:                                        .getRequestProcessor();
861:                                rp.setGlobalProcessor(global);
862:                                ObjectName rpName = new ObjectName(proto
863:                                        .getDomain()
864:                                        + ":type=RequestProcessor,worker="
865:                                        + proto.getName()
866:                                        + ",name=HttpRequest"
867:                                        + count++);
868:                                Registry.getRegistry(null, null)
869:                                        .registerComponent(rp, rpName, null);
870:                                rp.setRpName(rpName);
871:                            } catch (Exception e) {
872:                                log.warn("Error registering request");
873:                            }
874:                        }
875:                    }
876:                }
877:
878:                public void deregister(Http11NioProcessor processor) {
879:                    if (proto.getDomain() != null) {
880:                        synchronized (this ) {
881:                            try {
882:                                registerCount.addAndGet(-1);
883:                                if (log.isDebugEnabled())
884:                                    log.debug("Deregister [" + processor
885:                                            + "] count=" + registerCount.get());
886:                                RequestInfo rp = processor.getRequest()
887:                                        .getRequestProcessor();
888:                                rp.setGlobalProcessor(null);
889:                                ObjectName rpName = rp.getRpName();
890:                                Registry.getRegistry(null, null)
891:                                        .unregisterComponent(rpName);
892:                                rp.setRpName(null);
893:                            } catch (Exception e) {
894:                                log.warn("Error unregistering request", e);
895:                            }
896:                        }
897:                    }
898:                }
899:
900:            }
901:
902:            protected static org.apache.juli.logging.Log log = org.apache.juli.logging.LogFactory
903:                    .getLog(Http11NioProtocol.class);
904:
905:            // -------------------- Various implementation classes --------------------
906:
907:            protected String domain;
908:            protected ObjectName oname;
909:            protected MBeanServer mserver;
910:
911:            public ObjectName getObjectName() {
912:                return oname;
913:            }
914:
915:            public String getDomain() {
916:                return domain;
917:            }
918:
919:            public int getProcessorCache() {
920:                return processorCache;
921:            }
922:
923:            public int getOomParachute() {
924:                return ep.getOomParachute();
925:            }
926:
927:            public ObjectName preRegister(MBeanServer server, ObjectName name)
928:                    throws Exception {
929:                oname = name;
930:                mserver = server;
931:                domain = name.getDomain();
932:                return name;
933:            }
934:
935:            public void postRegister(Boolean registrationDone) {
936:            }
937:
938:            public void preDeregister() throws Exception {
939:            }
940:
941:            public void postDeregister() {
942:            }
943:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.