##### Coverage Report - com.ctrip.framework.apollo.common.customize.TomcatContainerCustomizer

Classes in this File | Line Coverage | Branch Coverage | Complexity
TomcatContainerCustomizer |
0% | 0/9
0% | 0/4
| 3.5;3.5
TomcatContainerCustomizer$1 |
0% | 0/8
0% | 0/2
| 3.5;3.5

1 |  |
     package com.ctrip.framework.apollo.common.customize;
2 |  |
3 |  |
     import org.apache.catalina.connector.Connector;
4 |  |
     import org.apache.coyote.ProtocolHandler;
5 |  |
     import org.apache.coyote.http11.Http11NioProtocol;
6 |  |
     import org.slf4j.Logger;
7 |  |
     import org.slf4j.LoggerFactory;
8 |  |
     import org.springframework.beans.factory.annotation.Autowired;
9 |  |
     import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;
10 |  |
     import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
11 |  |
     import org.springframework.boot.context.embedded.tomcat.TomcatConnectorCustomizer;
12 |  |
     import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
13 |  |
     import org.springframework.core.env.Environment;
14 |  |
     import org.springframework.stereotype.Component;
15 |  |
16 |  |
     /**
17 |  |
      * @author Jason Song(song_s@ctrip.com)
18 |  |
      */
19 |  |
     @Component
20 | 0 |
     public class TomcatContainerCustomizer implements EmbeddedServletContainerCustomizer {
21 | 0 |
       private static final Logger logger = LoggerFactory.getLogger(TomcatContainerCustomizer.class);
22 |  |
       private static final String TOMCAT_ACCEPTOR_COUNT = "server.tomcat.accept-count";
23 |  |
       @Autowired
24 |  |
       private Environment environment;
25 |  |
26 |  |
       @Override
27 |  |
       public void customize(ConfigurableEmbeddedServletContainer container) {
28 | 0 |
         if (!(container instanceof TomcatEmbeddedServletContainerFactory)) {
29 | 0 |
           return;
30 |  |
         }
31 | 0 |
         if (!environment.containsProperty(TOMCAT_ACCEPTOR_COUNT)) {
32 | 0 |
           return;
33 |  |
         }
34 | 0 |
         TomcatEmbeddedServletContainerFactory tomcat =
35 |  |
             (TomcatEmbeddedServletContainerFactory) container;
36 | 0 |
         tomcat.addConnectorCustomizers(new TomcatConnectorCustomizer() {
37 |  |
           @Override
38 |  |
           public void customize(Connector connector) {
39 | 0 |
             ProtocolHandler handler = connector.getProtocolHandler();
40 | 0 |
             if (handler instanceof Http11NioProtocol) {
41 | 0 |
               Http11NioProtocol http = (Http11NioProtocol) handler;
42 | 0 |
               int acceptCount = Integer.parseInt(environment.getProperty(TOMCAT_ACCEPTOR_COUNT));
43 | 0 |
               http.setBacklog(acceptCount);
44 | 0 |
               logger.info("Setting tomcat accept count to {}", acceptCount);
45 |  |
             }
46 |  |
47 | 0 |
           }
48 |  |
         });
49 | 0 |
       }
50 |  |
     }