MCPcopy Create free account
hub / github.com/e2wugui/zeze / Agent

Class Agent

ZezeJava/ZezeJava/src/main/java/Zeze/Raft/Agent.java:39–723  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

37import org.jetbrains.annotations.NotNull;
38
39public final class Agent {
40 private static final Logger logger = LogManager.getLogger(Agent.class);
41 private static final boolean isDebugEnabled = logger.isDebugEnabled();
42
43 // 保证在Raft-Server检查UniqueRequestId唯一性过期前唯一即可。
44 // 使用持久化是为了避免短时间重启,Id重复。
45 private final PersistentAtomicLong uniqueRequestIdGenerator;
46 private RaftConfig raftConfig;
47 private NetClient client;
48 private volatile ConnectorProxy leader;
49 private final ConcurrentHashMapOrdered<Long, RaftRpc<?, ?>> pending = new ConcurrentHashMapOrdered<>();
50 private long term;
51 public boolean dispatchProtocolToInternalThreadPool;
52 private volatile int pendingLimit = -1; // -1 no limit // 实际上没有进行线程保护。
53 private Future<?> resendTask;
54
55 private Action1<Agent> onSetLeader;
56 private final Lock mutex = new ReentrantLock();
57 private final ProxyAgent proxyAgent;
58
59 public RaftConfig getRaftConfig() {
60 return raftConfig;
61 }
62
63 public int getPendingLimit() {
64 return pendingLimit;
65 }
66
67 public void setPendingLimit(int value) {
68 pendingLimit = value;
69 }
70
71 public NetClient getClient() {
72 return client;
73 }
74
75 public String getName() {
76 return client.getName();
77 }
78
79 public ConnectorProxy getLeader() {
80 return leader;
81 }
82
83 public long getTerm() {
84 return term;
85 }
86
87 public Action1<Agent> getOnSetLeader() {
88 return onSetLeader;
89 }
90
91 public void setOnSetLeader(Action1<Agent> onSetLeader) {
92 this.onSetLeader = onSetLeader;
93 }
94
95 /**
96 * 发送Rpc请求。

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected