Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
commons
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
3
Merge Requests
3
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DevOps
commons
Commits
149ffdd9
Commit
149ffdd9
authored
Dec 12, 2017
by
ag
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat : jetty support
parent
e652aa0b
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
88 additions
and
10 deletions
+88
-10
pom.xml
pom.xml
+7
-1
BaseDestroyHandler.java
.../java/cn/quantgroup/tech/shutdown/BaseDestroyHandler.java
+11
-9
GracefulShutdownAutoConfiguration.java
...down/configuration/GracefulShutdownAutoConfiguration.java
+40
-0
JettyShutdown.java
...va/cn/quantgroup/tech/shutdown/service/JettyShutdown.java
+30
-0
No files found.
pom.xml
View file @
149ffdd9
...
@@ -58,10 +58,16 @@
...
@@ -58,10 +58,16 @@
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-
amqp
</artifactId>
<artifactId>
spring-boot-starter-
jetty
</artifactId>
<optional>
true
</optional>
<optional>
true
</optional>
</dependency>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-amqp
</artifactId>
<!--<optional>true</optional>-->
</dependency>
</dependencies>
</dependencies>
<!-- 部署时往公司私服上发包, 可以在网址上找到 其他项目引入该包的需要的 XML -->
<!-- 部署时往公司私服上发包, 可以在网址上找到 其他项目引入该包的需要的 XML -->
<distributionManagement>
<distributionManagement>
...
...
src/main/java/cn/quantgroup/tech/shutdown/BaseDestroyHandler.java
View file @
149ffdd9
...
@@ -8,8 +8,6 @@ import org.springframework.context.ApplicationContext;
...
@@ -8,8 +8,6 @@ import org.springframework.context.ApplicationContext;
import
org.springframework.context.Lifecycle
;
import
org.springframework.context.Lifecycle
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
javax.annotation.PreDestroy
;
@Slf4j
@Slf4j
@Component
@Component
public
class
BaseDestroyHandler
{
public
class
BaseDestroyHandler
{
...
@@ -17,18 +15,22 @@ public class BaseDestroyHandler {
...
@@ -17,18 +15,22 @@ public class BaseDestroyHandler {
@Autowired
@Autowired
private
ApplicationContext
applicationContext
;
private
ApplicationContext
applicationContext
;
@PreDestroy
//todo test
// @PreDestroy
private
void
stopRedisSub
()
{
private
void
stopRedisSub
()
{
// context.getBean(RedisMessageListenerContainer.)
log
.
info
(
"redis stopped"
);
log
.
info
(
"redis stopped"
);
}
}
@PreDestroy
//todo test
// @PreDestroy
private
void
stopRabbitMQ
()
{
private
void
stopRabbitMQ
()
{
try
{
RabbitListenerEndpointRegistry
rabbitListenerEndpointRegistry
=
applicationContext
.
getBean
(
RabbitListenerEndpointRegistry
rabbitListenerEndpointRegistry
=
applicationContext
.
getBean
(
RabbitListenerConfigUtils
.
RABBIT_LISTENER_ENDPOINT_REGISTRY_BEAN_NAME
,
RabbitListenerConfigUtils
.
RABBIT_LISTENER_ENDPOINT_REGISTRY_BEAN_NAME
,
RabbitListenerEndpointRegistry
.
class
);
RabbitListenerEndpointRegistry
.
class
);
rabbitListenerEndpointRegistry
.
getListenerContainers
().
forEach
(
Lifecycle:
:
stop
);
rabbitListenerEndpointRegistry
.
getListenerContainers
().
forEach
(
Lifecycle:
:
stop
);
}
catch
(
Exception
e
)
{
}
log
.
info
(
"MQ listener stopped"
);
log
.
info
(
"MQ listener stopped"
);
}
}
}
}
src/main/java/cn/quantgroup/tech/shutdown/configuration/GracefulShutdownAutoConfiguration.java
View file @
149ffdd9
package
cn
.
quantgroup
.
tech
.
shutdown
.
configuration
;
package
cn
.
quantgroup
.
tech
.
shutdown
.
configuration
;
import
cn.quantgroup.tech.shutdown.properties.GracefulShutdownProperties
;
import
cn.quantgroup.tech.shutdown.properties.GracefulShutdownProperties
;
import
cn.quantgroup.tech.shutdown.service.JettyShutdown
;
import
cn.quantgroup.tech.shutdown.service.TomcatShutdown
;
import
cn.quantgroup.tech.shutdown.service.TomcatShutdown
;
import
cn.quantgroup.tech.shutdown.service.UndertowShutdown
;
import
cn.quantgroup.tech.shutdown.service.UndertowShutdown
;
import
cn.quantgroup.tech.shutdown.wrapper.UndertowShutdownHandlerWrapper
;
import
cn.quantgroup.tech.shutdown.wrapper.UndertowShutdownHandlerWrapper
;
import
io.undertow.Undertow
;
import
io.undertow.Undertow
;
import
org.apache.catalina.startup.Tomcat
;
import
org.apache.catalina.startup.Tomcat
;
import
org.eclipse.jetty.server.Server
;
import
org.eclipse.jetty.util.Loader
;
import
org.eclipse.jetty.webapp.WebAppContext
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.boot.autoconfigure.condition.SearchStrategy
;
import
org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration
;
import
org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration
;
import
org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer
;
import
org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer
;
import
org.springframework.boot.context.embedded.EmbeddedServletContainerFactory
;
import
org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory
;
import
org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory
;
import
org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory
;
import
org.springframework.boot.context.embedded.undertow.UndertowDeploymentInfoCustomizer
;
import
org.springframework.boot.context.embedded.undertow.UndertowDeploymentInfoCustomizer
;
import
org.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainerFactory
;
import
org.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainerFactory
;
...
@@ -20,6 +28,7 @@ import org.springframework.context.annotation.Import;
...
@@ -20,6 +28,7 @@ import org.springframework.context.annotation.Import;
import
javax.servlet.Servlet
;
import
javax.servlet.Servlet
;
/**
/**
* This configuration class will be picked up by Spring Boot's auto configuration capabilities as soon as it's
* This configuration class will be picked up by Spring Boot's auto configuration capabilities as soon as it's
* on the classpath.
* on the classpath.
...
@@ -35,6 +44,7 @@ public class GracefulShutdownAutoConfiguration {
...
@@ -35,6 +44,7 @@ public class GracefulShutdownAutoConfiguration {
*/
*/
@Configuration
@Configuration
@ConditionalOnClass
({
Servlet
.
class
,
Tomcat
.
class
})
@ConditionalOnClass
({
Servlet
.
class
,
Tomcat
.
class
})
@ConditionalOnMissingBean
(
value
=
EmbeddedServletContainerFactory
.
class
,
search
=
SearchStrategy
.
CURRENT
)
public
static
class
EmbeddedTomcat
{
public
static
class
EmbeddedTomcat
{
@Bean
@Bean
...
@@ -57,11 +67,41 @@ public class GracefulShutdownAutoConfiguration {
...
@@ -57,11 +67,41 @@ public class GracefulShutdownAutoConfiguration {
}
}
}
}
@Configuration
@ConditionalOnClass
({
Servlet
.
class
,
Server
.
class
,
Loader
.
class
,
WebAppContext
.
class
})
@ConditionalOnMissingBean
(
value
=
EmbeddedServletContainerFactory
.
class
,
search
=
SearchStrategy
.
CURRENT
)
public
static
class
EmbeddedJetty
{
@Bean
public
JettyShutdown
jettyShutdown
()
{
return
new
JettyShutdown
();
}
@Bean
public
JettyEmbeddedServletContainerFactory
jettyEmbeddedServletContainerFactory
()
{
return
new
JettyEmbeddedServletContainerFactory
();
}
@Bean
public
EmbeddedServletContainerCustomizer
jettyCustomizer
()
{
return
container
->
{
if
(
container
instanceof
JettyEmbeddedServletContainerFactory
)
{
((
JettyEmbeddedServletContainerFactory
)
container
).
addServerCustomizers
(
jettyShutdown
());
}
};
}
}
/**
/**
* Configuration for Undertow.
* Configuration for Undertow.
*/
*/
@Configuration
@Configuration
@ConditionalOnClass
({
Servlet
.
class
,
Undertow
.
class
})
@ConditionalOnClass
({
Servlet
.
class
,
Undertow
.
class
})
@ConditionalOnMissingBean
(
value
=
EmbeddedServletContainerFactory
.
class
,
search
=
SearchStrategy
.
CURRENT
)
public
static
class
EmbeddedUndertow
{
public
static
class
EmbeddedUndertow
{
@Bean
@Bean
...
...
src/main/java/cn/quantgroup/tech/shutdown/service/JettyShutdown.java
0 → 100644
View file @
149ffdd9
package
cn
.
quantgroup
.
tech
.
shutdown
.
service
;
import
lombok.extern.slf4j.Slf4j
;
import
org.eclipse.jetty.server.Server
;
import
org.eclipse.jetty.server.handler.StatisticsHandler
;
import
org.springframework.boot.context.embedded.jetty.JettyServerCustomizer
;
/**
* @author ag
*/
@Slf4j
public
class
JettyShutdown
implements
Shutdown
,
JettyServerCustomizer
{
private
volatile
Server
server
;
@Override
public
void
shutdown
(
Integer
delay
)
throws
InterruptedException
{
StatisticsHandler
handler
=
new
StatisticsHandler
();
handler
.
setHandler
(
server
.
getHandler
());
server
.
setHandler
(
handler
);
server
.
setStopTimeout
(
delay
);
//todo stop at shutdown
server
.
setStopAtShutdown
(
true
);
}
@Override
public
void
customize
(
Server
server
)
{
this
.
server
=
server
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment