Extracted Server classes into ChainableServer in order offer foreign blockchain server information to the Core API. They were not extracted into the ServerConfigurationInfo class as stated in a recent commit.

This commit is contained in:
kennycud 2023-12-20 04:24:51 -08:00
parent 7e509f27fb
commit 46a9075faf
3 changed files with 136 additions and 0 deletions

View File

@ -0,0 +1,47 @@
package org.qortal.api.resource;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.qortal.crosschain.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
public class CrossChainUtils {
private static final Logger LOGGER = LogManager.getLogger(CrossChainUtils.class);
public static ServerConfigurationInfo buildServerConfigurationInfo(Bitcoiny blockchain) {
BitcoinyBlockchainProvider blockchainProvider = blockchain.getBlockchainProvider();
ChainableServer currentServer = blockchainProvider.getCurrentServer();
return new ServerConfigurationInfo(
buildInfos(blockchainProvider.getServers(), currentServer),
buildInfos(blockchainProvider.getRemainingServers(), currentServer),
buildInfos(blockchainProvider.getUselessServers(), currentServer)
);
}
public static ServerInfo buildInfo(ChainableServer server, boolean isCurrent) {
return new ServerInfo(
server.averageResponseTime(),
server.getHostName(),
server.getPort(),
server.getConnectionType().toString(),
isCurrent);
}
public static List<ServerInfo> buildInfos(Collection<ChainableServer> servers, ChainableServer currentServer) {
List<ServerInfo> infos = new ArrayList<>( servers.size() );
for( ChainableServer server : servers )
{
infos.add(buildInfo(server, server.equals(currentServer)));
}
return infos;
}
}

View File

@ -0,0 +1,15 @@
package org.qortal.crosschain;
public interface ChainableServer {
public void addResponseTime(long responseTime);
public long averageResponseTime();
public String getHostName();
public int getPort();
public ConnectionType getConnectionType();
public enum ConnectionType {TCP, SSL}
}

View File

@ -0,0 +1,74 @@
package org.qortal.crosschain;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import java.util.Objects;
@XmlAccessorType(XmlAccessType.FIELD)
public class ServerInfo {
private long averageResponseTime;
private String hostName;
private int port;
private String connectionType;
private boolean isCurrent;
public ServerInfo() {
}
public ServerInfo(long averageResponseTime, String hostName, int port, String connectionType, boolean isCurrent) {
this.averageResponseTime = averageResponseTime;
this.hostName = hostName;
this.port = port;
this.connectionType = connectionType;
this.isCurrent = isCurrent;
}
public long getAverageResponseTime() {
return averageResponseTime;
}
public String getHostName() {
return hostName;
}
public int getPort() {
return port;
}
public String getConnectionType() {
return connectionType;
}
public boolean isCurrent() {
return isCurrent;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ServerInfo that = (ServerInfo) o;
return averageResponseTime == that.averageResponseTime && port == that.port && isCurrent == that.isCurrent && Objects.equals(hostName, that.hostName) && Objects.equals(connectionType, that.connectionType);
}
@Override
public int hashCode() {
return Objects.hash(averageResponseTime, hostName, port, connectionType, isCurrent);
}
@Override
public String toString() {
return "ServerInfo{" +
"averageResponseTime=" + averageResponseTime +
", hostName='" + hostName + '\'' +
", port=" + port +
", connectionType='" + connectionType + '\'' +
", isCurrent=" + isCurrent +
'}';
}
}