以删除一个项目,将级联删除该项目下所有任务为例。
一、事件发布/订阅中心
可以看到事件的发布和订阅都采用的是异步的方式。
import com.google.common.eventbus.AsyncEventBus;
import com.google.common.eventbus.EventBus;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import java.util.concurrent.ThreadPoolExecutor;
/**
* 进程内的事件发布/订阅中心
*/
public class InternalEventCenter {
private final static EventBus eventBus;
static {
ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolTaskExecutor();
threadPoolTaskExecutor.setCorePoolSize(5);
threadPoolTaskExecutor.setMaxPoolSize(5);
threadPoolTaskExecutor.setQueueCapacity(10);
threadPoolTaskExecutor.setThreadNamePrefix("event-bus-task");
threadPoolTaskExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
threadPoolTaskExecutor.initialize();
eventBus = new AsyncEventBus(threadPoolTaskEx