mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-10-15 02:17:48 +00:00
perf[runnable]: 使用Runnable函数式编程接口
This commit is contained in:
1 parent
a637db260a
commit
c4cdf272eb
42 files changed
+105
-142
No files matched your search
@@ -29,7 +29,7 @@ import org.springframework.core.Ordered;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
||||
/**
|
||||
* @author jaysunxiao
|
||||
* @author godotg
|
||||
* @version 3.0
|
||||
* <p>
|
||||
* 在EventRegisterProcessor 中完成扫描
|
||||
|
||||
@@ -59,9 +59,9 @@ public abstract class EventBus {
|
||||
}
|
||||
|
||||
public static class EventThreadFactory implements ThreadFactory {
|
||||
private int poolNumber;
|
||||
private AtomicInteger threadNumber = new AtomicInteger(1);
|
||||
private ThreadGroup group;
|
||||
private final int poolNumber;
|
||||
private final AtomicInteger threadNumber = new AtomicInteger(1);
|
||||
private final ThreadGroup group;
|
||||
|
||||
public EventThreadFactory(int poolNumber) {
|
||||
var s = System.getSecurityManager();
|
||||
@@ -111,7 +111,7 @@ public abstract class EventBus {
|
||||
executors[Math.abs(event.threadId() % EXECUTORS_SIZE)].execute(() -> doSubmit(event, list));
|
||||
}
|
||||
|
||||
public static void asyncExecute(SafeRunnable runnable) {
|
||||
public static void asyncExecute(Runnable runnable) {
|
||||
execute(RandomUtils.randomInt(EXECUTORS_SIZE), runnable);
|
||||
}
|
||||
|
||||
@@ -121,8 +121,8 @@ public abstract class EventBus {
|
||||
* @param hashcode
|
||||
* @return
|
||||
*/
|
||||
public static void execute(int hashcode, SafeRunnable runnable) {
|
||||
executors[Math.abs(hashcode % EXECUTORS_SIZE)].execute(runnable);
|
||||
public static void execute(int hashcode, Runnable runnable) {
|
||||
executors[Math.abs(hashcode % EXECUTORS_SIZE)].execute(SafeRunnable.valueOf(runnable));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -18,7 +18,7 @@ import java.lang.annotation.*;
|
||||
/**
|
||||
* 接收事件的注解
|
||||
*
|
||||
* @author jaysunxiao
|
||||
* @author godotg
|
||||
* @version 3.0
|
||||
*/
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ import org.springframework.context.event.ApplicationContextEvent;
|
||||
* <p>
|
||||
* 启动顺序为:AppStartBeforeEvent -> AppStartEvent -> AppStartAfterEvent
|
||||
*
|
||||
* @author jaysunxiao
|
||||
* @author godotg
|
||||
* @version 3.0
|
||||
*/
|
||||
public class AppStartAfterEvent extends ApplicationContextEvent {
|
||||
|
||||
@@ -21,7 +21,7 @@ import org.springframework.context.event.ApplicationContextEvent;
|
||||
* <p>
|
||||
* 启动顺序为:AppStartBeforeEvent -> AppStartEvent -> AppStartAfterEvent
|
||||
*
|
||||
* @author jaysunxiao
|
||||
* @author godotg
|
||||
* @version 3.0
|
||||
*/
|
||||
public class AppStartBeforeEvent extends ApplicationContextEvent {
|
||||
|
||||
@@ -21,7 +21,7 @@ import org.springframework.context.event.ApplicationContextEvent;
|
||||
* <p>
|
||||
* 启动顺序为:AppStartBeforeEvent -> AppStartEvent -> AppStartAfterEvent
|
||||
*
|
||||
* @author jaysunxiao
|
||||
* @author godotg
|
||||
* @version 3.0
|
||||
*/
|
||||
public class AppStartEvent extends ApplicationContextEvent {
|
||||
|
||||
@@ -16,7 +16,7 @@ package com.zfoo.event.model.event;
|
||||
import com.zfoo.util.math.RandomUtils;
|
||||
|
||||
/**
|
||||
* @author jaysunxiao
|
||||
* @author godotg
|
||||
* @version 3.0
|
||||
*/
|
||||
public interface IEvent {
|
||||
|
||||
@@ -25,7 +25,7 @@ import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
/**
|
||||
* @author jaysunxiao
|
||||
* @author godotg
|
||||
* @version 3.0
|
||||
*/
|
||||
public abstract class EnhanceUtils {
|
||||
|
||||
@@ -21,7 +21,7 @@ import java.lang.reflect.Method;
|
||||
/**
|
||||
* 动态代理被EventReceiver注解标注的方法,为了避免反射最终会用javassist字节码增强的方法去代理EventReceiverDefinition
|
||||
*
|
||||
* @author jaysunxiao
|
||||
* @author godotg
|
||||
* @version 3.0
|
||||
*/
|
||||
public class EventReceiverDefinition implements IEventReceiver {
|
||||
|
||||
@@ -16,7 +16,7 @@ package com.zfoo.event.model.vo;
|
||||
import com.zfoo.event.model.event.IEvent;
|
||||
|
||||
/**
|
||||
* @author jaysunxiao
|
||||
* @author godotg
|
||||
* @version 3.0
|
||||
*/
|
||||
public interface IEventReceiver {
|
||||
|
||||
@@ -22,7 +22,7 @@ import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
* @author jaysunxiao
|
||||
* @author godotg
|
||||
* @version 3.0
|
||||
*/
|
||||
public class EventDefinitionParser implements BeanDefinitionParser {
|
||||
|
||||
@@ -32,7 +32,7 @@ import java.lang.reflect.Modifier;
|
||||
* 这是一个后置处理器,在boot项目中注册EventContext时,会import导入EventRegisterProcessor这个组件,这是一个后置处理器,
|
||||
* 断点发现 在AbstractAutowireCapableBeanFactory或调用getBeanPostProcessors,这样子每一个后置处理器都会走postProcessAfterInitialization这个方法
|
||||
*
|
||||
* @author jaysunxiao
|
||||
* @author godotg
|
||||
* @version 3.0
|
||||
*/
|
||||
public class EventRegisterProcessor implements BeanPostProcessor {
|
||||
|
||||
@@ -16,7 +16,7 @@ package com.zfoo.event.schema;
|
||||
import org.springframework.beans.factory.xml.NamespaceHandlerSupport;
|
||||
|
||||
/**
|
||||
* @author jaysunxiao
|
||||
* @author godotg
|
||||
* @version 3.0
|
||||
*/
|
||||
public class NamespaceHandler extends NamespaceHandlerSupport {
|
||||
|
||||
@@ -20,7 +20,7 @@ import org.junit.Test;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
/**
|
||||
* @author jaysunxiao
|
||||
* @author godotg
|
||||
* @version 3.0
|
||||
*/
|
||||
@Ignore
|
||||
|
||||
@@ -19,7 +19,7 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author jaysunxiao
|
||||
* @author godotg
|
||||
* @version 3.0
|
||||
*/
|
||||
@Component
|
||||
|
||||
@@ -19,7 +19,7 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author jaysunxiao
|
||||
* @author godotg
|
||||
* @version 3.0
|
||||
*/
|
||||
@Component
|
||||
|
||||
@@ -16,7 +16,7 @@ package com.zfoo.event;
|
||||
import com.zfoo.event.model.event.IEvent;
|
||||
|
||||
/**
|
||||
* @author jaysunxiao
|
||||
* @author godotg
|
||||
* @version 3.0
|
||||
*/
|
||||
public class MyNoticeEvent implements IEvent {
|
||||
|
||||
Reference in new issue
Block a user