mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-05-19 23:26:50 +00:00
Merge pull request #45 from Yuao-github/main
perf[event] add field "async" in @EventReceiver
This commit is contained in:
@@ -1,9 +0,0 @@
|
||||
package com.zfoo.event.model.anno;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.METHOD})
|
||||
public @interface AsyncExecute {
|
||||
}
|
||||
@@ -26,4 +26,5 @@ import java.lang.annotation.*;
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.METHOD})
|
||||
public @interface EventReceiver {
|
||||
boolean async() default false;
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
package com.zfoo.event.schema;
|
||||
|
||||
import com.zfoo.event.manager.EventBus;
|
||||
import com.zfoo.event.model.anno.AsyncExecute;
|
||||
import com.zfoo.event.model.anno.EventReceiver;
|
||||
import com.zfoo.event.model.event.IEvent;
|
||||
import com.zfoo.event.model.vo.EnhanceUtils;
|
||||
@@ -84,7 +83,7 @@ public class EventRegisterProcessor implements BeanPostProcessor {
|
||||
var enhanceReceiverDefinition = EnhanceUtils.createEventReceiver(receiverDefinition);
|
||||
|
||||
//异步执行标志,false表示同步执行,true表示异步执行
|
||||
var asyncFlag = method.isAnnotationPresent(AsyncExecute.class);
|
||||
var asyncFlag = method.getDeclaredAnnotation(EventReceiver.class).async();
|
||||
// key:class类型 value:观察者 注册Event的receiverMap中
|
||||
EventBus.registerEventReceiver(eventClazz, enhanceReceiverDefinition, asyncFlag);
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
|
||||
package com.zfoo.event;
|
||||
|
||||
import com.zfoo.event.model.anno.AsyncExecute;
|
||||
import com.zfoo.event.model.anno.EventReceiver;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -33,8 +32,7 @@ public class MyController2 {
|
||||
*
|
||||
* 异步事件会被不会立刻执行,注意日志打印的线程号
|
||||
*/
|
||||
@AsyncExecute
|
||||
@EventReceiver
|
||||
@EventReceiver(async = true)
|
||||
public void onMyNoticeEvent(MyNoticeEvent event) {
|
||||
logger.info("方法2异步执行事件:" + event.getMessage());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user