mirror of
https://github.com/hpd840321/starRiverProperty.git
synced 2026-06-09 08:20:31 +08:00
chore: 工作区反编译与 Maven/文档/脚本同步到发布分支
- artifacts/decompiled 树与相关源码变更 - maven-cw-elevator-application 业务 docs 与 package-info - scripts 下 formatter 校验与辅助脚本 - 其他子工程/接口与发布线一并纳入版本控制 Made-with: Cursor Former-commit-id: e102e8cab64e575bcd23c9a66a598aa1892bb492
This commit is contained in:
+426
-430
@@ -1,430 +1,426 @@
|
||||
/* */ package cn.cloudwalk.event;
|
||||
/* */
|
||||
/* */ import cn.cloudwalk.cwos.client.event.EventClient;
|
||||
/* */ import cn.cloudwalk.cwos.client.event.event.BaseEvent;
|
||||
/* */ import cn.cloudwalk.cwos.client.event.event.CustomEvent;
|
||||
/* */ import cn.cloudwalk.cwos.client.event.event.EventType;
|
||||
/* */ import cn.cloudwalk.cwos.client.event.handler.EventListener;
|
||||
/* */ import cn.cloudwalk.event.annotation.ConsumerGroup;
|
||||
/* */ import cn.cloudwalk.event.annotation.CustomTopic;
|
||||
/* */ import cn.cloudwalk.event.annotation.EventTopicSuffix;
|
||||
/* */ import cn.cloudwalk.event.autoconfig.EventProperties;
|
||||
/* */ import cn.cloudwalk.event.handler.CustomEventHandler;
|
||||
/* */ import cn.cloudwalk.event.handler.EventHandler;
|
||||
/* */ import cn.cloudwalk.event.handler.EventHandlerMapping;
|
||||
/* */ import cn.cloudwalk.event.handler.EventHandlerWorker;
|
||||
/* */ import cn.cloudwalk.event.handler.NamedThreadFactory;
|
||||
/* */ import cn.cloudwalk.event.listener.CloudwalkEventListener;
|
||||
/* */ import cn.cloudwalk.event.listener.GroupEventListener;
|
||||
/* */ import cn.cloudwalk.event.listener.GroupListnerClassMapping;
|
||||
/* */ import com.google.common.collect.Lists;
|
||||
/* */ import com.google.common.collect.Sets;
|
||||
/* */ import java.lang.reflect.ParameterizedType;
|
||||
/* */ import java.lang.reflect.Type;
|
||||
/* */ import java.util.ArrayList;
|
||||
/* */ import java.util.HashMap;
|
||||
/* */ import java.util.LinkedList;
|
||||
/* */ import java.util.List;
|
||||
/* */ import java.util.Map;
|
||||
/* */ import java.util.Set;
|
||||
/* */ import java.util.concurrent.SynchronousQueue;
|
||||
/* */ import java.util.concurrent.ThreadFactory;
|
||||
/* */ import java.util.concurrent.ThreadPoolExecutor;
|
||||
/* */ import java.util.concurrent.TimeUnit;
|
||||
/* */ import java.util.regex.Matcher;
|
||||
/* */ import java.util.regex.Pattern;
|
||||
/* */ import org.slf4j.Logger;
|
||||
/* */ import org.slf4j.LoggerFactory;
|
||||
/* */ import org.springframework.beans.BeansException;
|
||||
/* */ import org.springframework.beans.factory.annotation.Autowired;
|
||||
/* */ import org.springframework.boot.CommandLineRunner;
|
||||
/* */ import org.springframework.context.ApplicationContext;
|
||||
/* */ import org.springframework.core.env.Environment;
|
||||
/* */ import org.springframework.util.CollectionUtils;
|
||||
/* */ import org.springframework.util.StringUtils;
|
||||
/* */
|
||||
/* */ public class CloudwalkEventInitializing
|
||||
/* */ implements CommandLineRunner {
|
||||
/* 48 */ private static final Logger LOGGER = LoggerFactory.getLogger(CloudwalkEventInitializing.class);
|
||||
/* */
|
||||
/* */ @Autowired(required = false)
|
||||
/* */ private List<EventHandler> eventHandlers;
|
||||
/* */
|
||||
/* */ @Autowired
|
||||
/* */ private CloudwalkEventManager cloudwalkEventManager;
|
||||
/* */
|
||||
/* */ @Autowired
|
||||
/* */ private Environment environment;
|
||||
/* */
|
||||
/* 59 */ private static final Pattern pattern = Pattern.compile("^\\$\\{(.*?)\\}$");
|
||||
/* */
|
||||
/* */
|
||||
/* */ private static final String DEFAULT_SUFFIX = "";
|
||||
/* */
|
||||
/* */
|
||||
/* */ private String defaultGroup;
|
||||
/* */
|
||||
/* */
|
||||
/* */ private EventClient defaultEventClient;
|
||||
/* */
|
||||
/* 70 */ private Map<String, EventClient> eventClientMap = new HashMap<>();
|
||||
/* */
|
||||
/* */ private EventProperties eventProperties;
|
||||
/* */
|
||||
/* */ private static boolean isHandlerEnable = false;
|
||||
/* */
|
||||
/* */
|
||||
/* */ public void run(String... args) throws Exception {
|
||||
/* 78 */ init();
|
||||
/* */ }
|
||||
/* */
|
||||
/* */ public void init() throws Exception {
|
||||
/* 82 */ initEventClient();
|
||||
/* 83 */ initHandlerMapping();
|
||||
/* 84 */ initHandlerExecutor();
|
||||
/* 85 */ subscribeEvent();
|
||||
/* */ }
|
||||
/* */
|
||||
/* */ public CloudwalkEventInitializing(EventProperties eventProperties) {
|
||||
/* 89 */ this.eventProperties = eventProperties;
|
||||
/* */ }
|
||||
/* */
|
||||
/* */
|
||||
/* */ private void initEventClient() throws ClassNotFoundException {
|
||||
/* 94 */ String[] groupIds = this.eventProperties.getGroupId().split(",");
|
||||
/* */
|
||||
/* 96 */ if (groupIds.length == 0) {
|
||||
/* 97 */ throw new IllegalArgumentException("消费组ID不能为空");
|
||||
/* */ }
|
||||
/* */
|
||||
/* 100 */ Map<String, String> listenerClassMap = this.eventProperties.getListenerClass();
|
||||
/* */
|
||||
/* 102 */ GroupListnerClassMapping groupListnerClassMapping = new GroupListnerClassMapping();
|
||||
/* */
|
||||
/* 104 */ for (int i = 0; i < groupIds.length; i++) {
|
||||
/* 105 */ Class<? extends EventListener> listenerClass; boolean isFirst = (i == 0);
|
||||
/* 106 */ String groupId = groupIds[i];
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* 110 */ if (null == listenerClassMap || StringUtils.isEmpty(listenerClassMap.get(groupId))) {
|
||||
/* 111 */ if (isFirst) {
|
||||
/* 112 */ Class<CloudwalkEventListener> clazz = CloudwalkEventListener.class;
|
||||
/* */ } else {
|
||||
/* 114 */ throw new IllegalArgumentException(String.format("groupId[%s]缺少listener-class的配置", new Object[] { groupId }));
|
||||
/* */ }
|
||||
/* */ } else {
|
||||
/* 117 */ listenerClass = (Class)Class.forName(listenerClassMap.get(groupId));
|
||||
/* */ }
|
||||
/* */
|
||||
/* 120 */ initEventClient(this.eventProperties.getBootstrapServers(), groupId, listenerClass, isFirst);
|
||||
/* 121 */ groupListnerClassMapping.register(listenerClass, groupId);
|
||||
/* */ }
|
||||
/* */
|
||||
/* 124 */ this.cloudwalkEventManager.setGroupListnerClassMapping(groupListnerClassMapping);
|
||||
/* 125 */ this.cloudwalkEventManager.setEventClient(this.defaultEventClient);
|
||||
/* */ }
|
||||
/* */
|
||||
/* */ @Autowired
|
||||
/* */ public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
||||
/* 130 */ GroupEventListener.applicationContext = applicationContext;
|
||||
/* */ }
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */ private List<String> extractGroupIds(EventHandler eventHandler) {
|
||||
/* 138 */ if (eventHandler.getClass().isAnnotationPresent((Class)ConsumerGroup.class)) {
|
||||
/* 139 */ ConsumerGroup consumerGroup = eventHandler.getClass().<ConsumerGroup>getAnnotation(ConsumerGroup.class);
|
||||
/* */
|
||||
/* 141 */ List<String> groupIds = new LinkedList<>();
|
||||
/* 142 */ for (String groupId : consumerGroup.groupIds()) {
|
||||
/* 143 */ Matcher matcher = pattern.matcher(groupId);
|
||||
/* 144 */ if (matcher.find()) {
|
||||
/* 145 */ String propertyKey = groupId.substring(2, groupId.length() - 1).trim();
|
||||
/* 146 */ String propertyValue = this.environment.getProperty(propertyKey);
|
||||
/* 147 */ if (!StringUtils.isEmpty(propertyValue)) {
|
||||
/* 148 */ groupId = propertyValue;
|
||||
/* */ }
|
||||
/* */ }
|
||||
/* 151 */ groupIds.add(groupId);
|
||||
/* */ }
|
||||
/* */
|
||||
/* 154 */ return groupIds;
|
||||
/* */ }
|
||||
/* 156 */ return Lists.newArrayList((Object[])new String[] { this.defaultGroup });
|
||||
/* */ }
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */ private void initHandlerMapping() {
|
||||
/* 163 */ if (CollectionUtils.isEmpty(this.eventHandlers)) {
|
||||
/* */ return;
|
||||
/* */ }
|
||||
/* */
|
||||
/* 167 */ isHandlerEnable = true;
|
||||
/* */
|
||||
/* 169 */ EventHandlerMapping eventHandlerMapping = new EventHandlerMapping();
|
||||
/* */
|
||||
/* 171 */ for (EventHandler<BaseEvent> handler : this.eventHandlers) {
|
||||
/* 172 */ if (handler.getClass().isAnnotationPresent((Class)EventTopicSuffix.class)) {
|
||||
/* 173 */ Type type = handler.getClass().getGenericInterfaces()[0];
|
||||
/* 174 */ ParameterizedType p = (ParameterizedType)type;
|
||||
/* 175 */ Class<BaseEvent> eventClass = (Class)p.getActualTypeArguments()[0];
|
||||
/* 176 */ EventTopicSuffix eventTopicSuffix = handler.getClass().<EventTopicSuffix>getAnnotation(EventTopicSuffix.class);
|
||||
/* */
|
||||
/* 178 */ registerHandlerMapping(eventHandlerMapping, handler, eventClass, eventTopicSuffix.value()); continue;
|
||||
/* 179 */ } if (handler.getClass().isAnnotationPresent((Class)CustomTopic.class)) {
|
||||
/* 180 */ CustomTopic customTopic = handler.getClass().<CustomTopic>getAnnotation(CustomTopic.class);
|
||||
/* 181 */ String topic = customTopic.topic();
|
||||
/* 182 */ if (StringUtils.isEmpty(topic)) {
|
||||
/* */ continue;
|
||||
/* */ }
|
||||
/* 185 */ registerCustomHandlerMapping(eventHandlerMapping, (EventHandler)handler, topic, customTopic.suffix());
|
||||
/* */ }
|
||||
/* */ }
|
||||
/* 188 */ this.cloudwalkEventManager.setEventHandlerMapping(eventHandlerMapping);
|
||||
/* */ }
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */ private void initHandlerExecutor() {
|
||||
/* 195 */ if (isHandlerEnable) {
|
||||
/* 196 */ EventHandlerWorker eventHandlerWorker = new EventHandlerWorker();
|
||||
/* 197 */ EventProperties.HandlerExecutorConfig handlerExecutorConfig = this.eventProperties.getHandlerExecutorConfig();
|
||||
/* 198 */ eventHandlerWorker.setPoolExecutor(new ThreadPoolExecutor(handlerExecutorConfig.getCorePoolSize().intValue(), handlerExecutorConfig
|
||||
/* 199 */ .getMaximumPoolSize().intValue(), 1000L, TimeUnit.MILLISECONDS, new SynchronousQueue<>(), (ThreadFactory)new NamedThreadFactory(this.eventProperties
|
||||
/* 200 */ .getWorkerNamePrefix()), new ThreadPoolExecutor.CallerRunsPolicy()));
|
||||
/* 201 */ this.cloudwalkEventManager.setEventHandlerWorker(eventHandlerWorker);
|
||||
/* */ }
|
||||
/* */ }
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */ private EventType getEventType(Class<? extends BaseEvent> eventClass) {
|
||||
/* 212 */ for (EventType eventType : EventType.values()) {
|
||||
/* 213 */ if (eventType.getEventClass().getClass().equals(eventClass)) {
|
||||
/* 214 */ return eventType;
|
||||
/* */ }
|
||||
/* */ }
|
||||
/* 217 */ return null;
|
||||
/* */ }
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */ private void subscribeEvent() throws IllegalAccessException, InstantiationException {
|
||||
/* 224 */ EventHandlerMapping eventHandlerMapping = this.cloudwalkEventManager.getEventHandlerMapping();
|
||||
/* */
|
||||
/* 226 */ Map<String, Map<EventType, Set<String>>> subscribedMap = new HashMap<>();
|
||||
/* */
|
||||
/* 228 */ for (Map.Entry<String, Map<EventType, Map<String, List<EventHandler>>>> entry : (Iterable<Map.Entry<String, Map<EventType, Map<String, List<EventHandler>>>>>)eventHandlerMapping.getHandlerMap().entrySet()) {
|
||||
/* 229 */ for (Map.Entry<EventType, Map<String, List<EventHandler>>> eventTypeMapEntry : (Iterable<Map.Entry<EventType, Map<String, List<EventHandler>>>>)((Map)entry.getValue()).entrySet()) {
|
||||
/* 230 */ for (String serviceCode : ((Map)eventTypeMapEntry.getValue()).keySet()) {
|
||||
/* 231 */ subscribe(subscribedMap, entry.getKey(), eventTypeMapEntry.getKey(), serviceCode);
|
||||
/* */ }
|
||||
/* */ }
|
||||
/* */ }
|
||||
/* */
|
||||
/* 236 */ Map<String, Map<String, Set<String>>> customSubscribedMap = new HashMap<>();
|
||||
/* */
|
||||
/* 238 */ for (Map.Entry<String, Map<String, Map<String, List<CustomEventHandler>>>> entry : (Iterable<Map.Entry<String, Map<String, Map<String, List<CustomEventHandler>>>>>)eventHandlerMapping.getCustomHandlerMap().entrySet()) {
|
||||
/* 239 */ for (Map.Entry<String, Map<String, List<CustomEventHandler>>> subEntry : (Iterable<Map.Entry<String, Map<String, List<CustomEventHandler>>>>)((Map)entry.getValue()).entrySet()) {
|
||||
/* 240 */ for (Map.Entry<String, List<CustomEventHandler>> handlerEntry : (Iterable<Map.Entry<String, List<CustomEventHandler>>>)((Map)subEntry.getValue()).entrySet()) {
|
||||
/* 241 */ for (CustomEventHandler customEventHandler : handlerEntry.getValue()) {
|
||||
/* 242 */ Type type = customEventHandler.getClass().getGenericInterfaces()[0];
|
||||
/* 243 */ ParameterizedType p = (ParameterizedType)type;
|
||||
/* 244 */ Class<? extends CustomEvent> eventClass = (Class)p.getActualTypeArguments()[0];
|
||||
/* 245 */ customSubscribe(customSubscribedMap, entry.getKey(), subEntry.getKey(), handlerEntry
|
||||
/* 246 */ .getKey(), eventClass);
|
||||
/* */ }
|
||||
/* */ }
|
||||
/* */ }
|
||||
/* */ }
|
||||
/* */ }
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */ private void subscribe(Map<String, Map<EventType, Set<String>>> subscribedMap, String groupId, EventType eventType, String serviceCode) {
|
||||
/* 265 */ if (StringUtils.isEmpty(groupId)) {
|
||||
/* 266 */ groupId = this.defaultGroup;
|
||||
/* */ }
|
||||
/* */
|
||||
/* 269 */ Map<EventType, Set<String>> eventTypeServiceCodeMap = subscribedMap.get(groupId);
|
||||
/* 270 */ if (null != eventTypeServiceCodeMap) {
|
||||
/* 271 */ Set<String> serviceCodesSet = eventTypeServiceCodeMap.get(eventType);
|
||||
/* 272 */ if (CollectionUtils.isEmpty(serviceCodesSet)) {
|
||||
/* 273 */ eventTypeServiceCodeMap.put(eventType, Sets.newHashSet((Object[])new String[] { serviceCode }));
|
||||
/* */ } else {
|
||||
/* 275 */ serviceCodesSet.add(serviceCode);
|
||||
/* */ }
|
||||
/* */ } else {
|
||||
/* 278 */ eventTypeServiceCodeMap = new HashMap<>();
|
||||
/* 279 */ eventTypeServiceCodeMap.put(eventType, Sets.newHashSet((Object[])new String[] { serviceCode }));
|
||||
/* 280 */ subscribedMap.put(groupId, eventTypeServiceCodeMap);
|
||||
/* */ }
|
||||
/* 282 */ ((EventClient)this.eventClientMap.get(groupId)).subEvent(eventType, serviceCode);
|
||||
/* */ }
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */ private void customSubscribe(Map<String, Map<String, Set<String>>> customSubscribedMap, String groupId, String topic, String serviceCode, Class<? extends CustomEvent> eventClass) throws IllegalAccessException, InstantiationException {
|
||||
/* 288 */ if (StringUtils.isEmpty(groupId)) {
|
||||
/* 289 */ groupId = this.defaultGroup;
|
||||
/* */ }
|
||||
/* */
|
||||
/* 292 */ Map<String, Set<String>> topicServiceCodeMap = customSubscribedMap.get(groupId);
|
||||
/* 293 */ if (null != topicServiceCodeMap) {
|
||||
/* 294 */ Set<String> serviceCodesSet = topicServiceCodeMap.get(topic);
|
||||
/* 295 */ if (CollectionUtils.isEmpty(serviceCodesSet)) {
|
||||
/* 296 */ topicServiceCodeMap.put(topic, Sets.newHashSet((Object[])new String[] { serviceCode }));
|
||||
/* */ } else {
|
||||
/* 298 */ serviceCodesSet.add(serviceCode);
|
||||
/* */ }
|
||||
/* */ } else {
|
||||
/* 301 */ topicServiceCodeMap = new HashMap<>();
|
||||
/* 302 */ topicServiceCodeMap.put(topic, Sets.newHashSet((Object[])new String[] { serviceCode }));
|
||||
/* 303 */ customSubscribedMap.put(groupId, topicServiceCodeMap);
|
||||
/* */ }
|
||||
/* 305 */ EventClient eventClient = this.eventClientMap.get(groupId);
|
||||
/* 306 */ if (null == eventClient) {
|
||||
/* 307 */ throw new IllegalArgumentException(String.format("没有找到groupId[%s]对应的配置,请检查 ${cloudwalk.event.group-id} 配置", new Object[] { groupId }));
|
||||
/* */ }
|
||||
/* */
|
||||
/* 310 */ eventClient.subEvent(topic, serviceCode, eventClass.newInstance());
|
||||
/* */ }
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */ private void initEventClient(String bootstrapServers, String groupId, Class<? extends EventListener> listenerClass, boolean isDefault) {
|
||||
/* 316 */ EventClient eventClient = this.eventClientMap.get(groupId);
|
||||
/* */
|
||||
/* 318 */ if (null == eventClient) {
|
||||
/* 319 */ eventClient = EventClient.getInstance(bootstrapServers, groupId);
|
||||
/* 320 */ eventClient.init();
|
||||
/* 321 */ if (null != this.eventProperties.getFetchDataWorkerNumber()) {
|
||||
/* 322 */ eventClient.setWorkNum(this.eventProperties.getFetchDataWorkerNumber());
|
||||
/* */ }
|
||||
/* 324 */ eventClient.setListenerClass(listenerClass);
|
||||
/* */
|
||||
/* 326 */ this.eventClientMap.put(groupId, eventClient);
|
||||
/* */ }
|
||||
/* */
|
||||
/* 329 */ if (isDefault) {
|
||||
/* 330 */ this.defaultGroup = groupId;
|
||||
/* 331 */ this.defaultEventClient = eventClient;
|
||||
/* */ }
|
||||
/* */ }
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */ private <E extends BaseEvent> void registerHandlerMapping(EventHandlerMapping eventHandlerMapping, EventHandler<E> handler, Class<E> eventClass, String[] suffixes) {
|
||||
/* 349 */ List<String> groupIds = extractGroupIds(handler);
|
||||
/* 350 */ EventType eventType = getEventType(eventClass);
|
||||
/* */
|
||||
/* 352 */ for (String groupId : groupIds) {
|
||||
/* 353 */ Map<String, List<EventHandler>> handlers = eventHandlerMapping.getServiceCodeHandlerListMap(groupId, eventType);
|
||||
/* */
|
||||
/* 355 */ if (CollectionUtils.isEmpty(handlers)) {
|
||||
/* 356 */ handlers = new HashMap<>();
|
||||
/* 357 */ if (null == suffixes || suffixes.length == 0) {
|
||||
/* 358 */ handlers.put("", Lists.newArrayList((Object[])new EventHandler[] { handler }));
|
||||
/* */ } else {
|
||||
/* 360 */ for (String suffix : suffixes) {
|
||||
/* 361 */ handlers.put(suffix, Lists.newArrayList((Object[])new EventHandler[] { handler }));
|
||||
/* */ }
|
||||
/* */ }
|
||||
/* */
|
||||
/* 365 */ eventHandlerMapping.registerHandlers(groupId, eventType, handlers); continue;
|
||||
/* */ }
|
||||
/* 367 */ if (null == suffixes || suffixes.length == 0) {
|
||||
/* 368 */ List<EventHandler> currentHandlers = handlers.get("");
|
||||
/* 369 */ if (CollectionUtils.isEmpty(currentHandlers)) {
|
||||
/* 370 */ currentHandlers = new ArrayList<>();
|
||||
/* */ }
|
||||
/* 372 */ currentHandlers.add(handler);
|
||||
/* 373 */ handlers.put("", currentHandlers); continue;
|
||||
/* */ }
|
||||
/* 375 */ for (String suffix : suffixes) {
|
||||
/* 376 */ List<EventHandler> currentHandlers = handlers.get(suffix);
|
||||
/* 377 */ if (CollectionUtils.isEmpty(currentHandlers)) {
|
||||
/* 378 */ currentHandlers = new ArrayList<>();
|
||||
/* */ }
|
||||
/* 380 */ currentHandlers.add(handler);
|
||||
/* 381 */ handlers.put(suffix, currentHandlers);
|
||||
/* */ }
|
||||
/* */ }
|
||||
/* */ }
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */ private void registerCustomHandlerMapping(EventHandlerMapping eventHandlerMapping, EventHandler<? extends CustomEvent> handler, String topic, String serviceCode) {
|
||||
/* 392 */ List<String> groupIds = extractGroupIds(handler);
|
||||
/* */
|
||||
/* 394 */ for (String groupId : groupIds) {
|
||||
/* */
|
||||
/* */
|
||||
/* 397 */ Map<String, List<CustomEventHandler>> customHandlers = eventHandlerMapping.getServiceCodeCustomHandlerListMap(groupId, topic);
|
||||
/* */
|
||||
/* 399 */ if (null == customHandlers) {
|
||||
/* 400 */ customHandlers = new HashMap<>();
|
||||
/* 401 */ if (StringUtils.isEmpty(topic)) {
|
||||
/* 402 */ customHandlers.put("", Lists.newArrayList((Object[])new CustomEventHandler[] { (CustomEventHandler)handler }));
|
||||
/* */ } else {
|
||||
/* 404 */ customHandlers.put(serviceCode, Lists.newArrayList((Object[])new CustomEventHandler[] { (CustomEventHandler)handler }));
|
||||
/* */ }
|
||||
/* 406 */ eventHandlerMapping.registerCustomHandlers(groupId, topic, customHandlers); continue;
|
||||
/* */ }
|
||||
/* 408 */ if (StringUtils.isEmpty(serviceCode)) {
|
||||
/* 409 */ List<CustomEventHandler> list = customHandlers.get("");
|
||||
/* 410 */ if (CollectionUtils.isEmpty(list)) {
|
||||
/* 411 */ list = new ArrayList<>();
|
||||
/* */ }
|
||||
/* 413 */ list.add((CustomEventHandler)handler);
|
||||
/* 414 */ customHandlers.put("", list); continue;
|
||||
/* */ }
|
||||
/* 416 */ List<CustomEventHandler> currentHandlers = customHandlers.get(serviceCode);
|
||||
/* 417 */ if (CollectionUtils.isEmpty(currentHandlers)) {
|
||||
/* 418 */ currentHandlers = new ArrayList<>();
|
||||
/* */ }
|
||||
/* 420 */ currentHandlers.add((CustomEventHandler)handler);
|
||||
/* 421 */ customHandlers.put(serviceCode, currentHandlers);
|
||||
/* */ }
|
||||
/* */ }
|
||||
/* */ }
|
||||
|
||||
|
||||
/* Location: D:\星中心\cw-elevator-application-V1.0.0.20211103\cw-elevator-application-V1.0.0.20211103\lib\cloudwalk-common-event-3.7.2-Brussels-SRX.jar!\cn\cloudwalk\event\CloudwalkEventInitializing.class
|
||||
* Java compiler version: 7 (51.0)
|
||||
* JD-Core Version: 1.1.3
|
||||
*/
|
||||
package cn.cloudwalk.event;
|
||||
|
||||
import cn.cloudwalk.cwos.client.event.EventClient;
|
||||
import cn.cloudwalk.cwos.client.event.event.BaseEvent;
|
||||
import cn.cloudwalk.cwos.client.event.event.CustomEvent;
|
||||
import cn.cloudwalk.cwos.client.event.event.EventType;
|
||||
import cn.cloudwalk.cwos.client.event.handler.EventListener;
|
||||
import cn.cloudwalk.event.annotation.ConsumerGroup;
|
||||
import cn.cloudwalk.event.annotation.CustomTopic;
|
||||
import cn.cloudwalk.event.annotation.EventTopicSuffix;
|
||||
import cn.cloudwalk.event.autoconfig.EventProperties;
|
||||
import cn.cloudwalk.event.handler.CustomEventHandler;
|
||||
import cn.cloudwalk.event.handler.EventHandler;
|
||||
import cn.cloudwalk.event.handler.EventHandlerMapping;
|
||||
import cn.cloudwalk.event.handler.EventHandlerWorker;
|
||||
import cn.cloudwalk.event.handler.NamedThreadFactory;
|
||||
import cn.cloudwalk.event.listener.CloudwalkEventListener;
|
||||
import cn.cloudwalk.event.listener.GroupEventListener;
|
||||
import cn.cloudwalk.event.listener.GroupListnerClassMapping;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.SynchronousQueue;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
public class CloudwalkEventInitializing
|
||||
implements CommandLineRunner {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(CloudwalkEventInitializing.class);
|
||||
|
||||
@Autowired(required = false)
|
||||
private List<EventHandler> eventHandlers;
|
||||
|
||||
@Autowired
|
||||
private CloudwalkEventManager cloudwalkEventManager;
|
||||
|
||||
@Autowired
|
||||
private Environment environment;
|
||||
|
||||
private static final Pattern pattern = Pattern.compile("^\\$\\{(.*?)\\}$");
|
||||
|
||||
|
||||
private static final String DEFAULT_SUFFIX = "";
|
||||
|
||||
|
||||
private String defaultGroup;
|
||||
|
||||
|
||||
private EventClient defaultEventClient;
|
||||
|
||||
private Map<String, EventClient> eventClientMap = new HashMap<>();
|
||||
|
||||
private EventProperties eventProperties;
|
||||
|
||||
private static boolean isHandlerEnable = false;
|
||||
|
||||
|
||||
public void run(String... args) throws Exception {
|
||||
init();
|
||||
}
|
||||
|
||||
public void init() throws Exception {
|
||||
initEventClient();
|
||||
initHandlerMapping();
|
||||
initHandlerExecutor();
|
||||
subscribeEvent();
|
||||
}
|
||||
|
||||
public CloudwalkEventInitializing(EventProperties eventProperties) {
|
||||
this.eventProperties = eventProperties;
|
||||
}
|
||||
|
||||
|
||||
private void initEventClient() throws ClassNotFoundException {
|
||||
String[] groupIds = this.eventProperties.getGroupId().split(",");
|
||||
|
||||
if (groupIds.length == 0) {
|
||||
throw new IllegalArgumentException("消费组ID不能为空");
|
||||
}
|
||||
|
||||
Map<String, String> listenerClassMap = this.eventProperties.getListenerClass();
|
||||
|
||||
GroupListnerClassMapping groupListnerClassMapping = new GroupListnerClassMapping();
|
||||
|
||||
for (int i = 0; i < groupIds.length; i++) {
|
||||
Class<? extends EventListener> listenerClass; boolean isFirst = (i == 0);
|
||||
String groupId = groupIds[i];
|
||||
|
||||
|
||||
|
||||
if (null == listenerClassMap || StringUtils.isEmpty(listenerClassMap.get(groupId))) {
|
||||
if (isFirst) {
|
||||
Class<CloudwalkEventListener> clazz = CloudwalkEventListener.class;
|
||||
} else {
|
||||
throw new IllegalArgumentException(String.format("groupId[%s]缺少listener-class的配置", new Object[] { groupId }));
|
||||
}
|
||||
} else {
|
||||
listenerClass = (Class)Class.forName(listenerClassMap.get(groupId));
|
||||
}
|
||||
|
||||
initEventClient(this.eventProperties.getBootstrapServers(), groupId, listenerClass, isFirst);
|
||||
groupListnerClassMapping.register(listenerClass, groupId);
|
||||
}
|
||||
|
||||
this.cloudwalkEventManager.setGroupListnerClassMapping(groupListnerClassMapping);
|
||||
this.cloudwalkEventManager.setEventClient(this.defaultEventClient);
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
||||
GroupEventListener.applicationContext = applicationContext;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private List<String> extractGroupIds(EventHandler eventHandler) {
|
||||
if (eventHandler.getClass().isAnnotationPresent((Class)ConsumerGroup.class)) {
|
||||
ConsumerGroup consumerGroup = eventHandler.getClass().<ConsumerGroup>getAnnotation(ConsumerGroup.class);
|
||||
|
||||
List<String> groupIds = new LinkedList<>();
|
||||
for (String groupId : consumerGroup.groupIds()) {
|
||||
Matcher matcher = pattern.matcher(groupId);
|
||||
if (matcher.find()) {
|
||||
String propertyKey = groupId.substring(2, groupId.length() - 1).trim();
|
||||
String propertyValue = this.environment.getProperty(propertyKey);
|
||||
if (!StringUtils.isEmpty(propertyValue)) {
|
||||
groupId = propertyValue;
|
||||
}
|
||||
}
|
||||
groupIds.add(groupId);
|
||||
}
|
||||
|
||||
return groupIds;
|
||||
}
|
||||
return Lists.newArrayList((Object[])new String[] { this.defaultGroup });
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private void initHandlerMapping() {
|
||||
if (CollectionUtils.isEmpty(this.eventHandlers)) {
|
||||
return;
|
||||
}
|
||||
|
||||
isHandlerEnable = true;
|
||||
|
||||
EventHandlerMapping eventHandlerMapping = new EventHandlerMapping();
|
||||
|
||||
for (EventHandler<BaseEvent> handler : this.eventHandlers) {
|
||||
if (handler.getClass().isAnnotationPresent((Class)EventTopicSuffix.class)) {
|
||||
Type type = handler.getClass().getGenericInterfaces()[0];
|
||||
ParameterizedType p = (ParameterizedType)type;
|
||||
Class<BaseEvent> eventClass = (Class)p.getActualTypeArguments()[0];
|
||||
EventTopicSuffix eventTopicSuffix = handler.getClass().<EventTopicSuffix>getAnnotation(EventTopicSuffix.class);
|
||||
|
||||
registerHandlerMapping(eventHandlerMapping, handler, eventClass, eventTopicSuffix.value()); continue;
|
||||
} if (handler.getClass().isAnnotationPresent((Class)CustomTopic.class)) {
|
||||
CustomTopic customTopic = handler.getClass().<CustomTopic>getAnnotation(CustomTopic.class);
|
||||
String topic = customTopic.topic();
|
||||
if (StringUtils.isEmpty(topic)) {
|
||||
continue;
|
||||
}
|
||||
registerCustomHandlerMapping(eventHandlerMapping, (EventHandler)handler, topic, customTopic.suffix());
|
||||
}
|
||||
}
|
||||
this.cloudwalkEventManager.setEventHandlerMapping(eventHandlerMapping);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private void initHandlerExecutor() {
|
||||
if (isHandlerEnable) {
|
||||
EventHandlerWorker eventHandlerWorker = new EventHandlerWorker();
|
||||
EventProperties.HandlerExecutorConfig handlerExecutorConfig = this.eventProperties.getHandlerExecutorConfig();
|
||||
eventHandlerWorker.setPoolExecutor(new ThreadPoolExecutor(handlerExecutorConfig.getCorePoolSize().intValue(), handlerExecutorConfig
|
||||
.getMaximumPoolSize().intValue(), 1000L, TimeUnit.MILLISECONDS, new SynchronousQueue<>(), (ThreadFactory)new NamedThreadFactory(this.eventProperties
|
||||
.getWorkerNamePrefix()), new ThreadPoolExecutor.CallerRunsPolicy()));
|
||||
this.cloudwalkEventManager.setEventHandlerWorker(eventHandlerWorker);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private EventType getEventType(Class<? extends BaseEvent> eventClass) {
|
||||
for (EventType eventType : EventType.values()) {
|
||||
if (eventType.getEventClass().getClass().equals(eventClass)) {
|
||||
return eventType;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private void subscribeEvent() throws IllegalAccessException, InstantiationException {
|
||||
EventHandlerMapping eventHandlerMapping = this.cloudwalkEventManager.getEventHandlerMapping();
|
||||
|
||||
Map<String, Map<EventType, Set<String>>> subscribedMap = new HashMap<>();
|
||||
|
||||
for (Map.Entry<String, Map<EventType, Map<String, List<EventHandler>>>> entry : (Iterable<Map.Entry<String, Map<EventType, Map<String, List<EventHandler>>>>>)eventHandlerMapping.getHandlerMap().entrySet()) {
|
||||
for (Map.Entry<EventType, Map<String, List<EventHandler>>> eventTypeMapEntry : (Iterable<Map.Entry<EventType, Map<String, List<EventHandler>>>>)((Map)entry.getValue()).entrySet()) {
|
||||
for (String serviceCode : ((Map)eventTypeMapEntry.getValue()).keySet()) {
|
||||
subscribe(subscribedMap, entry.getKey(), eventTypeMapEntry.getKey(), serviceCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, Map<String, Set<String>>> customSubscribedMap = new HashMap<>();
|
||||
|
||||
for (Map.Entry<String, Map<String, Map<String, List<CustomEventHandler>>>> entry : (Iterable<Map.Entry<String, Map<String, Map<String, List<CustomEventHandler>>>>>)eventHandlerMapping.getCustomHandlerMap().entrySet()) {
|
||||
for (Map.Entry<String, Map<String, List<CustomEventHandler>>> subEntry : (Iterable<Map.Entry<String, Map<String, List<CustomEventHandler>>>>)((Map)entry.getValue()).entrySet()) {
|
||||
for (Map.Entry<String, List<CustomEventHandler>> handlerEntry : (Iterable<Map.Entry<String, List<CustomEventHandler>>>)((Map)subEntry.getValue()).entrySet()) {
|
||||
for (CustomEventHandler customEventHandler : handlerEntry.getValue()) {
|
||||
Type type = customEventHandler.getClass().getGenericInterfaces()[0];
|
||||
ParameterizedType p = (ParameterizedType)type;
|
||||
Class<? extends CustomEvent> eventClass = (Class)p.getActualTypeArguments()[0];
|
||||
customSubscribe(customSubscribedMap, entry.getKey(), subEntry.getKey(), handlerEntry
|
||||
.getKey(), eventClass);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private void subscribe(Map<String, Map<EventType, Set<String>>> subscribedMap, String groupId, EventType eventType, String serviceCode) {
|
||||
if (StringUtils.isEmpty(groupId)) {
|
||||
groupId = this.defaultGroup;
|
||||
}
|
||||
|
||||
Map<EventType, Set<String>> eventTypeServiceCodeMap = subscribedMap.get(groupId);
|
||||
if (null != eventTypeServiceCodeMap) {
|
||||
Set<String> serviceCodesSet = eventTypeServiceCodeMap.get(eventType);
|
||||
if (CollectionUtils.isEmpty(serviceCodesSet)) {
|
||||
eventTypeServiceCodeMap.put(eventType, Sets.newHashSet((Object[])new String[] { serviceCode }));
|
||||
} else {
|
||||
serviceCodesSet.add(serviceCode);
|
||||
}
|
||||
} else {
|
||||
eventTypeServiceCodeMap = new HashMap<>();
|
||||
eventTypeServiceCodeMap.put(eventType, Sets.newHashSet((Object[])new String[] { serviceCode }));
|
||||
subscribedMap.put(groupId, eventTypeServiceCodeMap);
|
||||
}
|
||||
((EventClient)this.eventClientMap.get(groupId)).subEvent(eventType, serviceCode);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void customSubscribe(Map<String, Map<String, Set<String>>> customSubscribedMap, String groupId, String topic, String serviceCode, Class<? extends CustomEvent> eventClass) throws IllegalAccessException, InstantiationException {
|
||||
if (StringUtils.isEmpty(groupId)) {
|
||||
groupId = this.defaultGroup;
|
||||
}
|
||||
|
||||
Map<String, Set<String>> topicServiceCodeMap = customSubscribedMap.get(groupId);
|
||||
if (null != topicServiceCodeMap) {
|
||||
Set<String> serviceCodesSet = topicServiceCodeMap.get(topic);
|
||||
if (CollectionUtils.isEmpty(serviceCodesSet)) {
|
||||
topicServiceCodeMap.put(topic, Sets.newHashSet((Object[])new String[] { serviceCode }));
|
||||
} else {
|
||||
serviceCodesSet.add(serviceCode);
|
||||
}
|
||||
} else {
|
||||
topicServiceCodeMap = new HashMap<>();
|
||||
topicServiceCodeMap.put(topic, Sets.newHashSet((Object[])new String[] { serviceCode }));
|
||||
customSubscribedMap.put(groupId, topicServiceCodeMap);
|
||||
}
|
||||
EventClient eventClient = this.eventClientMap.get(groupId);
|
||||
if (null == eventClient) {
|
||||
throw new IllegalArgumentException(String.format("没有找到groupId[%s]对应的配置,请检查 ${cloudwalk.event.group-id} 配置", new Object[] { groupId }));
|
||||
}
|
||||
|
||||
eventClient.subEvent(topic, serviceCode, eventClass.newInstance());
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void initEventClient(String bootstrapServers, String groupId, Class<? extends EventListener> listenerClass, boolean isDefault) {
|
||||
EventClient eventClient = this.eventClientMap.get(groupId);
|
||||
|
||||
if (null == eventClient) {
|
||||
eventClient = EventClient.getInstance(bootstrapServers, groupId);
|
||||
eventClient.init();
|
||||
if (null != this.eventProperties.getFetchDataWorkerNumber()) {
|
||||
eventClient.setWorkNum(this.eventProperties.getFetchDataWorkerNumber());
|
||||
}
|
||||
eventClient.setListenerClass(listenerClass);
|
||||
|
||||
this.eventClientMap.put(groupId, eventClient);
|
||||
}
|
||||
|
||||
if (isDefault) {
|
||||
this.defaultGroup = groupId;
|
||||
this.defaultEventClient = eventClient;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private <E extends BaseEvent> void registerHandlerMapping(EventHandlerMapping eventHandlerMapping, EventHandler<E> handler, Class<E> eventClass, String[] suffixes) {
|
||||
List<String> groupIds = extractGroupIds(handler);
|
||||
EventType eventType = getEventType(eventClass);
|
||||
|
||||
for (String groupId : groupIds) {
|
||||
Map<String, List<EventHandler>> handlers = eventHandlerMapping.getServiceCodeHandlerListMap(groupId, eventType);
|
||||
|
||||
if (CollectionUtils.isEmpty(handlers)) {
|
||||
handlers = new HashMap<>();
|
||||
if (null == suffixes || suffixes.length == 0) {
|
||||
handlers.put("", Lists.newArrayList((Object[])new EventHandler[] { handler }));
|
||||
} else {
|
||||
for (String suffix : suffixes) {
|
||||
handlers.put(suffix, Lists.newArrayList((Object[])new EventHandler[] { handler }));
|
||||
}
|
||||
}
|
||||
|
||||
eventHandlerMapping.registerHandlers(groupId, eventType, handlers); continue;
|
||||
}
|
||||
if (null == suffixes || suffixes.length == 0) {
|
||||
List<EventHandler> currentHandlers = handlers.get("");
|
||||
if (CollectionUtils.isEmpty(currentHandlers)) {
|
||||
currentHandlers = new ArrayList<>();
|
||||
}
|
||||
currentHandlers.add(handler);
|
||||
handlers.put("", currentHandlers); continue;
|
||||
}
|
||||
for (String suffix : suffixes) {
|
||||
List<EventHandler> currentHandlers = handlers.get(suffix);
|
||||
if (CollectionUtils.isEmpty(currentHandlers)) {
|
||||
currentHandlers = new ArrayList<>();
|
||||
}
|
||||
currentHandlers.add(handler);
|
||||
handlers.put(suffix, currentHandlers);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private void registerCustomHandlerMapping(EventHandlerMapping eventHandlerMapping, EventHandler<? extends CustomEvent> handler, String topic, String serviceCode) {
|
||||
List<String> groupIds = extractGroupIds(handler);
|
||||
|
||||
for (String groupId : groupIds) {
|
||||
|
||||
|
||||
Map<String, List<CustomEventHandler>> customHandlers = eventHandlerMapping.getServiceCodeCustomHandlerListMap(groupId, topic);
|
||||
|
||||
if (null == customHandlers) {
|
||||
customHandlers = new HashMap<>();
|
||||
if (StringUtils.isEmpty(topic)) {
|
||||
customHandlers.put("", Lists.newArrayList((Object[])new CustomEventHandler[] { (CustomEventHandler)handler }));
|
||||
} else {
|
||||
customHandlers.put(serviceCode, Lists.newArrayList((Object[])new CustomEventHandler[] { (CustomEventHandler)handler }));
|
||||
}
|
||||
eventHandlerMapping.registerCustomHandlers(groupId, topic, customHandlers); continue;
|
||||
}
|
||||
if (StringUtils.isEmpty(serviceCode)) {
|
||||
List<CustomEventHandler> list = customHandlers.get("");
|
||||
if (CollectionUtils.isEmpty(list)) {
|
||||
list = new ArrayList<>();
|
||||
}
|
||||
list.add((CustomEventHandler)handler);
|
||||
customHandlers.put("", list); continue;
|
||||
}
|
||||
List<CustomEventHandler> currentHandlers = customHandlers.get(serviceCode);
|
||||
if (CollectionUtils.isEmpty(currentHandlers)) {
|
||||
currentHandlers = new ArrayList<>();
|
||||
}
|
||||
currentHandlers.add((CustomEventHandler)handler);
|
||||
customHandlers.put(serviceCode, currentHandlers);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
+108
-112
@@ -1,112 +1,108 @@
|
||||
/* */ package cn.cloudwalk.event;
|
||||
/* */
|
||||
/* */ import cn.cloudwalk.cwos.client.event.EventClient;
|
||||
/* */ import cn.cloudwalk.cwos.client.event.event.BaseEvent;
|
||||
/* */ import cn.cloudwalk.cwos.client.event.event.CustomEvent;
|
||||
/* */ import cn.cloudwalk.event.handler.CustomEventHandler;
|
||||
/* */ import cn.cloudwalk.event.handler.EventHandler;
|
||||
/* */ import cn.cloudwalk.event.handler.EventHandlerMapping;
|
||||
/* */ import cn.cloudwalk.event.handler.EventHandlerWorker;
|
||||
/* */ import cn.cloudwalk.event.listener.GroupEventListener;
|
||||
/* */ import cn.cloudwalk.event.listener.GroupListnerClassMapping;
|
||||
/* */ import cn.cloudwalk.event.task.EventHandleTask;
|
||||
/* */ import java.util.List;
|
||||
/* */ import org.slf4j.Logger;
|
||||
/* */ import org.slf4j.LoggerFactory;
|
||||
/* */ import org.springframework.util.CollectionUtils;
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */ public class CloudwalkEventManager
|
||||
/* */ {
|
||||
/* 30 */ private static final Logger LOGGER = LoggerFactory.getLogger(CloudwalkEventManager.class);
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */ private EventHandlerMapping eventHandlerMapping;
|
||||
/* */
|
||||
/* */
|
||||
/* */ private EventHandlerWorker eventHandlerWorker;
|
||||
/* */
|
||||
/* */
|
||||
/* */ private GroupListnerClassMapping groupListnerClassMapping;
|
||||
/* */
|
||||
/* */
|
||||
/* */ private EventClient eventClient;
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */ public void handle(Class<? extends GroupEventListener> eventListnerClass, BaseEvent baseEvent) {
|
||||
/* 48 */ String groupId = this.groupListnerClassMapping.getGroupId(eventListnerClass);
|
||||
/* */
|
||||
/* 50 */ if (baseEvent instanceof CustomEvent) {
|
||||
/* */
|
||||
/* */
|
||||
/* 53 */ List<CustomEventHandler> customEventHandlers = (List<CustomEventHandler>)this.eventHandlerMapping.getServiceCodeCustomHandlerListMap(groupId, ((CustomEvent)baseEvent).getTopic()).get(baseEvent.getServiceCode());
|
||||
/* 54 */ eventHandle(baseEvent, customEventHandlers);
|
||||
/* */
|
||||
/* */ return;
|
||||
/* */ }
|
||||
/* */
|
||||
/* 59 */ List<EventHandler> handlerList = (List<EventHandler>)this.eventHandlerMapping.getServiceCodeHandlerListMap(groupId, baseEvent.getClass()).get(baseEvent.getServiceCode());
|
||||
/* 60 */ eventHandle(baseEvent, handlerList);
|
||||
/* */ }
|
||||
/* */
|
||||
/* */ private <H extends EventHandler> void eventHandle(BaseEvent baseEvent, List<H> handlers) {
|
||||
/* 64 */ if (CollectionUtils.isEmpty(handlers)) {
|
||||
/* 65 */ LOGGER.error("没有相应的事件处理程序");
|
||||
/* */ return;
|
||||
/* */ }
|
||||
/* 68 */ for (EventHandler eventHandler : handlers) {
|
||||
/* 69 */ this.eventHandlerWorker.work(new EventHandleTask(baseEvent, eventHandler));
|
||||
/* */ }
|
||||
/* */ }
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */ public void publish(BaseEvent baseEvent) {
|
||||
/* 79 */ this.eventClient.pubEvent(baseEvent);
|
||||
/* */ }
|
||||
/* */
|
||||
/* */ public void setEventHandlerMapping(EventHandlerMapping eventHandlerMapping) {
|
||||
/* 83 */ this.eventHandlerMapping = eventHandlerMapping;
|
||||
/* */ }
|
||||
/* */
|
||||
/* */ public EventHandlerMapping getEventHandlerMapping() {
|
||||
/* 87 */ return this.eventHandlerMapping;
|
||||
/* */ }
|
||||
/* */
|
||||
/* */ public void setEventHandlerWorker(EventHandlerWorker eventHandlerWorker) {
|
||||
/* 91 */ this.eventHandlerWorker = eventHandlerWorker;
|
||||
/* */ }
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */ public void setEventClient(EventClient eventClient) {
|
||||
/* 100 */ this.eventClient = eventClient;
|
||||
/* */ }
|
||||
/* */
|
||||
/* */ public void setGroupListnerClassMapping(GroupListnerClassMapping groupListnerClassMapping) {
|
||||
/* 104 */ this.groupListnerClassMapping = groupListnerClassMapping;
|
||||
/* */ }
|
||||
/* */ }
|
||||
|
||||
|
||||
/* Location: D:\星中心\cw-elevator-application-V1.0.0.20211103\cw-elevator-application-V1.0.0.20211103\lib\cloudwalk-common-event-3.7.2-Brussels-SRX.jar!\cn\cloudwalk\event\CloudwalkEventManager.class
|
||||
* Java compiler version: 7 (51.0)
|
||||
* JD-Core Version: 1.1.3
|
||||
*/
|
||||
package cn.cloudwalk.event;
|
||||
|
||||
import cn.cloudwalk.cwos.client.event.EventClient;
|
||||
import cn.cloudwalk.cwos.client.event.event.BaseEvent;
|
||||
import cn.cloudwalk.cwos.client.event.event.CustomEvent;
|
||||
import cn.cloudwalk.event.handler.CustomEventHandler;
|
||||
import cn.cloudwalk.event.handler.EventHandler;
|
||||
import cn.cloudwalk.event.handler.EventHandlerMapping;
|
||||
import cn.cloudwalk.event.handler.EventHandlerWorker;
|
||||
import cn.cloudwalk.event.listener.GroupEventListener;
|
||||
import cn.cloudwalk.event.listener.GroupListnerClassMapping;
|
||||
import cn.cloudwalk.event.task.EventHandleTask;
|
||||
import java.util.List;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public class CloudwalkEventManager
|
||||
{
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(CloudwalkEventManager.class);
|
||||
|
||||
|
||||
|
||||
private EventHandlerMapping eventHandlerMapping;
|
||||
|
||||
|
||||
private EventHandlerWorker eventHandlerWorker;
|
||||
|
||||
|
||||
private GroupListnerClassMapping groupListnerClassMapping;
|
||||
|
||||
|
||||
private EventClient eventClient;
|
||||
|
||||
|
||||
|
||||
public void handle(Class<? extends GroupEventListener> eventListnerClass, BaseEvent baseEvent) {
|
||||
String groupId = this.groupListnerClassMapping.getGroupId(eventListnerClass);
|
||||
|
||||
if (baseEvent instanceof CustomEvent) {
|
||||
|
||||
|
||||
List<CustomEventHandler> customEventHandlers = (List<CustomEventHandler>)this.eventHandlerMapping.getServiceCodeCustomHandlerListMap(groupId, ((CustomEvent)baseEvent).getTopic()).get(baseEvent.getServiceCode());
|
||||
eventHandle(baseEvent, customEventHandlers);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
List<EventHandler> handlerList = (List<EventHandler>)this.eventHandlerMapping.getServiceCodeHandlerListMap(groupId, baseEvent.getClass()).get(baseEvent.getServiceCode());
|
||||
eventHandle(baseEvent, handlerList);
|
||||
}
|
||||
|
||||
private <H extends EventHandler> void eventHandle(BaseEvent baseEvent, List<H> handlers) {
|
||||
if (CollectionUtils.isEmpty(handlers)) {
|
||||
LOGGER.error("没有相应的事件处理程序");
|
||||
return;
|
||||
}
|
||||
for (EventHandler eventHandler : handlers) {
|
||||
this.eventHandlerWorker.work(new EventHandleTask(baseEvent, eventHandler));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public void publish(BaseEvent baseEvent) {
|
||||
this.eventClient.pubEvent(baseEvent);
|
||||
}
|
||||
|
||||
public void setEventHandlerMapping(EventHandlerMapping eventHandlerMapping) {
|
||||
this.eventHandlerMapping = eventHandlerMapping;
|
||||
}
|
||||
|
||||
public EventHandlerMapping getEventHandlerMapping() {
|
||||
return this.eventHandlerMapping;
|
||||
}
|
||||
|
||||
public void setEventHandlerWorker(EventHandlerWorker eventHandlerWorker) {
|
||||
this.eventHandlerWorker = eventHandlerWorker;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public void setEventClient(EventClient eventClient) {
|
||||
this.eventClient = eventClient;
|
||||
}
|
||||
|
||||
public void setGroupListnerClassMapping(GroupListnerClassMapping groupListnerClassMapping) {
|
||||
this.groupListnerClassMapping = groupListnerClassMapping;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
+17
-21
@@ -1,21 +1,17 @@
|
||||
package cn.cloudwalk.event;
|
||||
|
||||
import cn.cloudwalk.event.autoconfig.EventConfiguration;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
@Target({ElementType.TYPE})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Import({EventConfiguration.class})
|
||||
public @interface EnableCloudwalkEvent {}
|
||||
|
||||
|
||||
/* Location: D:\星中心\cw-elevator-application-V1.0.0.20211103\cw-elevator-application-V1.0.0.20211103\lib\cloudwalk-common-event-3.7.2-Brussels-SRX.jar!\cn\cloudwalk\event\EnableCloudwalkEvent.class
|
||||
* Java compiler version: 7 (51.0)
|
||||
* JD-Core Version: 1.1.3
|
||||
*/
|
||||
package cn.cloudwalk.event;
|
||||
|
||||
import cn.cloudwalk.event.autoconfig.EventConfiguration;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
@Target({ElementType.TYPE})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Import({EventConfiguration.class})
|
||||
public @interface EnableCloudwalkEvent {}
|
||||
|
||||
|
||||
|
||||
+16
-20
@@ -1,20 +1,16 @@
|
||||
package cn.cloudwalk.event.annotation;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target({ElementType.TYPE})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
public @interface ConsumerGroup {
|
||||
String[] groupIds() default {};
|
||||
}
|
||||
|
||||
|
||||
/* Location: D:\星中心\cw-elevator-application-V1.0.0.20211103\cw-elevator-application-V1.0.0.20211103\lib\cloudwalk-common-event-3.7.2-Brussels-SRX.jar!\cn\cloudwalk\event\annotation\ConsumerGroup.class
|
||||
* Java compiler version: 7 (51.0)
|
||||
* JD-Core Version: 1.1.3
|
||||
*/
|
||||
package cn.cloudwalk.event.annotation;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target({ElementType.TYPE})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
public @interface ConsumerGroup {
|
||||
String[] groupIds() default {};
|
||||
}
|
||||
|
||||
|
||||
|
||||
+21
-25
@@ -1,25 +1,21 @@
|
||||
package cn.cloudwalk.event.annotation;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import org.springframework.core.annotation.AliasFor;
|
||||
|
||||
@Target({ElementType.TYPE})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@EventTopicSuffix
|
||||
public @interface CustomTopic {
|
||||
String topic();
|
||||
|
||||
@AliasFor(annotation = EventTopicSuffix.class)
|
||||
String suffix() default "";
|
||||
}
|
||||
|
||||
|
||||
/* Location: D:\星中心\cw-elevator-application-V1.0.0.20211103\cw-elevator-application-V1.0.0.20211103\lib\cloudwalk-common-event-3.7.2-Brussels-SRX.jar!\cn\cloudwalk\event\annotation\CustomTopic.class
|
||||
* Java compiler version: 7 (51.0)
|
||||
* JD-Core Version: 1.1.3
|
||||
*/
|
||||
package cn.cloudwalk.event.annotation;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import org.springframework.core.annotation.AliasFor;
|
||||
|
||||
@Target({ElementType.TYPE})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@EventTopicSuffix
|
||||
public @interface CustomTopic {
|
||||
String topic();
|
||||
|
||||
@AliasFor(annotation = EventTopicSuffix.class)
|
||||
String suffix() default "";
|
||||
}
|
||||
|
||||
|
||||
|
||||
+21
-25
@@ -1,25 +1,21 @@
|
||||
package cn.cloudwalk.event.annotation;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import org.springframework.core.annotation.AliasFor;
|
||||
|
||||
@Target({ElementType.TYPE})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
public @interface EventTopicSuffix {
|
||||
@AliasFor(attribute = "suffix")
|
||||
String[] value() default {};
|
||||
|
||||
@AliasFor(attribute = "value")
|
||||
String[] suffix() default {};
|
||||
}
|
||||
|
||||
|
||||
/* Location: D:\星中心\cw-elevator-application-V1.0.0.20211103\cw-elevator-application-V1.0.0.20211103\lib\cloudwalk-common-event-3.7.2-Brussels-SRX.jar!\cn\cloudwalk\event\annotation\EventTopicSuffix.class
|
||||
* Java compiler version: 7 (51.0)
|
||||
* JD-Core Version: 1.1.3
|
||||
*/
|
||||
package cn.cloudwalk.event.annotation;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import org.springframework.core.annotation.AliasFor;
|
||||
|
||||
@Target({ElementType.TYPE})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
public @interface EventTopicSuffix {
|
||||
@AliasFor(attribute = "suffix")
|
||||
String[] value() default {};
|
||||
|
||||
@AliasFor(attribute = "value")
|
||||
String[] suffix() default {};
|
||||
}
|
||||
|
||||
|
||||
|
||||
+31
-35
@@ -1,35 +1,31 @@
|
||||
/* */ package cn.cloudwalk.event.autoconfig;
|
||||
/* */
|
||||
/* */ import cn.cloudwalk.event.CloudwalkEventInitializing;
|
||||
/* */ import cn.cloudwalk.event.CloudwalkEventManager;
|
||||
/* */ import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
/* */ import org.springframework.context.annotation.Bean;
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */ @EnableConfigurationProperties({EventProperties.class})
|
||||
/* */ public class EventConfiguration
|
||||
/* */ {
|
||||
/* */ @Bean
|
||||
/* */ public CloudwalkEventManager cloudwalkEventManager() {
|
||||
/* 22 */ return new CloudwalkEventManager();
|
||||
/* */ }
|
||||
/* */
|
||||
/* */ @Bean
|
||||
/* */ public CloudwalkEventInitializing CloudwalkEventInitializing(EventProperties eventProperties) {
|
||||
/* 27 */ return new CloudwalkEventInitializing(eventProperties);
|
||||
/* */ }
|
||||
/* */ }
|
||||
|
||||
|
||||
/* Location: D:\星中心\cw-elevator-application-V1.0.0.20211103\cw-elevator-application-V1.0.0.20211103\lib\cloudwalk-common-event-3.7.2-Brussels-SRX.jar!\cn\cloudwalk\event\autoconfig\EventConfiguration.class
|
||||
* Java compiler version: 7 (51.0)
|
||||
* JD-Core Version: 1.1.3
|
||||
*/
|
||||
package cn.cloudwalk.event.autoconfig;
|
||||
|
||||
import cn.cloudwalk.event.CloudwalkEventInitializing;
|
||||
import cn.cloudwalk.event.CloudwalkEventManager;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@EnableConfigurationProperties({EventProperties.class})
|
||||
public class EventConfiguration
|
||||
{
|
||||
@Bean
|
||||
public CloudwalkEventManager cloudwalkEventManager() {
|
||||
return new CloudwalkEventManager();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public CloudwalkEventInitializing CloudwalkEventInitializing(EventProperties eventProperties) {
|
||||
return new CloudwalkEventInitializing(eventProperties);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
+127
-131
@@ -1,131 +1,127 @@
|
||||
/* */ package cn.cloudwalk.event.autoconfig;
|
||||
/* */
|
||||
/* */ import java.util.Map;
|
||||
/* */ import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */ @ConfigurationProperties(prefix = "cloudwalk.event")
|
||||
/* */ public class EventProperties
|
||||
/* */ {
|
||||
/* */ protected static final String CONF_PREFIX = "cloudwalk.event";
|
||||
/* */ private String bootstrapServers;
|
||||
/* */ private String groupId;
|
||||
/* */ private Map<String, String> listenerClass;
|
||||
/* */ private Integer fetchDataWorkerNumber;
|
||||
/* */ private String workerNamePrefix;
|
||||
/* 49 */ private HandlerExecutorConfig handlerExecutorConfig = new HandlerExecutorConfig(Integer.valueOf(5), Integer.valueOf(10));
|
||||
/* */
|
||||
/* */ public static class HandlerExecutorConfig
|
||||
/* */ {
|
||||
/* */ private Integer corePoolSize;
|
||||
/* */ private Integer maximumPoolSize;
|
||||
/* */
|
||||
/* */ public HandlerExecutorConfig(Integer corePoolSize, Integer maximumPoolSize) {
|
||||
/* 57 */ this.corePoolSize = corePoolSize;
|
||||
/* 58 */ this.maximumPoolSize = maximumPoolSize;
|
||||
/* */ }
|
||||
/* */
|
||||
/* */ public Integer getCorePoolSize() {
|
||||
/* 62 */ return this.corePoolSize;
|
||||
/* */ }
|
||||
/* */
|
||||
/* */ public void setCorePoolSize(Integer corePoolSize) {
|
||||
/* 66 */ this.corePoolSize = corePoolSize;
|
||||
/* */ }
|
||||
/* */
|
||||
/* */ public Integer getMaximumPoolSize() {
|
||||
/* 70 */ return this.maximumPoolSize;
|
||||
/* */ }
|
||||
/* */
|
||||
/* */ public void setMaximumPoolSize(Integer maximumPoolSize) {
|
||||
/* 74 */ this.maximumPoolSize = maximumPoolSize;
|
||||
/* */ }
|
||||
/* */ }
|
||||
/* */
|
||||
/* */ public String getBootstrapServers() {
|
||||
/* 79 */ return this.bootstrapServers;
|
||||
/* */ }
|
||||
/* */
|
||||
/* */ public void setBootstrapServers(String bootstrapServers) {
|
||||
/* 83 */ this.bootstrapServers = bootstrapServers;
|
||||
/* */ }
|
||||
/* */
|
||||
/* */ public String getGroupId() {
|
||||
/* 87 */ return this.groupId;
|
||||
/* */ }
|
||||
/* */
|
||||
/* */ public void setGroupId(String groupId) {
|
||||
/* 91 */ this.groupId = groupId;
|
||||
/* */ }
|
||||
/* */
|
||||
/* */ public Map<String, String> getListenerClass() {
|
||||
/* 95 */ return this.listenerClass;
|
||||
/* */ }
|
||||
/* */
|
||||
/* */ public void setListenerClass(Map<String, String> listenerClass) {
|
||||
/* 99 */ this.listenerClass = listenerClass;
|
||||
/* */ }
|
||||
/* */
|
||||
/* */ public Integer getFetchDataWorkerNumber() {
|
||||
/* 103 */ return this.fetchDataWorkerNumber;
|
||||
/* */ }
|
||||
/* */
|
||||
/* */ public void setFetchDataWorkerNumber(Integer fetchDataWorkerNumber) {
|
||||
/* 107 */ this.fetchDataWorkerNumber = fetchDataWorkerNumber;
|
||||
/* */ }
|
||||
/* */
|
||||
/* */ public HandlerExecutorConfig getHandlerExecutorConfig() {
|
||||
/* 111 */ return this.handlerExecutorConfig;
|
||||
/* */ }
|
||||
/* */
|
||||
/* */ public void setHandlerExecutorConfig(HandlerExecutorConfig handlerExecutorConfig) {
|
||||
/* 115 */ this.handlerExecutorConfig = handlerExecutorConfig;
|
||||
/* */ }
|
||||
/* */
|
||||
/* */ public String getWorkerNamePrefix() {
|
||||
/* 119 */ return this.workerNamePrefix;
|
||||
/* */ }
|
||||
/* */
|
||||
/* */ public void setWorkerNamePrefix(String workerNamePrefix) {
|
||||
/* 123 */ this.workerNamePrefix = workerNamePrefix;
|
||||
/* */ }
|
||||
/* */ }
|
||||
|
||||
|
||||
/* Location: D:\星中心\cw-elevator-application-V1.0.0.20211103\cw-elevator-application-V1.0.0.20211103\lib\cloudwalk-common-event-3.7.2-Brussels-SRX.jar!\cn\cloudwalk\event\autoconfig\EventProperties.class
|
||||
* Java compiler version: 7 (51.0)
|
||||
* JD-Core Version: 1.1.3
|
||||
*/
|
||||
package cn.cloudwalk.event.autoconfig;
|
||||
|
||||
import java.util.Map;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ConfigurationProperties(prefix = "cloudwalk.event")
|
||||
public class EventProperties
|
||||
{
|
||||
protected static final String CONF_PREFIX = "cloudwalk.event";
|
||||
private String bootstrapServers;
|
||||
private String groupId;
|
||||
private Map<String, String> listenerClass;
|
||||
private Integer fetchDataWorkerNumber;
|
||||
private String workerNamePrefix;
|
||||
private HandlerExecutorConfig handlerExecutorConfig = new HandlerExecutorConfig(Integer.valueOf(5), Integer.valueOf(10));
|
||||
|
||||
public static class HandlerExecutorConfig
|
||||
{
|
||||
private Integer corePoolSize;
|
||||
private Integer maximumPoolSize;
|
||||
|
||||
public HandlerExecutorConfig(Integer corePoolSize, Integer maximumPoolSize) {
|
||||
this.corePoolSize = corePoolSize;
|
||||
this.maximumPoolSize = maximumPoolSize;
|
||||
}
|
||||
|
||||
public Integer getCorePoolSize() {
|
||||
return this.corePoolSize;
|
||||
}
|
||||
|
||||
public void setCorePoolSize(Integer corePoolSize) {
|
||||
this.corePoolSize = corePoolSize;
|
||||
}
|
||||
|
||||
public Integer getMaximumPoolSize() {
|
||||
return this.maximumPoolSize;
|
||||
}
|
||||
|
||||
public void setMaximumPoolSize(Integer maximumPoolSize) {
|
||||
this.maximumPoolSize = maximumPoolSize;
|
||||
}
|
||||
}
|
||||
|
||||
public String getBootstrapServers() {
|
||||
return this.bootstrapServers;
|
||||
}
|
||||
|
||||
public void setBootstrapServers(String bootstrapServers) {
|
||||
this.bootstrapServers = bootstrapServers;
|
||||
}
|
||||
|
||||
public String getGroupId() {
|
||||
return this.groupId;
|
||||
}
|
||||
|
||||
public void setGroupId(String groupId) {
|
||||
this.groupId = groupId;
|
||||
}
|
||||
|
||||
public Map<String, String> getListenerClass() {
|
||||
return this.listenerClass;
|
||||
}
|
||||
|
||||
public void setListenerClass(Map<String, String> listenerClass) {
|
||||
this.listenerClass = listenerClass;
|
||||
}
|
||||
|
||||
public Integer getFetchDataWorkerNumber() {
|
||||
return this.fetchDataWorkerNumber;
|
||||
}
|
||||
|
||||
public void setFetchDataWorkerNumber(Integer fetchDataWorkerNumber) {
|
||||
this.fetchDataWorkerNumber = fetchDataWorkerNumber;
|
||||
}
|
||||
|
||||
public HandlerExecutorConfig getHandlerExecutorConfig() {
|
||||
return this.handlerExecutorConfig;
|
||||
}
|
||||
|
||||
public void setHandlerExecutorConfig(HandlerExecutorConfig handlerExecutorConfig) {
|
||||
this.handlerExecutorConfig = handlerExecutorConfig;
|
||||
}
|
||||
|
||||
public String getWorkerNamePrefix() {
|
||||
return this.workerNamePrefix;
|
||||
}
|
||||
|
||||
public void setWorkerNamePrefix(String workerNamePrefix) {
|
||||
this.workerNamePrefix = workerNamePrefix;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
+59
-63
@@ -1,63 +1,59 @@
|
||||
/* */ package cn.cloudwalk.event.client;
|
||||
/* */
|
||||
/* */ import cn.cloudwalk.cwos.client.event.event.EventType;
|
||||
/* */ import cn.cloudwalk.event.handler.EventHandler;
|
||||
/* */ import java.util.List;
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */ public class EventSubscribeHandlers
|
||||
/* */ {
|
||||
/* */ private EventType eventType;
|
||||
/* */ private String serviceCode;
|
||||
/* */ private List<EventHandler> eventHandlerList;
|
||||
/* */
|
||||
/* */ public EventType getEventType() {
|
||||
/* 35 */ return this.eventType;
|
||||
/* */ }
|
||||
/* */
|
||||
/* */ public void setEventType(EventType eventType) {
|
||||
/* 39 */ this.eventType = eventType;
|
||||
/* */ }
|
||||
/* */
|
||||
/* */ public String getServiceCode() {
|
||||
/* 43 */ return this.serviceCode;
|
||||
/* */ }
|
||||
/* */
|
||||
/* */ public void setServiceCode(String serviceCode) {
|
||||
/* 47 */ this.serviceCode = serviceCode;
|
||||
/* */ }
|
||||
/* */
|
||||
/* */ public List<EventHandler> getEventHandlerList() {
|
||||
/* 51 */ return this.eventHandlerList;
|
||||
/* */ }
|
||||
/* */
|
||||
/* */ public void setEventHandlerList(List<EventHandler> eventHandlerList) {
|
||||
/* 55 */ this.eventHandlerList = eventHandlerList;
|
||||
/* */ }
|
||||
/* */ }
|
||||
|
||||
|
||||
/* Location: D:\星中心\cw-elevator-application-V1.0.0.20211103\cw-elevator-application-V1.0.0.20211103\lib\cloudwalk-common-event-3.7.2-Brussels-SRX.jar!\cn\cloudwalk\event\client\EventSubscribeHandlers.class
|
||||
* Java compiler version: 7 (51.0)
|
||||
* JD-Core Version: 1.1.3
|
||||
*/
|
||||
package cn.cloudwalk.event.client;
|
||||
|
||||
import cn.cloudwalk.cwos.client.event.event.EventType;
|
||||
import cn.cloudwalk.event.handler.EventHandler;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public class EventSubscribeHandlers
|
||||
{
|
||||
private EventType eventType;
|
||||
private String serviceCode;
|
||||
private List<EventHandler> eventHandlerList;
|
||||
|
||||
public EventType getEventType() {
|
||||
return this.eventType;
|
||||
}
|
||||
|
||||
public void setEventType(EventType eventType) {
|
||||
this.eventType = eventType;
|
||||
}
|
||||
|
||||
public String getServiceCode() {
|
||||
return this.serviceCode;
|
||||
}
|
||||
|
||||
public void setServiceCode(String serviceCode) {
|
||||
this.serviceCode = serviceCode;
|
||||
}
|
||||
|
||||
public List<EventHandler> getEventHandlerList() {
|
||||
return this.eventHandlerList;
|
||||
}
|
||||
|
||||
public void setEventHandlerList(List<EventHandler> eventHandlerList) {
|
||||
this.eventHandlerList = eventHandlerList;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
+5
-9
@@ -1,9 +1,5 @@
|
||||
package cn.cloudwalk.event.handler;
|
||||
|
||||
public interface CustomEventHandler<E extends cn.cloudwalk.cwos.client.event.event.CustomEvent> extends EventHandler<E> {}
|
||||
|
||||
|
||||
/* Location: D:\星中心\cw-elevator-application-V1.0.0.20211103\cw-elevator-application-V1.0.0.20211103\lib\cloudwalk-common-event-3.7.2-Brussels-SRX.jar!\cn\cloudwalk\event\handler\CustomEventHandler.class
|
||||
* Java compiler version: 7 (51.0)
|
||||
* JD-Core Version: 1.1.3
|
||||
*/
|
||||
package cn.cloudwalk.event.handler;
|
||||
|
||||
public interface CustomEventHandler<E extends cn.cloudwalk.cwos.client.event.event.CustomEvent> extends EventHandler<E> {}
|
||||
|
||||
|
||||
|
||||
+7
-11
@@ -1,11 +1,7 @@
|
||||
package cn.cloudwalk.event.handler;
|
||||
|
||||
public interface EventHandler<E extends cn.cloudwalk.cwos.client.event.event.BaseEvent> {
|
||||
void onEvent(E paramE);
|
||||
}
|
||||
|
||||
|
||||
/* Location: D:\星中心\cw-elevator-application-V1.0.0.20211103\cw-elevator-application-V1.0.0.20211103\lib\cloudwalk-common-event-3.7.2-Brussels-SRX.jar!\cn\cloudwalk\event\handler\EventHandler.class
|
||||
* Java compiler version: 7 (51.0)
|
||||
* JD-Core Version: 1.1.3
|
||||
*/
|
||||
package cn.cloudwalk.event.handler;
|
||||
|
||||
public interface EventHandler<E extends cn.cloudwalk.cwos.client.event.event.BaseEvent> {
|
||||
void onEvent(E paramE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
+122
-126
@@ -1,126 +1,122 @@
|
||||
/* */ package cn.cloudwalk.event.handler;
|
||||
/* */
|
||||
/* */ import cn.cloudwalk.cwos.client.event.event.BaseEvent;
|
||||
/* */ import cn.cloudwalk.cwos.client.event.event.EventType;
|
||||
/* */ import cn.cloudwalk.cwos.client.event.handler.EventListener;
|
||||
/* */ import java.util.HashMap;
|
||||
/* */ import java.util.List;
|
||||
/* */ import java.util.Map;
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */ public class EventHandlerMapping
|
||||
/* */ {
|
||||
/* 26 */ private final Map<String, Map<EventType, Map<String, List<EventHandler>>>> handlerMap = new HashMap<>();
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* 32 */ private final Map<String, Map<String, Map<String, List<CustomEventHandler>>>> customHandlerMap = new HashMap<>();
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* 38 */ private final Map<Class<? extends EventListener>, String> listenerClassGroupMap = new HashMap<>();
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */ public void registerHandlers(String groupId, EventType eventType, Map<String, List<EventHandler>> handlers) {
|
||||
/* 48 */ Map<EventType, Map<String, List<EventHandler>>> map = this.handlerMap.get(groupId);
|
||||
/* 49 */ if (null == map) {
|
||||
/* 50 */ map = new HashMap<>();
|
||||
/* 51 */ map.put(eventType, handlers);
|
||||
/* 52 */ this.handlerMap.put(groupId, map);
|
||||
/* */ } else {
|
||||
/* 54 */ map.put(eventType, handlers);
|
||||
/* */ }
|
||||
/* */ }
|
||||
/* */
|
||||
/* */
|
||||
/* */ public Map<String, List<EventHandler>> getServiceCodeHandlerListMap(String groupId, Class<? extends BaseEvent> eventClass) {
|
||||
/* 60 */ for (EventType eventType : EventType.values()) {
|
||||
/* 61 */ if (eventType.getEventClass().getClass().equals(eventClass)) {
|
||||
/* 62 */ return getServiceCodeHandlerListMap(groupId, eventType);
|
||||
/* */ }
|
||||
/* */ }
|
||||
/* 65 */ throw new IllegalArgumentException("没有找到合适的事件类型");
|
||||
/* */ }
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */ public Map<String, List<EventHandler>> getServiceCodeHandlerListMap(String groupId, EventType eventType) {
|
||||
/* 76 */ Map<EventType, Map<String, List<EventHandler>>> map = this.handlerMap.get(groupId);
|
||||
/* 77 */ if (null != map) {
|
||||
/* 78 */ return map.get(eventType);
|
||||
/* */ }
|
||||
/* 80 */ return null;
|
||||
/* */ }
|
||||
/* */
|
||||
/* */ public Map<String, List<CustomEventHandler>> getServiceCodeCustomHandlerListMap(String groupId, String topic) {
|
||||
/* 84 */ Map<String, Map<String, List<CustomEventHandler>>> map = this.customHandlerMap.get(groupId);
|
||||
/* 85 */ if (null != map) {
|
||||
/* 86 */ return map.get(topic);
|
||||
/* */ }
|
||||
/* 88 */ return null;
|
||||
/* */ }
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */ public void registerCustomHandlers(String groupId, String topic, Map<String, List<CustomEventHandler>> handlers) {
|
||||
/* 99 */ Map<String, Map<String, List<CustomEventHandler>>> map = this.customHandlerMap.get(groupId);
|
||||
/* 100 */ if (null == map) {
|
||||
/* 101 */ map = new HashMap<>();
|
||||
/* 102 */ map.put(topic, handlers);
|
||||
/* 103 */ this.customHandlerMap.put(groupId, map);
|
||||
/* */ } else {
|
||||
/* 105 */ map.put(topic, handlers);
|
||||
/* */ }
|
||||
/* */ }
|
||||
/* */
|
||||
/* */ public Map<String, Map<EventType, Map<String, List<EventHandler>>>> getHandlerMap() {
|
||||
/* 110 */ return this.handlerMap;
|
||||
/* */ }
|
||||
/* */
|
||||
/* */ public Map<String, Map<String, Map<String, List<CustomEventHandler>>>> getCustomHandlerMap() {
|
||||
/* 114 */ return this.customHandlerMap;
|
||||
/* */ }
|
||||
/* */
|
||||
/* */ public Map<Class<? extends EventListener>, String> getListenerClassGroupMap() {
|
||||
/* 118 */ return this.listenerClassGroupMap;
|
||||
/* */ }
|
||||
/* */ }
|
||||
|
||||
|
||||
/* Location: D:\星中心\cw-elevator-application-V1.0.0.20211103\cw-elevator-application-V1.0.0.20211103\lib\cloudwalk-common-event-3.7.2-Brussels-SRX.jar!\cn\cloudwalk\event\handler\EventHandlerMapping.class
|
||||
* Java compiler version: 7 (51.0)
|
||||
* JD-Core Version: 1.1.3
|
||||
*/
|
||||
package cn.cloudwalk.event.handler;
|
||||
|
||||
import cn.cloudwalk.cwos.client.event.event.BaseEvent;
|
||||
import cn.cloudwalk.cwos.client.event.event.EventType;
|
||||
import cn.cloudwalk.cwos.client.event.handler.EventListener;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public class EventHandlerMapping
|
||||
{
|
||||
private final Map<String, Map<EventType, Map<String, List<EventHandler>>>> handlerMap = new HashMap<>();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private final Map<String, Map<String, Map<String, List<CustomEventHandler>>>> customHandlerMap = new HashMap<>();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private final Map<Class<? extends EventListener>, String> listenerClassGroupMap = new HashMap<>();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public void registerHandlers(String groupId, EventType eventType, Map<String, List<EventHandler>> handlers) {
|
||||
Map<EventType, Map<String, List<EventHandler>>> map = this.handlerMap.get(groupId);
|
||||
if (null == map) {
|
||||
map = new HashMap<>();
|
||||
map.put(eventType, handlers);
|
||||
this.handlerMap.put(groupId, map);
|
||||
} else {
|
||||
map.put(eventType, handlers);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Map<String, List<EventHandler>> getServiceCodeHandlerListMap(String groupId, Class<? extends BaseEvent> eventClass) {
|
||||
for (EventType eventType : EventType.values()) {
|
||||
if (eventType.getEventClass().getClass().equals(eventClass)) {
|
||||
return getServiceCodeHandlerListMap(groupId, eventType);
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("没有找到合适的事件类型");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public Map<String, List<EventHandler>> getServiceCodeHandlerListMap(String groupId, EventType eventType) {
|
||||
Map<EventType, Map<String, List<EventHandler>>> map = this.handlerMap.get(groupId);
|
||||
if (null != map) {
|
||||
return map.get(eventType);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Map<String, List<CustomEventHandler>> getServiceCodeCustomHandlerListMap(String groupId, String topic) {
|
||||
Map<String, Map<String, List<CustomEventHandler>>> map = this.customHandlerMap.get(groupId);
|
||||
if (null != map) {
|
||||
return map.get(topic);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public void registerCustomHandlers(String groupId, String topic, Map<String, List<CustomEventHandler>> handlers) {
|
||||
Map<String, Map<String, List<CustomEventHandler>>> map = this.customHandlerMap.get(groupId);
|
||||
if (null == map) {
|
||||
map = new HashMap<>();
|
||||
map.put(topic, handlers);
|
||||
this.customHandlerMap.put(groupId, map);
|
||||
} else {
|
||||
map.put(topic, handlers);
|
||||
}
|
||||
}
|
||||
|
||||
public Map<String, Map<EventType, Map<String, List<EventHandler>>>> getHandlerMap() {
|
||||
return this.handlerMap;
|
||||
}
|
||||
|
||||
public Map<String, Map<String, Map<String, List<CustomEventHandler>>>> getCustomHandlerMap() {
|
||||
return this.customHandlerMap;
|
||||
}
|
||||
|
||||
public Map<Class<? extends EventListener>, String> getListenerClassGroupMap() {
|
||||
return this.listenerClassGroupMap;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
+37
-41
@@ -1,41 +1,37 @@
|
||||
/* */ package cn.cloudwalk.event.handler;
|
||||
/* */
|
||||
/* */ import cn.cloudwalk.event.task.EventHandleTask;
|
||||
/* */ import java.util.concurrent.Callable;
|
||||
/* */ import java.util.concurrent.Future;
|
||||
/* */ import java.util.concurrent.ThreadPoolExecutor;
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */ public class EventHandlerWorker
|
||||
/* */ {
|
||||
/* */ private ThreadPoolExecutor poolExecutor;
|
||||
/* */
|
||||
/* */ public void setPoolExecutor(ThreadPoolExecutor poolExecutor) {
|
||||
/* 24 */ this.poolExecutor = poolExecutor;
|
||||
/* */ }
|
||||
/* */
|
||||
/* */ public Future<String> work(final EventHandleTask task) {
|
||||
/* 28 */ return this.poolExecutor.submit(new Callable<String>()
|
||||
/* */ {
|
||||
/* */ public String call() throws Exception {
|
||||
/* 31 */ return task.start();
|
||||
/* */ }
|
||||
/* */ });
|
||||
/* */ }
|
||||
/* */ }
|
||||
|
||||
|
||||
/* Location: D:\星中心\cw-elevator-application-V1.0.0.20211103\cw-elevator-application-V1.0.0.20211103\lib\cloudwalk-common-event-3.7.2-Brussels-SRX.jar!\cn\cloudwalk\event\handler\EventHandlerWorker.class
|
||||
* Java compiler version: 7 (51.0)
|
||||
* JD-Core Version: 1.1.3
|
||||
*/
|
||||
package cn.cloudwalk.event.handler;
|
||||
|
||||
import cn.cloudwalk.event.task.EventHandleTask;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public class EventHandlerWorker
|
||||
{
|
||||
private ThreadPoolExecutor poolExecutor;
|
||||
|
||||
public void setPoolExecutor(ThreadPoolExecutor poolExecutor) {
|
||||
this.poolExecutor = poolExecutor;
|
||||
}
|
||||
|
||||
public Future<String> work(final EventHandleTask task) {
|
||||
return this.poolExecutor.submit(new Callable<String>()
|
||||
{
|
||||
public String call() throws Exception {
|
||||
return task.start();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
+58
-62
@@ -1,62 +1,58 @@
|
||||
/* */ package cn.cloudwalk.event.handler;
|
||||
/* */
|
||||
/* */ import java.util.concurrent.ThreadFactory;
|
||||
/* */ import java.util.concurrent.atomic.AtomicInteger;
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */ public class NamedThreadFactory
|
||||
/* */ implements ThreadFactory
|
||||
/* */ {
|
||||
/* */ private static final String DEFAULT_POOL_NAME = "cloudwalk-common-event";
|
||||
/* 19 */ protected static final AtomicInteger POOL_SEQ = new AtomicInteger(1);
|
||||
/* */
|
||||
/* 21 */ private final AtomicInteger threadNumber = new AtomicInteger(1);
|
||||
/* */
|
||||
/* */
|
||||
/* */ private final String namePrefix;
|
||||
/* */
|
||||
/* */
|
||||
/* */ private final ThreadGroup threadGroup;
|
||||
/* */
|
||||
/* */
|
||||
/* */ public NamedThreadFactory() {
|
||||
/* 31 */ this("cloudwalk-common-event");
|
||||
/* */ }
|
||||
/* */
|
||||
/* */ public NamedThreadFactory(String namePrefix) {
|
||||
/* 35 */ SecurityManager s = System.getSecurityManager();
|
||||
/* 36 */ this.threadGroup = (s != null) ? s.getThreadGroup() : Thread.currentThread().getThreadGroup();
|
||||
/* 37 */ if (null == namePrefix || "".equals(namePrefix.trim())) {
|
||||
/* 38 */ namePrefix = "cloudwalk-common-event";
|
||||
/* */ }
|
||||
/* 40 */ this.namePrefix = namePrefix + "-" + POOL_SEQ.getAndIncrement() + "-thread-";
|
||||
/* */ }
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */ public Thread newThread(Runnable r) {
|
||||
/* 46 */ Thread t = new Thread(this.threadGroup, r, this.namePrefix + this.threadNumber.getAndIncrement(), 0L);
|
||||
/* */
|
||||
/* 48 */ if (t.isDaemon()) {
|
||||
/* 49 */ t.setDaemon(false);
|
||||
/* */ }
|
||||
/* 51 */ if (t.getPriority() != 5) {
|
||||
/* 52 */ t.setPriority(5);
|
||||
/* */ }
|
||||
/* 54 */ return t;
|
||||
/* */ }
|
||||
/* */ }
|
||||
|
||||
|
||||
/* Location: D:\星中心\cw-elevator-application-V1.0.0.20211103\cw-elevator-application-V1.0.0.20211103\lib\cloudwalk-common-event-3.7.2-Brussels-SRX.jar!\cn\cloudwalk\event\handler\NamedThreadFactory.class
|
||||
* Java compiler version: 7 (51.0)
|
||||
* JD-Core Version: 1.1.3
|
||||
*/
|
||||
package cn.cloudwalk.event.handler;
|
||||
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public class NamedThreadFactory
|
||||
implements ThreadFactory
|
||||
{
|
||||
private static final String DEFAULT_POOL_NAME = "cloudwalk-common-event";
|
||||
protected static final AtomicInteger POOL_SEQ = new AtomicInteger(1);
|
||||
|
||||
private final AtomicInteger threadNumber = new AtomicInteger(1);
|
||||
|
||||
|
||||
private final String namePrefix;
|
||||
|
||||
|
||||
private final ThreadGroup threadGroup;
|
||||
|
||||
|
||||
public NamedThreadFactory() {
|
||||
this("cloudwalk-common-event");
|
||||
}
|
||||
|
||||
public NamedThreadFactory(String namePrefix) {
|
||||
SecurityManager s = System.getSecurityManager();
|
||||
this.threadGroup = (s != null) ? s.getThreadGroup() : Thread.currentThread().getThreadGroup();
|
||||
if (null == namePrefix || "".equals(namePrefix.trim())) {
|
||||
namePrefix = "cloudwalk-common-event";
|
||||
}
|
||||
this.namePrefix = namePrefix + "-" + POOL_SEQ.getAndIncrement() + "-thread-";
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Thread newThread(Runnable r) {
|
||||
Thread t = new Thread(this.threadGroup, r, this.namePrefix + this.threadNumber.getAndIncrement(), 0L);
|
||||
|
||||
if (t.isDaemon()) {
|
||||
t.setDaemon(false);
|
||||
}
|
||||
if (t.getPriority() != 5) {
|
||||
t.setPriority(5);
|
||||
}
|
||||
return t;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
+5
-9
@@ -1,9 +1,5 @@
|
||||
package cn.cloudwalk.event.listener;
|
||||
|
||||
public class CloudwalkEventListener extends GroupEventListener {}
|
||||
|
||||
|
||||
/* Location: D:\星中心\cw-elevator-application-V1.0.0.20211103\cw-elevator-application-V1.0.0.20211103\lib\cloudwalk-common-event-3.7.2-Brussels-SRX.jar!\cn\cloudwalk\event\listener\CloudwalkEventListener.class
|
||||
* Java compiler version: 7 (51.0)
|
||||
* JD-Core Version: 1.1.3
|
||||
*/
|
||||
package cn.cloudwalk.event.listener;
|
||||
|
||||
public class CloudwalkEventListener extends GroupEventListener {}
|
||||
|
||||
|
||||
|
||||
+37
-41
@@ -1,41 +1,37 @@
|
||||
/* */ package cn.cloudwalk.event.listener;
|
||||
/* */
|
||||
/* */ import cn.cloudwalk.cwos.client.event.event.BaseEvent;
|
||||
/* */ import cn.cloudwalk.cwos.client.event.handler.EventListener;
|
||||
/* */ import cn.cloudwalk.event.CloudwalkEventManager;
|
||||
/* */ import org.slf4j.Logger;
|
||||
/* */ import org.slf4j.LoggerFactory;
|
||||
/* */ import org.springframework.context.ApplicationContext;
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */ public abstract class GroupEventListener
|
||||
/* */ implements EventListener
|
||||
/* */ {
|
||||
/* */ public static ApplicationContext applicationContext;
|
||||
/* 23 */ private static final Logger LOGGER = LoggerFactory.getLogger(CloudwalkEventListener.class);
|
||||
/* */
|
||||
/* */
|
||||
/* */ public void messageListener(BaseEvent baseEvent) throws RuntimeException {
|
||||
/* */ try {
|
||||
/* 28 */ CloudwalkEventManager cloudwalkEventManager = (CloudwalkEventManager)applicationContext.getBean(CloudwalkEventManager.class);
|
||||
/* 29 */ cloudwalkEventManager.handle(getClass(), baseEvent);
|
||||
/* 30 */ } catch (Exception e) {
|
||||
/* 31 */ LOGGER.error("事件处理出现异常,原因:", e);
|
||||
/* 32 */ throw new RuntimeException(e);
|
||||
/* */ }
|
||||
/* */ }
|
||||
/* */ }
|
||||
|
||||
|
||||
/* Location: D:\星中心\cw-elevator-application-V1.0.0.20211103\cw-elevator-application-V1.0.0.20211103\lib\cloudwalk-common-event-3.7.2-Brussels-SRX.jar!\cn\cloudwalk\event\listener\GroupEventListener.class
|
||||
* Java compiler version: 7 (51.0)
|
||||
* JD-Core Version: 1.1.3
|
||||
*/
|
||||
package cn.cloudwalk.event.listener;
|
||||
|
||||
import cn.cloudwalk.cwos.client.event.event.BaseEvent;
|
||||
import cn.cloudwalk.cwos.client.event.handler.EventListener;
|
||||
import cn.cloudwalk.event.CloudwalkEventManager;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public abstract class GroupEventListener
|
||||
implements EventListener
|
||||
{
|
||||
public static ApplicationContext applicationContext;
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(CloudwalkEventListener.class);
|
||||
|
||||
|
||||
public void messageListener(BaseEvent baseEvent) throws RuntimeException {
|
||||
try {
|
||||
CloudwalkEventManager cloudwalkEventManager = (CloudwalkEventManager)applicationContext.getBean(CloudwalkEventManager.class);
|
||||
cloudwalkEventManager.handle(getClass(), baseEvent);
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("事件处理出现异常,原因:", e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
+38
-42
@@ -1,42 +1,38 @@
|
||||
/* */ package cn.cloudwalk.event.listener;
|
||||
/* */
|
||||
/* */ import cn.cloudwalk.cwos.client.event.handler.EventListener;
|
||||
/* */ import java.util.HashMap;
|
||||
/* */ import java.util.Map;
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */ public class GroupListnerClassMapping
|
||||
/* */ {
|
||||
/* 23 */ private final Map<Class<? extends EventListener>, String> mapping = new HashMap<>();
|
||||
/* */
|
||||
/* */ public void register(Class<? extends EventListener> eventListnerClass, String groupId) {
|
||||
/* 26 */ if (this.mapping.containsKey(eventListnerClass)) {
|
||||
/* 27 */ throw new IllegalArgumentException(String.format("eventListnerClass[%s]已经存在,不允许重复", new Object[] { eventListnerClass
|
||||
/* 28 */ .toString() }));
|
||||
/* */ }
|
||||
/* 30 */ this.mapping.put(eventListnerClass, groupId);
|
||||
/* */ }
|
||||
/* */
|
||||
/* */ public String getGroupId(Class<? extends EventListener> eventListnerClass) {
|
||||
/* 34 */ return this.mapping.get(eventListnerClass);
|
||||
/* */ }
|
||||
/* */ }
|
||||
|
||||
|
||||
/* Location: D:\星中心\cw-elevator-application-V1.0.0.20211103\cw-elevator-application-V1.0.0.20211103\lib\cloudwalk-common-event-3.7.2-Brussels-SRX.jar!\cn\cloudwalk\event\listener\GroupListnerClassMapping.class
|
||||
* Java compiler version: 7 (51.0)
|
||||
* JD-Core Version: 1.1.3
|
||||
*/
|
||||
package cn.cloudwalk.event.listener;
|
||||
|
||||
import cn.cloudwalk.cwos.client.event.handler.EventListener;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public class GroupListnerClassMapping
|
||||
{
|
||||
private final Map<Class<? extends EventListener>, String> mapping = new HashMap<>();
|
||||
|
||||
public void register(Class<? extends EventListener> eventListnerClass, String groupId) {
|
||||
if (this.mapping.containsKey(eventListnerClass)) {
|
||||
throw new IllegalArgumentException(String.format("eventListnerClass[%s]已经存在,不允许重复", new Object[] { eventListnerClass
|
||||
.toString() }));
|
||||
}
|
||||
this.mapping.put(eventListnerClass, groupId);
|
||||
}
|
||||
|
||||
public String getGroupId(Class<? extends EventListener> eventListnerClass) {
|
||||
return this.mapping.get(eventListnerClass);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
+54
-58
@@ -1,58 +1,54 @@
|
||||
/* */ package cn.cloudwalk.event.task;
|
||||
/* */
|
||||
/* */ import cn.cloudwalk.cwos.client.event.event.BaseEvent;
|
||||
/* */ import cn.cloudwalk.event.handler.EventHandler;
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */ public class EventHandleTask<E extends BaseEvent>
|
||||
/* */ {
|
||||
/* */ private E event;
|
||||
/* */ private EventHandler<E> handler;
|
||||
/* */
|
||||
/* */ public EventHandleTask(E event, EventHandler<E> handler) {
|
||||
/* 28 */ this.event = event;
|
||||
/* 29 */ this.handler = handler;
|
||||
/* */ }
|
||||
/* */
|
||||
/* */ public String start() {
|
||||
/* 33 */ this.handler.onEvent((BaseEvent)this.event);
|
||||
/* 34 */ return this.event.getMessageId();
|
||||
/* */ }
|
||||
/* */
|
||||
/* */ public E getEvent() {
|
||||
/* 38 */ return this.event;
|
||||
/* */ }
|
||||
/* */
|
||||
/* */ public void setEvent(E event) {
|
||||
/* 42 */ this.event = event;
|
||||
/* */ }
|
||||
/* */
|
||||
/* */ public EventHandler<E> getHandler() {
|
||||
/* 46 */ return this.handler;
|
||||
/* */ }
|
||||
/* */
|
||||
/* */ public void setHandler(EventHandler<E> handler) {
|
||||
/* 50 */ this.handler = handler;
|
||||
/* */ }
|
||||
/* */ }
|
||||
|
||||
|
||||
/* Location: D:\星中心\cw-elevator-application-V1.0.0.20211103\cw-elevator-application-V1.0.0.20211103\lib\cloudwalk-common-event-3.7.2-Brussels-SRX.jar!\cn\cloudwalk\event\task\EventHandleTask.class
|
||||
* Java compiler version: 7 (51.0)
|
||||
* JD-Core Version: 1.1.3
|
||||
*/
|
||||
package cn.cloudwalk.event.task;
|
||||
|
||||
import cn.cloudwalk.cwos.client.event.event.BaseEvent;
|
||||
import cn.cloudwalk.event.handler.EventHandler;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public class EventHandleTask<E extends BaseEvent>
|
||||
{
|
||||
private E event;
|
||||
private EventHandler<E> handler;
|
||||
|
||||
public EventHandleTask(E event, EventHandler<E> handler) {
|
||||
this.event = event;
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
public String start() {
|
||||
this.handler.onEvent((BaseEvent)this.event);
|
||||
return this.event.getMessageId();
|
||||
}
|
||||
|
||||
public E getEvent() {
|
||||
return this.event;
|
||||
}
|
||||
|
||||
public void setEvent(E event) {
|
||||
this.event = event;
|
||||
}
|
||||
|
||||
public EventHandler<E> getHandler() {
|
||||
return this.handler;
|
||||
}
|
||||
|
||||
public void setHandler(EventHandler<E> handler) {
|
||||
this.handler = handler;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user