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

org.openfeed.client.api.impl.ConnectionStats Maven / Gradle / Ivy

The newest version!
package org.openfeed.client.api.impl;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class ConnectionStats {
    private final MessageStats overallStats = new MessageStats();

    // channel => { exchangeCode => Stats }
    private final Map> channelToExchangeToMessageStats = new HashMap<>();

    public MessageStats getMessageStats() {
        return this.overallStats;
    }

    public MessageStats getExchangeMessageStats(int channel, String exchangeCode) {
        if (!channelToExchangeToMessageStats.containsKey(channel)) {
            channelToExchangeToMessageStats.put(channel,new HashMap<>());
        }
        return this.channelToExchangeToMessageStats.get(channel)
                .computeIfAbsent(exchangeCode, key -> new MessageStats(channel,exchangeCode));
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder("\nOverall: " + overallStats + "\n");

        for(Map channelStats : channelToExchangeToMessageStats.values()) {
            channelStats.values().forEach(stats ->  sb.append("\t " + stats + "\n"));
        }
        return sb.toString();
    }

    public void clear() {
        overallStats.clear();
        channelToExchangeToMessageStats.clear();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy