diff --git a/contact-center/app/pom.xml b/contact-center/app/pom.xml index 82070c5a..3313220e 100644 --- a/contact-center/app/pom.xml +++ b/contact-center/app/pom.xml @@ -375,6 +375,13 @@ sdk 2.1.0 + + + org.projectlombok + lombok + provided + + diff --git a/contact-center/app/src/main/java/com/chatopera/cc/config/WebServerContainerConfigure.java b/contact-center/app/src/main/java/com/chatopera/cc/config/WebServerContainerConfigure.java index 256c194c..7958286e 100644 --- a/contact-center/app/src/main/java/com/chatopera/cc/config/WebServerContainerConfigure.java +++ b/contact-center/app/src/main/java/com/chatopera/cc/config/WebServerContainerConfigure.java @@ -1,69 +1,60 @@ -/* - * Copyright (C) 2017 优客服-多渠道客服系统 - * Modifications copyright (C) 2018-2019 Chatopera Inc, - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.chatopera.cc.config; - -import org.apache.catalina.connector.Connector; -import org.apache.coyote.http11.Http11NioProtocol; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; -import org.springframework.boot.context.embedded.tomcat.TomcatConnectorCustomizer; -import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -import java.io.IOException; -import java.security.NoSuchAlgorithmException; - -@Configuration -public class WebServerContainerConfigure { - - @Value("${server.threads.max}") - private Integer maxthread; - - @Value("${server.connection.max}") - private Integer maxconnections; - - @Value("${web.upload-path}") - private String path; - - @Bean - public EmbeddedServletContainerFactory createEmbeddedServletContainerFactory() throws IOException, NoSuchAlgorithmException { - TomcatEmbeddedServletContainerFactory tomcatFactory = new TomcatEmbeddedServletContainerFactory(); - tomcatFactory.addConnectorCustomizers(new CSKeFuTomcatConnectorCustomizer(maxthread, maxconnections)); - return tomcatFactory; - } - - class CSKeFuTomcatConnectorCustomizer implements TomcatConnectorCustomizer { - private Integer maxthread; - private Integer maxconnection; - - CSKeFuTomcatConnectorCustomizer(Integer maxthread, Integer maxconnection) { - this.maxthread = maxthread; - this.maxconnection = maxconnection; - } - - public void customize(Connector connector) { - Http11NioProtocol protocol = (Http11NioProtocol) connector.getProtocolHandler(); - //设置最大连接数 - protocol.setMaxConnections(maxthread != null ? maxthread : 2000); - //设置最大线程数 - protocol.setMaxThreads(maxconnection != null ? maxconnection : 2000); - protocol.setConnectionTimeout(30000); - } - } -} - +/* + * Copyright (C) 2017 优客服-多渠道客服系统 + * Modifications copyright (C) 2018-2019 Chatopera Inc, + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.chatopera.cc.config; + +import lombok.RequiredArgsConstructor; +import org.apache.catalina.connector.Connector; +import org.apache.coyote.http11.Http11NioProtocol; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.web.embedded.tomcat.ConfigurableTomcatWebServerFactory; +import org.springframework.boot.web.embedded.tomcat.TomcatConnectorCustomizer; +import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class WebServerContainerConfigure { + + @Value("${server.threads.max}") + private Integer maxThread; + + @Value("${server.connection.max}") + private Integer maxConnections; + + @Bean + public ConfigurableTomcatWebServerFactory createEmbeddedServletContainerFactory() { + ConfigurableTomcatWebServerFactory tomcatFactory = new TomcatServletWebServerFactory(); + tomcatFactory.addConnectorCustomizers(new CSKeFuTomcatConnectorCustomizer(maxThread, maxConnections)); + return tomcatFactory; + } + + @RequiredArgsConstructor + private static class CSKeFuTomcatConnectorCustomizer implements TomcatConnectorCustomizer { + private final Integer maxThread; + private final Integer maxConnection; + + public void customize(Connector connector) { + Http11NioProtocol protocol = (Http11NioProtocol) connector.getProtocolHandler(); + //设置最大连接数 + protocol.setMaxConnections(maxThread != null ? maxThread : 2000); + //设置最大线程数 + protocol.setMaxThreads(maxConnection != null ? maxConnection : 2000); + protocol.setConnectionTimeout(30000); + } + } +} +