Skip to content

Commit

Permalink
调整文档,添加默认类实现的校验
Browse files Browse the repository at this point in the history
  • Loading branch information
p-moon committed Dec 11, 2024
1 parent 26be3c4 commit e732fd9
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ ISP)则要求我们确保流程中的任何接口实现都可以被替换,
<dependency>
<groupId>plus.jdk</groupId>
<artifactId>spring-smart-ioc-starter</artifactId>
<version>1.0.2</version>
<version>1.0.3</version>
</dependency>
```

Expand Down
13 changes: 7 additions & 6 deletions doc/execution-sequence-diagram.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
```plantuml:execution-sequence-diagram
```plantuml
:execution-sequence-diagram
@startuml
skinparam backgroundColor #EEEBDC
skinparam handwritten true
Expand Down Expand Up @@ -48,18 +49,18 @@ title 启动 & 执行时序图
!define jexl_engine_eval_msg PURPLE_TEXT("通过 jexl 来执行脚本并获取返回结果")
!define jexl_engine_eval_result PURPLE_TEXT("jexl 执行输入的条件表达式并返回结果")
!define jexl_engine_eval_condition PURPLE_TEXT("判定jexl 执行输入的条件表达式是否为 true")
!define loop_bean_impl_msg "遍历所有的 bean 实现"
!define loop_bean_impl_msg "遍历所有的 bean 实现,根据@ConditionOnRule直接标注的规则来判定是否执行。注意,class上面标注规则的优先级高于method上标注的规则"
!define script_eval_true_msg "jexl eval结果为 true"
!define script_eval_false_msg "jexl eval结果为 false"
!define script_eval_false_continue_msg "继续遍历 eval下一个 bean的条件"
!define bean_impl_invoke_method_msg "调用符合条件的实现类的方法"
!define bean_impl_invoke_method_return_msg RED_TEXT("返回函数执行结果")
!define no_matching_rules_were_hit "未命中任何符合条件实现类"
!define get_default_implementation_annotated_via_primary_msg RED_TEXT(获取通过@SmartService的primary)\nRED_TEXT(属性标注的默认实现)
!define bean_load_flow_note GREEN_TEXT(在这里会扫描并记录所有接口被)\nRED_TEXT("@SmartService")GREEN_TEXT( 标注的实现类)
!define jexl_desc_note_line1 YELLOW_TEXT("JEXL(Java Expression Language)是Apache Commons项目中的一个子项目,它提供了一种轻量级且灵活的表达式语言,")
!define jexl_desc_note_line2 YELLOW_TEXT("用于在Java应用程序中动态计算和操作数据。JEXL的设计初衷是为了使表达式的解析和执行变得简单且高效,同时保持与Java语言的紧密集成。")
!define jexl_desc_note_line3 YELLOW_TEXT("JEXL设计之初就考虑了性能问题,通过编译和缓存机制来提高表达式的执行效率。这里的逻辑判定耗时一般在纳秒级别")
!define bean_load_flow_note GREEN_TEXT(在这里会扫描并记录所有接口被)\nRED_TEXT("@SmartService")GREEN_TEXT( 标注的实现类)\nGREEN_TEXT(必须有一个默认实现作为兜底)
!define jexl_desc_note_line1 YELLOW_TEXT("JEXL(Java Expression Language)是Apache Commons项目中的一个子项目,它提供了一种轻量级且灵活的表达式语言,用于在Java应用程序")
!define jexl_desc_note_line2 YELLOW_TEXT("中动态计算和操作数据。JEXL的设计初衷是为了使表达式的解析和执行变得简单且高效,同时保持与Java语言的紧密集成。JEXL设计之初就考虑了")
!define jexl_desc_note_line3 YELLOW_TEXT("考虑了性能问题,通过编译和缓存机制来提高表达式的执行效率。这里的逻辑判定耗时一般在纳秒级别,所以不需要担心这里实时判定的性能问题")
Expand Down
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>plus.jdk</groupId>
<artifactId>spring-smart-ioc-starter</artifactId>
<version>1.0.2</version>
<version>1.0.3</version>


<description>spring-smart-ioc-starter</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.jexl3.*;
import org.springframework.context.ApplicationContext;
import org.springframework.context.SmartLifecycle;
import plus.jdk.smart.ioc.annotations.ConditionOnRule;
import plus.jdk.smart.ioc.annotations.SmartService;
import lombok.SneakyThrows;
Expand All @@ -19,7 +20,7 @@
import java.util.zip.CRC32;

@Slf4j
public class SmartIocSelectorFactory {
public class SmartIocSelectorFactory implements SmartLifecycle {

/**
* Stores the mapping relationship between the SmartService interface and its implementation class for dynamic proxying and instantiation.
Expand All @@ -41,6 +42,11 @@ public class SmartIocSelectorFactory {
*/
private final JexlEngine jexlEngine;

/**
* A flag indicating whether SmartIocSelectorFactory has been started.
*/
private Boolean started;

/**
* Create a new SmartIocSelectorFactory instance.
*/
Expand Down Expand Up @@ -142,4 +148,25 @@ protected Object switchBeanToInvoke(Class<?> interfaceClazz, Method method, Obje
throw new RuntimeException(String.format("No implementation class meeting the ConditionOnRule conditions for interface %s was found, " +
"and no primary bean was registered, method: %s", interfaceClazz, method.getName()));
}

@Override
public void start() {
this.started = true;
for(Class<?> clazz : beanDefinitionMap.keySet()) {
SmartIocDefinition smartIocDefinition = beanDefinitionMap.get(clazz);
if(smartIocDefinition.getDefaultDescriptor() == null) {
throw new RuntimeException(String.format("The defined grouping interface %s does not have an implementation class annotated with the `primary` attribute of @SmartService", clazz.getName()));
}
}
}

@Override
public void stop() {
this.started = false;
}

@Override
public boolean isRunning() {
return started;
}
}

0 comments on commit e732fd9

Please sign in to comment.