You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.5 KiB
59 lines
1.5 KiB
package com.mh.common.constant; |
|
|
|
import java.util.Arrays; |
|
import java.util.regex.Pattern; |
|
|
|
import static com.mh.common.constant.TopicConst.*; |
|
|
|
|
|
/** |
|
* @author ljf |
|
* @version 1.0 |
|
* @description: TODO |
|
* @date 2024/11/06 14:28 |
|
*/ |
|
public enum TopicEnum { |
|
|
|
/** |
|
* 客户端主动上报数据 |
|
*/ |
|
CLIENT_UPLOAD_DATA(Pattern.compile("^" + MH_UPLOAD + EVENTS_UPLOAD + REGEX_SN + "$"), ChannelName.EVENTS_UPLOAD_INBOUND), |
|
|
|
/** |
|
* 服务端采集数据 |
|
*/ |
|
SERVER_COLLECTION_DATA(Pattern.compile("^" + MH_COLLECTION + EVENTS_COLLECTION + REGEX_SN + "$"), ChannelName.EVENTS_COLLECTION_INBOUND), |
|
|
|
/** |
|
* 服务端控制指令 |
|
*/ |
|
SERVER_CONTROL_DATA(Pattern.compile("^" + MH_CONTROL + EVENTS_CONTROL + REGEX_SN + "$"), ChannelName.EVENTS_CONTROL_INBOUND), |
|
|
|
/** |
|
* 订阅服务端发送的主题命令 |
|
*/ |
|
SERVER_SEND_DATA(Pattern.compile("^A/cmd/ctl/send" + "$"), ChannelName.EVENTS_SEND_INBOUND), |
|
|
|
UNKNOWN(Pattern.compile("^.*$"), ChannelName.DEFAULT_BOUND); |
|
|
|
final Pattern pattern; |
|
|
|
final String beanName; |
|
|
|
TopicEnum(Pattern pattern, String beanName) { |
|
this.pattern = pattern; |
|
this.beanName = beanName; |
|
} |
|
|
|
public Pattern getPattern() { |
|
return pattern; |
|
} |
|
|
|
public String getBeanName() { |
|
return beanName; |
|
} |
|
|
|
public static TopicEnum find(String topic) { |
|
return Arrays.stream(TopicEnum.values()).filter(topicEnum -> topicEnum.pattern.matcher(topic).matches()).findAny().orElse(UNKNOWN); |
|
} |
|
}
|
|
|