WangHan
2024-09-12 d5855a4926926698b740bc6c7ba489de47adb68b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package tech.powerjob.common.request;
 
import lombok.Setter;
import lombok.experimental.Accessors;
import org.apache.commons.lang3.StringUtils;
import tech.powerjob.common.enums.Protocol;
 
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
 
/**
 * 服务发现请求
 *
 * @author tjq
 * @since 2023/1/21
 */
@Setter
@Accessors(chain = true)
public class ServerDiscoveryRequest implements Serializable {
 
    private Long appId;
 
    private String protocol;
 
    private String currentServer;
 
    private String clientVersion;
 
    public Map<String, Object> toMap() {
        Map<String, Object> ret = new HashMap<>();
        // testMode 下 appId 可能为空,此处不判断会导致 testMode 无法启动 #580
        if (appId != null) {
            ret.put("appId", appId);
        }
        ret.put("protocol", protocol);
        if (StringUtils.isNotEmpty(currentServer)) {
            ret.put("currentServer", currentServer);
        }
        if (StringUtils.isNotEmpty(clientVersion)) {
            ret.put("clientVersion", clientVersion);
        }
        return ret;
    }
 
    public Long getAppId() {
        return appId;
    }
 
    public String getProtocol() {
        return Optional.ofNullable(protocol).orElse(Protocol.AKKA.name());
    }
 
    public String getCurrentServer() {
        return currentServer;
    }
 
    public String getClientVersion() {
        return clientVersion;
    }
}