mirror of
https://github.com/hpd840321/starRiverProperty.git
synced 2026-06-09 16:30:29 +08:00
dee355b4a7
- artifacts/decompiled 树与相关源码变更 - maven-cw-elevator-application 业务 docs 与 package-info - scripts 下 formatter 校验与辅助脚本 - 其他子工程/接口与发布线一并纳入版本控制 Made-with: Cursor Former-commit-id: e102e8cab64e575bcd23c9a66a598aa1892bb492
123 lines
2.6 KiB
Java
123 lines
2.6 KiB
Java
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;
|
|
}
|
|
}
|
|
|
|
|