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

Commit

Permalink
Destroy server (#198)
Browse files Browse the repository at this point in the history
* un-destroy server

* destroy server

* destroy server

* add test case
  • Loading branch information
QilongZhang authored and JervyShi committed Jul 8, 2019
1 parent c9897a7 commit 78d8afe
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 30 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.alipay.sofa</groupId>
<artifactId>sofa-rpc-boot-projects</artifactId>
<version>6.0.3</version>
<version>6.0.4-SNAPSHOT</version>
<packaging>pom</packaging>

<name>${project.groupId}:${project.artifactId}</name>
Expand Down
4 changes: 2 additions & 2 deletions sofa-boot-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<modelVersion>4.0.0</modelVersion>

<artifactId>rpc-sofa-boot-core</artifactId>
<version>6.0.3</version>
<version>6.0.4-SNAPSHOT</version>

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

Expand All @@ -23,7 +23,7 @@
<dubbo_version>2.4.10</dubbo_version>
<cxf.version>3.0.14</cxf.version>
<skipTests>false</skipTests>
<rpc.all.version>5.5.5</rpc.all.version>
<rpc.all.version>5.5.7-SNAPSHOT</rpc.all.version>
<zkclient.version>0.10</zkclient.version>
<maven-compiler-plugin.version>3.3</maven-compiler-plugin.version>
<maven-source-plugin.version>3.0.1</maven-source-plugin.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.alipay.sofa.rpc.boot.log.SofaBootRpcLoggerFactory;
import com.alipay.sofa.rpc.common.RpcConstants;
import com.alipay.sofa.rpc.config.ServerConfig;
import com.alipay.sofa.rpc.server.Server;
import com.alipay.sofa.rpc.server.bolt.BoltServer;
import org.slf4j.Logger;
import org.springframework.util.StringUtils;
Expand Down Expand Up @@ -420,34 +421,30 @@ ServerConfig createDubboServerConfig() {
* 释放所有 ServerConfig 对应的资源,并移除所有的 ServerConfig。
*/
public void closeAllServer() {
if (boltServerConfig != null) {
boltServerConfig.destroy();
boltServerConfig = null;
}

if (restServerConfig != null) {
restServerConfig.destroy();
restServerConfig = null;
}
destroyServerConfig(boltServerConfig);
destroyServerConfig(restServerConfig);
destroyServerConfig(dubboServerConfig);
destroyServerConfig(h2cServerConfig);

if (dubboServerConfig != null) {
dubboServerConfig.destroy();
dubboServerConfig = null;
for (Map.Entry<String, ServerConfig> entry : customServerConfigs.entrySet()) {
final ServerConfig serverConfig = entry.getValue();
destroyServerConfig(serverConfig);
}

if (h2cServerConfig != null) {
h2cServerConfig.destroy();
h2cServerConfig = null;
}
boltServerConfig = null;
restServerConfig = null;
dubboServerConfig = null;
h2cServerConfig = null;
customServerConfigs.clear();
}

for (Map.Entry<String, ServerConfig> entry : customServerConfigs.entrySet()) {
final ServerConfig serverConfig = entry.getValue();
if (serverConfig != null) {
private void destroyServerConfig(ServerConfig serverConfig) {
if (serverConfig != null) {
Server server = serverConfig.getServer();
if (server != null && server.hasNoEntry()) {
serverConfig.destroy();
}
}

customServerConfigs.clear();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions sofa-boot-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
<modelVersion>4.0.0</modelVersion>

<artifactId>rpc-sofa-boot-plugin</artifactId>
<version>6.0.3</version>
<version>6.0.4-SNAPSHOT</version>

<properties>
<ark.plugin.name>rpc-sofa-boot-plugin</ark.plugin.name>
<rpc.all.version>5.5.5</rpc.all.version>
<rpc.all.version>5.5.7-SNAPSHOT</rpc.all.version>
<skipTests>false</skipTests>
<maven-javadoc-plugin.version>2.10.4</maven-javadoc-plugin.version>
<maven-source-plugin.version>3.0.1</maven-source-plugin.version>
Expand Down
4 changes: 2 additions & 2 deletions sofa-boot-samples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
<parent>
<groupId>com.alipay.sofa</groupId>
<artifactId>sofa-rpc-boot-projects</artifactId>
<version>6.0.3</version>
<version>6.0.4-SNAPSHOT</version>
</parent>

<properties>
<dubbo_version>2.4.10</dubbo_version>
<cxf.version>3.0.14</cxf.version>
<sofaboot.version>3.1.4</sofaboot.version>
<rpc.starter.version>6.0.3</rpc.starter.version>
<rpc.starter.version>6.0.4-SNAPSHOT</rpc.starter.version>
<curator-test.version>2.9.1</curator-test.version>
<junit.version>4.12</junit.version>
<spring-boot-starter-test.version>1.4.2.RELEASE</spring-boot-starter-test.version>
Expand Down
4 changes: 2 additions & 2 deletions sofa-boot-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
<modelVersion>4.0.0</modelVersion>

<artifactId>rpc-sofa-boot-starter</artifactId>
<version>6.0.3</version>
<version>6.0.4-SNAPSHOT</version>

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

<properties>
<java.version>1.8</java.version>
<project.build.encoding>UTF-8</project.build.encoding>
<skipTests>false</skipTests>
<rpc.starter.version>6.0.3</rpc.starter.version>
<rpc.starter.version>6.0.4-SNAPSHOT</rpc.starter.version>
<maven-compiler-plugin.version>3.3</maven-compiler-plugin.version>
<maven-source-plugin.version>3.0.1</maven-source-plugin.version>
<license-maven-plugin.version>3.0</license-maven-plugin.version>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.alipay.sofa.rpc.test.service;

import com.alipay.rpc.common.service.facade.SampleService;
import com.alipay.sofa.rpc.boot.config.SofaBootRpcConfigConstants;
import com.alipay.sofa.rpc.boot.container.ServerConfigContainer;
import com.alipay.sofa.rpc.config.ServerConfig;
import com.alipay.sofa.runtime.api.annotation.SofaReferenceBinding;
import com.alipay.sofa.runtime.api.annotation.SofaService;
import com.alipay.sofa.runtime.api.annotation.SofaServiceBinding;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner;

/**
* @author qilong.zql
* @since 6.0.4
*/
@SpringBootTest
@RunWith(SpringRunner.class)
public class ServiceTest {

@Autowired
private ServerConfigContainer serverConfigContainer;
private static ServerConfig serverConfig;

@Test
@DirtiesContext
public void testService() {
Assert.assertNotNull(serverConfigContainer);
serverConfig = serverConfigContainer.getServerConfig(SofaBootRpcConfigConstants.RPC_PROTOCOL_BOLT);
Assert.assertNotNull(serverConfig);
Assert.assertNotNull(serverConfig.getServer());
Assert.assertFalse(serverConfig.getServer().hasNoEntry());
}

@AfterClass
public static void afterClass() {
Assert.assertNull(serverConfig.getServer());
}

@Configuration
@EnableAutoConfiguration
static class ServiceTestConfiguration {
@Bean
@SofaService(bindings = { @SofaServiceBinding(bindingType = "bolt") })
public SampleService sampleService() {
return new SampleService() {
@Override
public String echoStr(String name) {
return "sampleService";
}
};
}
}
}

0 comments on commit 78d8afe

Please sign in to comment.