-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
858282c
commit a05b1b2
Showing
2 changed files
with
34 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,8 +16,12 @@ | |
*/ | ||
package com.alipay.sofa.rpc.boot.context; | ||
|
||
import org.springframework.beans.BeansException; | ||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.context.ApplicationContextAware; | ||
import org.springframework.context.ApplicationEvent; | ||
import org.springframework.context.ApplicationListener; | ||
import org.springframework.context.event.ApplicationContextEvent; | ||
import org.springframework.context.event.ContextClosedEvent; | ||
import org.springframework.context.event.ContextStoppedEvent; | ||
|
||
|
@@ -29,9 +33,11 @@ | |
* | ||
* @author <a href="mailto:[email protected]">LiWei</a> | ||
*/ | ||
public class ApplicationContextClosedListener implements ApplicationListener { | ||
public class ApplicationContextClosedListener implements ApplicationListener, | ||
ApplicationContextAware { | ||
private final ProviderConfigContainer providerConfigContainer; | ||
private final ServerConfigContainer serverConfigContainer; | ||
private ApplicationContext applicationContext; | ||
|
||
public ApplicationContextClosedListener(ProviderConfigContainer providerConfigContainer, | ||
ServerConfigContainer serverConfigContainer) { | ||
|
@@ -42,8 +48,16 @@ public ApplicationContextClosedListener(ProviderConfigContainer providerConfigCo | |
@Override | ||
public void onApplicationEvent(ApplicationEvent event) { | ||
if ((event instanceof ContextClosedEvent) || (event instanceof ContextStoppedEvent)) { | ||
providerConfigContainer.unExportAllProviderConfig(); | ||
serverConfigContainer.closeAllServer(); | ||
if (applicationContext | ||
.equals(((ApplicationContextEvent) event).getApplicationContext())) { | ||
providerConfigContainer.unExportAllProviderConfig(); | ||
serverConfigContainer.closeAllServer(); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { | ||
this.applicationContext = applicationContext; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,9 @@ | |
*/ | ||
package com.alipay.sofa.rpc.boot.context; | ||
|
||
import org.springframework.beans.BeansException; | ||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.context.ApplicationContextAware; | ||
import org.springframework.context.ApplicationListener; | ||
import org.springframework.context.event.ContextRefreshedEvent; | ||
|
||
|
@@ -28,15 +30,24 @@ | |
* | ||
* @author <a href="mailto:[email protected]">leizhiyuan</a> | ||
*/ | ||
public class ApplicationContextRefreshedListener implements | ||
public class ApplicationContextRefreshedListener implements ApplicationContextAware, | ||
ApplicationListener<ContextRefreshedEvent> { | ||
|
||
private ApplicationContext applicationContext; | ||
|
||
@Override | ||
public void onApplicationEvent(ContextRefreshedEvent event) { | ||
ApplicationContext applicationContext = event.getApplicationContext(); | ||
//rpc 开始启动事件监听器 | ||
applicationContext.publishEvent(new SofaBootRpcStartEvent(applicationContext)); | ||
//rpc 启动完毕事件监听器 | ||
applicationContext.publishEvent(new SofaBootRpcStartAfterEvent(applicationContext)); | ||
if (applicationContext.equals(event.getApplicationContext())) { | ||
ApplicationContext applicationContext = event.getApplicationContext(); | ||
//rpc 开始启动事件监听器 | ||
applicationContext.publishEvent(new SofaBootRpcStartEvent(applicationContext)); | ||
//rpc 启动完毕事件监听器 | ||
applicationContext.publishEvent(new SofaBootRpcStartAfterEvent(applicationContext)); | ||
} | ||
} | ||
|
||
@Override | ||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { | ||
this.applicationContext = applicationContext; | ||
} | ||
} |