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

Method init

ZezeJava/ZezeJava/src/main/java/Zeze/Raft/Agent.java:347–381  ·  view source on GitHub ↗
(NetClient client, RaftConfig raftConf)

Source from the content-addressed store, hash-verified

345 }
346
347 private void init(NetClient client, RaftConfig raftConf) throws Exception {
348 if (raftConf == null)
349 raftConf = RaftConfig.load();
350
351 raftConfig = raftConf;
352 this.client = client;
353
354 if (this.client.getConfig().acceptorCount() != 0)
355 throw new IllegalStateException("Acceptor Found!");
356 if (this.client.getConfig().connectorCount() != 0)
357 throw new IllegalStateException("Connector Found!");
358
359 if (proxyAgent == null) {
360 // 没有启用代理,按原始raft方式建立连接器。
361 for (var node : raftConfig.getNodes().values())
362 this.client.getConfig().addConnector(new Connector(node.getHost(), node.getPort()));
363 } else {
364 proxyAgent.addAgent(this);
365 leader = proxyAgent.getLeader(raftConfig.getNodes().values().iterator().next());
366 logger.info("proxy first leader {} {}_{}",
367 leader.getName(), leader.getConnector().getHostNameOrAddress(), leader.getConnector().getPort());
368 }
369
370 this.client.AddFactoryHandle(LeaderIs.TypeId_, new Service.ProtocolFactoryHandle<>(
371 LeaderIs::new, this::processLeaderIs, TransactionLevel.Serializable, DispatchMode.Critical));
372
373 this.client.AddFactoryHandle(GetLeader.TypeId_, new Service.ProtocolFactoryHandle<>(
374 GetLeader::new, null, TransactionLevel.None, DispatchMode.Normal));
375 this.client.AddFactoryHandle(StartServerConnector.TypeId_, new Service.ProtocolFactoryHandle<>(
376 StartServerConnector::new, null, TransactionLevel.None, DispatchMode.Normal));
377 this.client.AddFactoryHandle(StopServerConnector.TypeId_, new Service.ProtocolFactoryHandle<>(
378 StopServerConnector::new, null, TransactionLevel.None, DispatchMode.Normal));
379 // ugly
380 resendTask = Task.scheduleUnsafe(1000, 1000, this::resend);
381 }
382
383 private Connector getRandomConnector(Connector except) {
384 var notMe = new ArrayList<Connector>(client.getConfig().connectorCount());

Callers 1

AgentMethod · 0.95

Calls 15

loadMethod · 0.95
scheduleUnsafeMethod · 0.95
acceptorCountMethod · 0.80
connectorCountMethod · 0.80
addConnectorMethod · 0.80
addAgentMethod · 0.80
getHostNameOrAddressMethod · 0.80
AddFactoryHandleMethod · 0.80
valuesMethod · 0.65
getHostMethod · 0.65
getPortMethod · 0.65
nextMethod · 0.65

Tested by

no test coverage detected