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

Method sendDirect

ZezeJava/ZezeJava/src/main/java/Zeze/Arch/Online.java:880–940  ·  view source on GitHub ↗
(@NotNull Set<BLoginKey> loginKeys, long typeId, @NotNull Binary fullEncodedProtocol,
						  boolean trySend)

Source from the content-addressed store, hash-verified

878
879 // 可在事务外执行
880 public int sendDirect(@NotNull Set<BLoginKey> loginKeys, long typeId, @NotNull Binary fullEncodedProtocol,
881 boolean trySend) {
882 if (loginKeys.isEmpty())
883 return 0;
884 var groups = new HashMap<String, LinkRoles>();
885 var links = providerApp.providerService.getLinks();
886 for (var loginKey : loginKeys) {
887 var account = loginKey.getAccount();
888 var clientId = loginKey.getClientId();
889 var online = _tonline.selectDirty(account);
890 if (online == null) {
891 if (!trySend) {
892 logger.info("sendDirects({}): not found account={} in _tonline",
893 getTypeId(fullEncodedProtocol), account);
894 }
895 continue;
896 }
897 var login = online.getLogins().get(clientId);
898 if (login == null) {
899 if (!trySend) {
900 logger.info("sendDirects({}): not found login for clientId={} account={}",
901 getTypeId(fullEncodedProtocol), clientId, account);
902 }
903 continue;
904 }
905 var link = login.getLink();
906 var state = link.getState();
907 if (state != eLogined) {
908 if (!trySend) {
909 logger.info("sendDirects({}): state={} != eLogined for clientId={} account={}",
910 getTypeId(fullEncodedProtocol), state, clientId, account);
911 }
912 continue;
913 }
914 var linkName = link.getLinkName();
915 // 后面保存connector.socket并使用,如果之后连接被关闭,以后发送协议失败。
916 var group = groups.get(linkName);
917 if (group == null) {
918 var linkSocket = getLinkSocket(links, linkName, account, clientId); // maybe null
919 groups.put(linkName, group = new LinkRoles(linkName, linkSocket, typeId, fullEncodedProtocol));
920 }
921 group.send.Argument.getLinkSids().add(link.getLinkSid());
922 group.accounts.add(loginKey);
923 }
924 int sendCount = 0;
925 for (var group : groups.values()) {
926 if (null == group.linkSocket) {
927 processErrorSids(group.send.Argument.getLinkSids(), group);
928 continue; // link miss process done
929 }
930
931 if (group.send.Send(group.linkSocket, rpc -> {
932 var send = group.send;
933 var errorSids = send.isTimeout() ? send.Argument.getLinkSids() : send.Result.getErrorLinkSids();
934 processErrorSids(errorSids, group);
935 return Procedure.Success;
936 }))
937 sendCount++;

Callers 2

sendReliableNotifyMethod · 0.95
sendMethod · 0.95

Calls 15

getTypeIdMethod · 0.95
getLinkSocketMethod · 0.95
processErrorSidsMethod · 0.95
runMethod · 0.95
sendErrorMethod · 0.95
SendMethod · 0.95
getLinksMethod · 0.80
isEmptyMethod · 0.65
getAccountMethod · 0.65
getClientIdMethod · 0.65
selectDirtyMethod · 0.65
getMethod · 0.65

Tested by

no test coverage detected