Skip to content
This repository was archived by the owner on May 30, 2022. It is now read-only.

Commit 78d8afe

Browse files
QilongZhangJervyShi
authored andcommitted
Destroy server (#198)
* un-destroy server * destroy server * destroy server * add test case
1 parent c9897a7 commit 78d8afe

File tree

7 files changed

+106
-30
lines changed

7 files changed

+106
-30
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.alipay.sofa</groupId>
88
<artifactId>sofa-rpc-boot-projects</artifactId>
9-
<version>6.0.3</version>
9+
<version>6.0.4-SNAPSHOT</version>
1010
<packaging>pom</packaging>
1111

1212
<name>${project.groupId}:${project.artifactId}</name>

sofa-boot-core/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<modelVersion>4.0.0</modelVersion>
1111

1212
<artifactId>rpc-sofa-boot-core</artifactId>
13-
<version>6.0.3</version>
13+
<version>6.0.4-SNAPSHOT</version>
1414

1515
<url>https://github.com/sofastack/sofa-rpc</url>
1616

@@ -23,7 +23,7 @@
2323
<dubbo_version>2.4.10</dubbo_version>
2424
<cxf.version>3.0.14</cxf.version>
2525
<skipTests>false</skipTests>
26-
<rpc.all.version>5.5.5</rpc.all.version>
26+
<rpc.all.version>5.5.7-SNAPSHOT</rpc.all.version>
2727
<zkclient.version>0.10</zkclient.version>
2828
<maven-compiler-plugin.version>3.3</maven-compiler-plugin.version>
2929
<maven-source-plugin.version>3.0.1</maven-source-plugin.version>

sofa-boot-core/src/main/java/com/alipay/sofa/rpc/boot/container/ServerConfigContainer.java

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.alipay.sofa.rpc.boot.log.SofaBootRpcLoggerFactory;
2525
import com.alipay.sofa.rpc.common.RpcConstants;
2626
import com.alipay.sofa.rpc.config.ServerConfig;
27+
import com.alipay.sofa.rpc.server.Server;
2728
import com.alipay.sofa.rpc.server.bolt.BoltServer;
2829
import org.slf4j.Logger;
2930
import org.springframework.util.StringUtils;
@@ -420,34 +421,30 @@ ServerConfig createDubboServerConfig() {
420421
* 释放所有 ServerConfig 对应的资源,并移除所有的 ServerConfig。
421422
*/
422423
public void closeAllServer() {
423-
if (boltServerConfig != null) {
424-
boltServerConfig.destroy();
425-
boltServerConfig = null;
426-
}
427-
428-
if (restServerConfig != null) {
429-
restServerConfig.destroy();
430-
restServerConfig = null;
431-
}
424+
destroyServerConfig(boltServerConfig);
425+
destroyServerConfig(restServerConfig);
426+
destroyServerConfig(dubboServerConfig);
427+
destroyServerConfig(h2cServerConfig);
432428

433-
if (dubboServerConfig != null) {
434-
dubboServerConfig.destroy();
435-
dubboServerConfig = null;
429+
for (Map.Entry<String, ServerConfig> entry : customServerConfigs.entrySet()) {
430+
final ServerConfig serverConfig = entry.getValue();
431+
destroyServerConfig(serverConfig);
436432
}
437433

438-
if (h2cServerConfig != null) {
439-
h2cServerConfig.destroy();
440-
h2cServerConfig = null;
441-
}
434+
boltServerConfig = null;
435+
restServerConfig = null;
436+
dubboServerConfig = null;
437+
h2cServerConfig = null;
438+
customServerConfigs.clear();
439+
}
442440

443-
for (Map.Entry<String, ServerConfig> entry : customServerConfigs.entrySet()) {
444-
final ServerConfig serverConfig = entry.getValue();
445-
if (serverConfig != null) {
441+
private void destroyServerConfig(ServerConfig serverConfig) {
442+
if (serverConfig != null) {
443+
Server server = serverConfig.getServer();
444+
if (server != null && server.hasNoEntry()) {
446445
serverConfig.destroy();
447446
}
448447
}
449-
450-
customServerConfigs.clear();
451448
}
452449

453450
/**

sofa-boot-plugin/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
<modelVersion>4.0.0</modelVersion>
1111

1212
<artifactId>rpc-sofa-boot-plugin</artifactId>
13-
<version>6.0.3</version>
13+
<version>6.0.4-SNAPSHOT</version>
1414

1515
<properties>
1616
<ark.plugin.name>rpc-sofa-boot-plugin</ark.plugin.name>
17-
<rpc.all.version>5.5.5</rpc.all.version>
17+
<rpc.all.version>5.5.7-SNAPSHOT</rpc.all.version>
1818
<skipTests>false</skipTests>
1919
<maven-javadoc-plugin.version>2.10.4</maven-javadoc-plugin.version>
2020
<maven-source-plugin.version>3.0.1</maven-source-plugin.version>

sofa-boot-samples/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
<parent>
88
<groupId>com.alipay.sofa</groupId>
99
<artifactId>sofa-rpc-boot-projects</artifactId>
10-
<version>6.0.3</version>
10+
<version>6.0.4-SNAPSHOT</version>
1111
</parent>
1212

1313
<properties>
1414
<dubbo_version>2.4.10</dubbo_version>
1515
<cxf.version>3.0.14</cxf.version>
1616
<sofaboot.version>3.1.4</sofaboot.version>
17-
<rpc.starter.version>6.0.3</rpc.starter.version>
17+
<rpc.starter.version>6.0.4-SNAPSHOT</rpc.starter.version>
1818
<curator-test.version>2.9.1</curator-test.version>
1919
<junit.version>4.12</junit.version>
2020
<spring-boot-starter-test.version>1.4.2.RELEASE</spring-boot-starter-test.version>

sofa-boot-starter/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010
<modelVersion>4.0.0</modelVersion>
1111

1212
<artifactId>rpc-sofa-boot-starter</artifactId>
13-
<version>6.0.3</version>
13+
<version>6.0.4-SNAPSHOT</version>
1414

1515
<url>https://github.com/sofastack/sofa-rpc</url>
1616

1717
<properties>
1818
<java.version>1.8</java.version>
1919
<project.build.encoding>UTF-8</project.build.encoding>
2020
<skipTests>false</skipTests>
21-
<rpc.starter.version>6.0.3</rpc.starter.version>
21+
<rpc.starter.version>6.0.4-SNAPSHOT</rpc.starter.version>
2222
<maven-compiler-plugin.version>3.3</maven-compiler-plugin.version>
2323
<maven-source-plugin.version>3.0.1</maven-source-plugin.version>
2424
<license-maven-plugin.version>3.0</license-maven-plugin.version>
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package com.alipay.sofa.rpc.test.service;
18+
19+
import com.alipay.rpc.common.service.facade.SampleService;
20+
import com.alipay.sofa.rpc.boot.config.SofaBootRpcConfigConstants;
21+
import com.alipay.sofa.rpc.boot.container.ServerConfigContainer;
22+
import com.alipay.sofa.rpc.config.ServerConfig;
23+
import com.alipay.sofa.runtime.api.annotation.SofaReferenceBinding;
24+
import com.alipay.sofa.runtime.api.annotation.SofaService;
25+
import com.alipay.sofa.runtime.api.annotation.SofaServiceBinding;
26+
import org.junit.AfterClass;
27+
import org.junit.Assert;
28+
import org.junit.Test;
29+
import org.junit.runner.RunWith;
30+
import org.springframework.beans.factory.annotation.Autowired;
31+
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
32+
import org.springframework.boot.test.context.SpringBootTest;
33+
import org.springframework.context.annotation.Bean;
34+
import org.springframework.context.annotation.Configuration;
35+
import org.springframework.test.annotation.DirtiesContext;
36+
import org.springframework.test.context.junit4.SpringRunner;
37+
38+
/**
39+
* @author qilong.zql
40+
* @since 6.0.4
41+
*/
42+
@SpringBootTest
43+
@RunWith(SpringRunner.class)
44+
public class ServiceTest {
45+
46+
@Autowired
47+
private ServerConfigContainer serverConfigContainer;
48+
private static ServerConfig serverConfig;
49+
50+
@Test
51+
@DirtiesContext
52+
public void testService() {
53+
Assert.assertNotNull(serverConfigContainer);
54+
serverConfig = serverConfigContainer.getServerConfig(SofaBootRpcConfigConstants.RPC_PROTOCOL_BOLT);
55+
Assert.assertNotNull(serverConfig);
56+
Assert.assertNotNull(serverConfig.getServer());
57+
Assert.assertFalse(serverConfig.getServer().hasNoEntry());
58+
}
59+
60+
@AfterClass
61+
public static void afterClass() {
62+
Assert.assertNull(serverConfig.getServer());
63+
}
64+
65+
@Configuration
66+
@EnableAutoConfiguration
67+
static class ServiceTestConfiguration {
68+
@Bean
69+
@SofaService(bindings = { @SofaServiceBinding(bindingType = "bolt") })
70+
public SampleService sampleService() {
71+
return new SampleService() {
72+
@Override
73+
public String echoStr(String name) {
74+
return "sampleService";
75+
}
76+
};
77+
}
78+
}
79+
}

0 commit comments

Comments
 (0)