forked from alibaba/nacos
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ISSUE-alibaba#4256] Just inject environment in StartingSpringApplica…
…tionRunListener (alibaba#4257) * just inject environment in StartingSpringApplicationRunListener * make nacosStartingListener is decoupling with springApplicationRunListener. * add api doc * refactor. transfer nacos listeners to SpringApplicationRunListener. * remove unuseful import * add doc info
- Loading branch information
Showing
9 changed files
with
274 additions
and
105 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
113 changes: 113 additions & 0 deletions
113
core/src/main/java/com/alibaba/nacos/core/code/SpringApplicationRunListener.java
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 |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/* | ||
* Copyright 1999-2018 Alibaba Group Holding Ltd. | ||
* | ||
* 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.alibaba.nacos.core.code; | ||
|
||
import com.alibaba.nacos.core.listener.LoggingApplicationListener; | ||
import com.alibaba.nacos.core.listener.NacosApplicationListener; | ||
import com.alibaba.nacos.core.listener.StartingApplicationListener; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.context.event.EventPublishingRunListener; | ||
import org.springframework.context.ConfigurableApplicationContext; | ||
import org.springframework.core.Ordered; | ||
import org.springframework.core.env.ConfigurableEnvironment; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* {@link org.springframework.boot.SpringApplicationRunListener} before {@link EventPublishingRunListener} execution. | ||
* | ||
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a> | ||
* @since 0.2.2 | ||
*/ | ||
public class SpringApplicationRunListener implements org.springframework.boot.SpringApplicationRunListener, Ordered { | ||
|
||
private final SpringApplication application; | ||
|
||
private final String[] args; | ||
|
||
private List<NacosApplicationListener> nacosApplicationListeners = new ArrayList<>(); | ||
|
||
{ | ||
nacosApplicationListeners.add(new LoggingApplicationListener()); | ||
nacosApplicationListeners.add(new StartingApplicationListener()); | ||
} | ||
|
||
public SpringApplicationRunListener(SpringApplication application, String[] args) { | ||
this.application = application; | ||
this.args = args; | ||
} | ||
|
||
@Override | ||
public void starting() { | ||
for (NacosApplicationListener nacosApplicationListener : nacosApplicationListeners) { | ||
nacosApplicationListener.starting(); | ||
} | ||
} | ||
|
||
@Override | ||
public void environmentPrepared(ConfigurableEnvironment environment) { | ||
for (NacosApplicationListener nacosApplicationListener : nacosApplicationListeners) { | ||
nacosApplicationListener.environmentPrepared(environment); | ||
} | ||
} | ||
|
||
@Override | ||
public void contextPrepared(ConfigurableApplicationContext context) { | ||
for (NacosApplicationListener nacosApplicationListener : nacosApplicationListeners) { | ||
nacosApplicationListener.contextPrepared(context); | ||
} | ||
} | ||
|
||
@Override | ||
public void contextLoaded(ConfigurableApplicationContext context) { | ||
for (NacosApplicationListener nacosApplicationListener : nacosApplicationListeners) { | ||
nacosApplicationListener.contextLoaded(context); | ||
} | ||
} | ||
|
||
@Override | ||
public void started(ConfigurableApplicationContext context) { | ||
for (NacosApplicationListener nacosApplicationListener : nacosApplicationListeners) { | ||
nacosApplicationListener.started(context); | ||
} | ||
} | ||
|
||
@Override | ||
public void running(ConfigurableApplicationContext context) { | ||
for (NacosApplicationListener nacosApplicationListener : nacosApplicationListeners) { | ||
nacosApplicationListener.running(context); | ||
} | ||
} | ||
|
||
@Override | ||
public void failed(ConfigurableApplicationContext context, Throwable exception) { | ||
for (NacosApplicationListener nacosApplicationListener : nacosApplicationListeners) { | ||
nacosApplicationListener.failed(context, exception); | ||
} | ||
} | ||
|
||
/** | ||
* Before {@link EventPublishingRunListener}. | ||
* | ||
* @return HIGHEST_PRECEDENCE | ||
*/ | ||
@Override | ||
public int getOrder() { | ||
return HIGHEST_PRECEDENCE; | ||
} | ||
} |
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
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
78 changes: 78 additions & 0 deletions
78
core/src/main/java/com/alibaba/nacos/core/listener/NacosApplicationListener.java
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 |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Copyright 1999-2018 Alibaba Group Holding Ltd. | ||
* | ||
* 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.alibaba.nacos.core.listener; | ||
|
||
import com.alibaba.nacos.core.code.SpringApplicationRunListener; | ||
import org.springframework.context.ConfigurableApplicationContext; | ||
import org.springframework.core.env.ConfigurableEnvironment; | ||
|
||
/** | ||
* Nacos Application Listener, execute init process. | ||
* | ||
* @author horizonzy | ||
* @since 1.4.1 | ||
*/ | ||
public interface NacosApplicationListener { | ||
|
||
/** | ||
* {@link SpringApplicationRunListener#starting}. | ||
*/ | ||
void starting(); | ||
|
||
/** | ||
* {@link com.alibaba.nacos.core.code.SpringApplicationRunListener#environmentPrepared}. | ||
* | ||
* @param environment environment | ||
*/ | ||
void environmentPrepared(ConfigurableEnvironment environment); | ||
|
||
/** | ||
* {@link com.alibaba.nacos.core.code.SpringApplicationRunListener#contextLoaded}. | ||
* | ||
* @param context context | ||
*/ | ||
void contextPrepared(ConfigurableApplicationContext context); | ||
|
||
/** | ||
* {@link com.alibaba.nacos.core.code.SpringApplicationRunListener#contextLoaded}. | ||
* | ||
* @param context context | ||
*/ | ||
void contextLoaded(ConfigurableApplicationContext context); | ||
|
||
/** | ||
* {@link com.alibaba.nacos.core.code.SpringApplicationRunListener#started}. | ||
* | ||
* @param context context | ||
*/ | ||
void started(ConfigurableApplicationContext context); | ||
|
||
/** | ||
* {@link com.alibaba.nacos.core.code.SpringApplicationRunListener#running}. | ||
* | ||
* @param context context | ||
*/ | ||
void running(ConfigurableApplicationContext context); | ||
|
||
/** | ||
* {@link com.alibaba.nacos.core.code.SpringApplicationRunListener#failed}. | ||
* | ||
* @param context context | ||
* @param exception exception | ||
*/ | ||
void failed(ConfigurableApplicationContext context, Throwable exception); | ||
} |
Oops, something went wrong.