All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.quorum.tessera.discovery.DefaultNetworkStore Maven / Gradle / Ivy

Go to download

Tessera is a stateless Java system that is used to enable the encryption, decryption, and distribution of private transactions for Quorum.

There is a newer version: 24.4.2
Show newest version
package com.quorum.tessera.discovery;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Stream;

enum DefaultNetworkStore implements NetworkStore {

    INSTANCE;

    private final Set activeNodes = ConcurrentHashMap.newKeySet();

    private static final Logger LOGGER = LoggerFactory.getLogger(DefaultNetworkStore.class);

    @Override
    public NetworkStore store(ActiveNode activeNode) {

        activeNodes.removeIf(a -> a.getUri().equals(activeNode.getUri()));
        activeNodes.add(activeNode);

        LOGGER.debug("Stored node {}. Active node count {}",activeNode.getUri(),activeNodes.size());
        return this;
    }

    @Override
    public NetworkStore remove(NodeUri nodeUri) {
        activeNodes.removeIf(a -> a.getUri().equals(nodeUri));
        LOGGER.debug("Removed node {}. Active node count {}",nodeUri,activeNodes.size());
        return this;
    }

    @Override
    public Stream getActiveNodes() {
        LOGGER.debug("Fetching active nodes {}",activeNodes);
        return activeNodes.stream();
    }



}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy