Search in sources :

Example 1 with PeerStatusCache

use of org.apache.nifi.remote.util.PeerStatusCache in project nifi by apache.

the class PeerSelector method refreshPeers.

public void refreshPeers() {
    final PeerStatusCache existingCache = peerStatusCache;
    if (existingCache != null && (existingCache.getTimestamp() + PEER_CACHE_MILLIS > systemTime.currentTimeMillis())) {
        return;
    }
    try {
        final Set<PeerStatus> statuses = fetchRemotePeerStatuses();
        persistPeerStatuses(statuses);
        peerStatusCache = new PeerStatusCache(statuses);
        logger.info("{} Successfully refreshed Peer Status; remote instance consists of {} peers", this, statuses.size());
    } catch (Exception e) {
        warn(logger, eventReporter, "{} Unable to refresh Remote Group's peers due to {}", this, e.getMessage());
        if (logger.isDebugEnabled()) {
            logger.debug("", e);
        }
    }
}
Also used : PeerStatus(org.apache.nifi.remote.PeerStatus) PeerStatusCache(org.apache.nifi.remote.util.PeerStatusCache) IOException(java.io.IOException)

Example 2 with PeerStatusCache

use of org.apache.nifi.remote.util.PeerStatusCache in project nifi by apache.

the class PeerSelector method getPeerStatuses.

private Set<PeerStatus> getPeerStatuses() {
    final PeerStatusCache cache = this.peerStatusCache;
    if (cache == null || cache.getStatuses() == null || cache.getStatuses().isEmpty()) {
        return null;
    }
    if (cache.getTimestamp() + PEER_CACHE_MILLIS < systemTime.currentTimeMillis()) {
        final Set<PeerStatus> equalizedSet = new HashSet<>(cache.getStatuses().size());
        for (final PeerStatus status : cache.getStatuses()) {
            final PeerStatus equalizedStatus = new PeerStatus(status.getPeerDescription(), 1, status.isQueryForPeers());
            equalizedSet.add(equalizedStatus);
        }
        return equalizedSet;
    }
    return cache.getStatuses();
}
Also used : PeerStatus(org.apache.nifi.remote.PeerStatus) PeerStatusCache(org.apache.nifi.remote.util.PeerStatusCache) HashSet(java.util.HashSet)

Aggregations

PeerStatus (org.apache.nifi.remote.PeerStatus)2 PeerStatusCache (org.apache.nifi.remote.util.PeerStatusCache)2 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1