8000 update sofaboot switch by HzjNeverStop · Pull Request #1084 · sofastack/sofa-boot · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
8000

update sofaboot switch #1084

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
< 8000 span data-view-component="true"> Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,20 @@
import java.lang.annotation.Target;

/**
* 只在非 ark 环境或者 ark 环境的 master biz 生效,非 master biz 不生效
* {@link Conditional @Conditional} that checks if the running environment is not ark module biz.
*
* @author caojie.cj@antfin.com
* @since 2019/10/29
*/
@Target({ ElementType.TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Conditional(OnMasterBiz.class)
@Conditional(OnMasterBizCondition.class)
public @interface ConditionalOnMasterBiz {

/**
* 额外的条件,用于处理某些配置在基座
* @return
* Extension condition used in master biz.
*
*/
String extensionCondition() default "";
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
import java.lang.annotation.Target;

/**
* 只能在非测试环境下生效
* {@link Conditional @Conditional} that checks if the running environment is not test.
*
* @author huzijie
* @version ConditionalOnNotTest.java, v 0.1 2022年10月17日 2:54 PM huzijie Exp $
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alipay.sofa.boot.annotation.condition;
package com.alipay.sofa.boot.autoconfigure.condition;

import org.springframework.context.annotation.Conditional;

Expand All @@ -25,6 +25,8 @@
import java.lang.annotation.Target;

/**
* {@link Conditional @Conditional} that checks if the switch is enabled in environment.
*
* @author yuanxuan
* @version : ConditionalOnSwitch.java, v 0.1 2023年02月09日 09:48 yuanxuan Exp $
*/
Expand All @@ -35,7 +37,7 @@
public @interface ConditionalOnSwitch {

/**
* switch key
* switch key.
*
* @return the switch key in config
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.alipay.sofa.boot.util.SofaBootEnvUtils;
import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.type.AnnotatedTypeMetadata;
Expand All @@ -35,10 +36,12 @@
import java.util.Map;

/**
* {@link Condition} that checks if running in ark master biz environment.
*
* @author caojie.cj@antfin.com
* @since 2019/10/29
*/
public class OnMasterBiz extends SpringBootCondition {
public class OnMasterBizCondition extends SpringBootCondition {

private static Object masterBiz;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alipay.sofa.boot.annotation.condition;
package com.alipay.sofa.boot.autoconfigure.condition;

import org.springframework.boot.autoconfigure.condition.ConditionMessage;
import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.annotation.MergedAnnotation;
import org.springframework.core.env.Environment;
Expand All @@ -28,12 +29,14 @@
import org.springframework.util.StringUtils;

/**
* {@link Condition} that checks if switch properties are defined in environment.
*
* @author yuanxuan
* @version : OnSwitchCondition.java, v 0.1 2023年02月09日 09:53 yuanxuan Exp $
*/
public class OnSwitchCondition extends SpringBootCondition {

private static final String CONFIG_KEY_PREFIX = "sofa.boot.bean.switch";
private static final String CONFIG_KEY_PREFIX = "sofa.boot.switch.bean";

@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@
import org.springframework.boot.autoconfigure.condition.ConditionMessage;
import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;

/**
* {@link Condition} that checks if running in test environment.
*
* @author huzijie
* @version OnTestCondition.java, v 0.1 2022年10月17日 2:54 PM huzijie Exp $
*/
9E81 Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
package com.alipay.sofa.boot.autoconfigure.rpc;

import com.alipay.sofa.boot.annotation.condition.ConditionalOnSwitch;
import com.alipay.sofa.boot.autoconfigure.condition.ConditionalOnSwitch;
import com.alipay.sofa.rpc.boot.swagger.BoltSwaggerServiceApplicationListener;
import com.alipay.sofa.rpc.boot.swagger.SwaggerServiceApplicationListener;
import com.alipay.sofa.runtime.spi.component.SofaRuntimeManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
package com.alipay.sofa.boot.autoconfigure.rpc;

import com.alipay.sofa.boot.annotation.condition.ConditionalOnSwitch;
import com.alipay.sofa.boot.autoconfigure.condition.ConditionalOnSwitch;
import com.alipay.sofa.boot.autoconfigure.runtime.SofaRuntimeAutoConfiguration;
import com.alipay.sofa.rpc.boot.config.RegistryConfigureProcessor;
import com.alipay.sofa.rpc.boot.container.ProviderConfigContainer;
Expand Down
5 changes: 0 additions & 5 deletions sofa-boot-project/sofa-boot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
Expand All @@ -43,7 +39,6 @@
<artifactId>logback-classic</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@
import org.springframework.util.StringUtils;

/**
* An {@link ApplicationContextInitializer} that could use property to dynamic enable initializer.
*
* @author yuanxuan
* @version : SwitchableApplicationContextInitializer.java, v 0.1 2023年02月09日 11:57 yuanxuan Exp $
*/
public abstract class SwitchableApplicationContextInitializer
implements
ApplicationContextInitializer<ConfigurableApplicationContext> {
protected static final String CONFIG_KEY_PREFIX = "sofa.boot.initializer.switch";

protected static final String CONFIG_KEY_PREFIX = "sofa.boot.switch.initializer";

@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,19 @@
import org.springframework.util.StringUtils;

/**
* An {@link ApplicationListener} that could use property to dynamic enable listener.
*
* @author yuanxuan
* @version : SwitchableApplicationListener.java, v 0.1 2023年02月09日 17:40 yuanxuan Exp $
*/
public abstract class SwitchableApplicationListener<EVENT extends ApplicationEvent>
public abstract class SwitchableApplicationListener<E extends ApplicationEvent>
implements
ApplicationListener<EVENT> {
protected static final String CONFIG_KEY_PREFIX = "sofa.boot.listener.switch";
ApplicationListener<E> {

protected static final String CONFIG_KEY_PREFIX = "sofa.boot.switch.initializer";

@Override
public void onApplicationEvent(EVENT event) {
public void onApplicationEvent(E event) {
ApplicationContext applicationContext = null;
Environment environment = null;
if (event instanceof ApplicationContextEvent applicationContextEvent) {
Expand All @@ -62,14 +65,14 @@ public void onApplicationEvent(EVENT event) {
}
if (environment != null) {
if (isEnable(environment)) {
doApplicationEvent(event);
doOnApplicationEvent(event);
}
} else {
doApplicationEvent(event);
doOnApplicationEvent(event);
}
}

protected abstract void doApplicationEvent(EVENT event);
protected abstract void doOnApplicationEvent(E event);

/**
* sofa.boot.switch.listener
Expand Down
0