Search in sources :

Example 1 with NodePo

use of io.nuls.network.storage.po.NodePo in project nuls by nuls-io.

the class NetworkStorageServiceImpl method getAllNodes.

@Override
public List<Node> getAllNodes() {
    List<NodePo> poList = getDbService().values(NetworkStorageConstant.DB_NAME_NETWORK_NODE, NodePo.class);
    if (poList == null) {
        return new ArrayList<>();
    }
    List<Node> nodeList = new ArrayList<>();
    for (NodePo po : poList) {
        nodeList.add(NetworkTransferTool.toNode(po));
    }
    return nodeList;
}
Also used : NodePo(io.nuls.network.storage.po.NodePo) Node(io.nuls.network.model.Node)

Example 2 with NodePo

use of io.nuls.network.storage.po.NodePo in project nuls by nuls-io.

the class NetworkStorageServiceImpl method saveNode.

@Override
public void saveNode(Node node) {
    NodePo po = getDbService().getModel(NetworkStorageConstant.DB_NAME_NETWORK_NODE, bytes(node.getId()), NodePo.class);
    if (po != null) {
        NetworkTransferTool.toPojo(node, po);
    } else {
        po = NetworkTransferTool.toPojo(node);
    }
    getDbService().putModel(NetworkStorageConstant.DB_NAME_NETWORK_NODE, bytes(node.getId()), po);
}
Also used : NodePo(io.nuls.network.storage.po.NodePo)

Example 3 with NodePo

use of io.nuls.network.storage.po.NodePo in project nuls by nuls-io.

the class NetworkStorageServiceImpl method getNodeList.

@Override
public List<Node> getNodeList(int size, Set<String> ipSet) {
    List<Node> nodeList = new ArrayList<>();
    List<NodePo> poList = getDbService().values(NetworkStorageConstant.DB_NAME_NETWORK_NODE, NodePo.class);
    if (poList == null) {
        return nodeList;
    }
    int count = 0;
    for (int i = poList.size() - 1; i >= 0; i--) {
        NodePo po = poList.get(i);
        if (ipSet.contains(po.getIp())) {
            continue;
        }
        nodeList.add(NetworkTransferTool.toNode(po));
        count++;
        if (count >= size) {
            break;
        }
    }
    return nodeList;
}
Also used : NodePo(io.nuls.network.storage.po.NodePo) Node(io.nuls.network.model.Node)

Aggregations

NodePo (io.nuls.network.storage.po.NodePo)3 Node (io.nuls.network.model.Node)2