package com.basic.security.manager.impl.erlang;
|
|
import android.text.TextUtils;
|
|
import com.basic.security.utils.Constants;
|
import com.basic.security.utils.ErlangLocalNodeName;
|
import com.ericsson.otp.erlang.OtpConnection;
|
import com.ericsson.otp.erlang.OtpPeer;
|
import com.ericsson.otp.erlang.OtpSelf;
|
|
import java.util.HashMap;
|
import java.util.Map;
|
|
public class ErlangConnection extends ErBaseManger {
|
|
static OtpConnection localConnection = null;
|
static Map<String, OtpConnection> remoteConnectionMap = new HashMap<>();
|
|
public static OtpConnection getLocalConnection() {
|
if (localConnection == null || !localConnection.isConnected()) {
|
try {
|
OtpSelf node = new OtpSelf(ErlangLocalNodeName.getNodeName());
|
node.setCookie("123");
|
OtpPeer otpPeer = new OtpPeer(Constants.erlangLocalNode);
|
localConnection = node.connect(otpPeer);
|
} catch (Exception e) {
|
// System.out.println("getLocalConnection " + e.getMessage());
|
}
|
}
|
return localConnection;
|
}
|
|
public static OtpConnection getRemoteConnection(String nodeName) {
|
OtpConnection remoteConnection = remoteConnectionMap.get(nodeName);
|
if (remoteConnection == null || !remoteConnection.isConnected()) {
|
try {
|
String remoteNodeName = NodeNameManager.getNodeNameByNodeName(nodeName);
|
if (!TextUtils.isEmpty(remoteNodeName)) {
|
OtpSelf node = new OtpSelf(ErlangLocalNodeName.getNodeName());
|
node.setCookie("123");
|
OtpPeer otpPeer = new OtpPeer(remoteNodeName);
|
remoteConnection = node.connect(otpPeer);
|
remoteConnectionMap.put(nodeName, remoteConnection);
|
} else {
|
// System.out.println(nodeName+" 不在线");
|
}
|
} catch (Exception e) {
|
System.out.println("ErlangConnection getRemoteConnection " + e.getMessage() + " " + nodeName);
|
}
|
}
|
return remoteConnection;
|
}
|
|
|
}
|