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

Method sendForWait

ZezeJava/ZezeJava/src/main/java/Zeze/Raft/Agent.java:185–214  ·  view source on GitHub ↗
(RaftRpc<TArgument, TResult> rpc)

Source from the content-addressed store, hash-verified

183 }
184
185 public <TArgument extends Serializable, TResult extends Serializable>
186 TaskCompletionSourceX<RaftRpc<TArgument, TResult>> sendForWait(RaftRpc<TArgument, TResult> rpc) {
187 if (pendingLimit > 0 && pending.size() > pendingLimit) // UrgentPending不限制。
188 throw new IllegalStateException("too many pending");
189 // 由于interface不能把setter弄成保护的,实际上外面可以修改。
190 // 简单检查一下吧。
191 if (rpc.getUnique().getRequestId() != 0)
192 throw new IllegalStateException("RaftRpc.UniqueRequestId != 0. Need A Fresh RaftRpc");
193
194 rpc.getUnique().setRequestId(uniqueRequestIdGenerator.next());
195 // 外面在发送前可以设置clientId
196 if (rpc.getUnique().getClientId().isEmpty())
197 rpc.getUnique().setClientId(uniqueRequestIdGenerator.getName());
198 rpc.setCreateTime(System.currentTimeMillis());
199 rpc.setSendTime(rpc.getCreateTime());
200 if (rpc.getTimeout() == 0) // set default timeout
201 rpc.setTimeout(raftConfig.getAgentTimeout());
202
203 var future = new TaskCompletionSourceX<RaftRpc<TArgument, TResult>>();
204 rpc.future = future;
205 if (pending.putIfAbsent(rpc.getUnique().getRequestId(), rpc) != null)
206 throw new IllegalStateException("duplicate requestId rpc=" + rpc);
207
208 rpc.setResponseHandle(p -> sendForWaitHandle(p, rpc));
209 ConnectorProxy leader = this.leader;
210 if (!ProxyAgent.send(client, proxyAgent, rpc, leader,
211 leader != null ? leader.getConnector().TryGetReadySocket() : null))
212 logger.debug("sendForWait failed: leader={}, rpc={}", leader, rpc);
213 return future;
214 }
215
216 /**
217 * Connector 代理,

Callers 15

getCurrentCountMethod · 0.80
concurrentAddCountMethod · 0.80
runTraceMethod · 0.80
setBucketMetaMethod · 0.80
getMethod · 0.80
prepareBatchMethod · 0.80
commitBatchMethod · 0.80
undoBatchMethod · 0.80
walkMethod · 0.80
walkKeyMethod · 0.80
acquireMethod · 0.80
closeMethod · 0.80

Calls 15

sendForWaitHandleMethod · 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 3

getCurrentCountMethod · 0.64
concurrentAddCountMethod · 0.64
runTraceMethod · 0.64