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

Method send

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

发送Rpc请求。

(RaftRpc<TArgument, TResult> rpc, ToLongFunction<Protocol<?>> handle)

Source from the content-addressed store, hash-verified

96 * 发送Rpc请求。
97 */
98 public <TArgument extends Serializable, TResult extends Serializable>
99 void send(RaftRpc<TArgument, TResult> rpc, ToLongFunction<Protocol<?>> handle) {
100 if (handle == null)
101 throw new IllegalArgumentException("null handle");
102 if (pendingLimit > 0 && pending.size() > pendingLimit) // UrgentPending不限制。
103 throw new IllegalStateException("too many pending");
104
105 // 由于interface不能把setter弄成保护的,实际上外面可以修改。
106 // 简单检查一下吧。
107 if (rpc.getUnique().getRequestId() != 0)
108 throw new IllegalStateException("RaftRpc.UniqueRequestId != 0. Need A Fresh RaftRpc");
109
110 rpc.getUnique().setRequestId(uniqueRequestIdGenerator.next());
111 // 外面可以设置clientId,默认使用Generator.getName();
112 if (rpc.getUnique().getClientId().isEmpty())
113 rpc.getUnique().setClientId(uniqueRequestIdGenerator.getName());
114 rpc.setCreateTime(System.currentTimeMillis());
115 rpc.setSendTime(rpc.getCreateTime());
116 if (rpc.getTimeout() == 0) // set default timeout
117 rpc.setTimeout(raftConfig.getAgentTimeout());
118
119 rpc.handle = handle;
120 if (pending.putIfAbsent(rpc.getUnique().getRequestId(), rpc) != null)
121 throw new IllegalStateException("duplicate requestId rpc=" + rpc);
122
123 rpc.setResponseHandle(p -> sendHandle(p, rpc));
124 ConnectorProxy leader = this.leader;
125 if (!ProxyAgent.send(client, proxyAgent, rpc, leader,
126 leader != null ? leader.getConnector().TryGetReadySocket() : null))
127 logger.debug("send failed: leader={}, rpc={}", leader, rpc);
128 }
129
130 private <TArgument extends Serializable, TResult extends Serializable>
131 long sendHandle(Rpc<TArgument, TResult> p, RaftRpc<TArgument, TResult> rpc) {

Callers 1

getLeaderAsyncMethod · 0.95

Calls 15

sendHandleMethod · 0.95
sendMethod · 0.95
getConnectorMethod · 0.95
getRequestIdMethod · 0.80
setRequestIdMethod · 0.80
getTimeoutMethod · 0.80
setTimeoutMethod · 0.80
getAgentTimeoutMethod · 0.80
setResponseHandleMethod · 0.80
sizeMethod · 0.65
getUniqueMethod · 0.65
nextMethod · 0.65

Tested by

no test coverage detected