// Path: src/main/java/net/iponweb/disthene/service/blacklist/BlacklistService.java
// public class BlacklistService {
// 
//     private Map<String, Pattern> rules = new HashMap<>();
// 
//     public BlacklistService(BlackListConfiguration blackListConfiguration) {
//         for(Map.Entry<String, List<String>> entry : blackListConfiguration.getRules().entrySet()) {
//             rules.put(entry.getKey(), Pattern.compile(Joiner.on("|").skipNulls().join(entry.getValue())));
//         }
//     }
// 
//     public boolean isBlackListed(Metric metric) {
//         Pattern pattern = rules.get(metric.getTenant());
//         if (pattern != null) {
//             Matcher matcher = pattern.matcher(metric.getPath());
//             return matcher.matches();
//         } else {
//             return false;
//         }
//     }
// 
//     public void setRules(BlackListConfiguration blackListConfiguration) {
//         Map<String, Pattern> rules = new HashMap<>();
// 
//         for(Map.Entry<String, List<String>> entry : blackListConfiguration.getRules().entrySet()) {
//             rules.put(entry.getKey(), Pattern.compile(Joiner.on("|").skipNulls().join(entry.getValue())));
//         }
// 
//         this.rules = rules;
//     }
// }
// 
// Path: src/main/java/net/iponweb/disthene/config/DistheneConfiguration.java
// @SuppressWarnings("UnusedDeclaration")
// public final class DistheneConfiguration {
//     private CarbonConfiguration carbon;
//     private StoreConfiguration store;
//     private IndexConfiguration index;
//     private StatsConfiguration stats;
// 
// 
//     public CarbonConfiguration getCarbon() {
//         return carbon;
//     }
// 
//     public void setCarbon(CarbonConfiguration carbon) {
//         this.carbon = carbon;
//     }
// 
//     public StoreConfiguration getStore() {
//         return store;
//     }
// 
//     public void setStore(StoreConfiguration store) {
//         this.store = store;
//     }
// 
//     public IndexConfiguration getIndex() {
//         return index;
//     }
// 
//     public void setIndex(IndexConfiguration index) {
//         this.index = index;
//     }
// 
//     public StatsConfiguration getStats() {
//         return stats;
//     }
// 
//     public void setStats(StatsConfiguration stats) {
//         this.stats = stats;
//     }
// 
//     @Override
//     public String toString() {
//         return "DistheneConfiguration{" +
//                 "carbon=" + carbon +
//                 ", store=" + store +
//                 ", index=" + index +
//                 ", stats=" + stats +
//                 '}';
//     }
// }
// 
// Path: src/main/java/net/iponweb/disthene/events/DistheneEvent.java
// public interface DistheneEvent {
// }
// 
// Path: src/main/java/net/iponweb/disthene/events/MetricAggregateEvent.java
// public class MetricAggregateEvent extends AbstractMetricEvent {
// 
//     public MetricAggregateEvent(Metric metric) {
//         super(metric);
//     }
// }
// 
// Path: src/main/java/net/iponweb/disthene/events/MetricReceivedEvent.java
// public class MetricReceivedEvent extends AbstractMetricEvent {
// 
//     public MetricReceivedEvent(Metric metric) {
//         super(metric);
//     }
// }
// 
// Path: src/main/java/net/iponweb/disthene/events/MetricStoreEvent.java
// public class MetricStoreEvent extends AbstractMetricEvent {
//     public MetricStoreEvent(Metric metric) {
//         super(metric);
//     }
// }


import net.engio.mbassy.bus.MBassador;
import net.engio.mbassy.listener.Handler;
import net.engio.mbassy.listener.Listener;
import net.engio.mbassy.listener.References;
import net.iponweb.disthene.service.blacklist.BlacklistService;
import net.iponweb.disthene.config.DistheneConfiguration;
import net.iponweb.disthene.events.DistheneEvent;
import net.iponweb.disthene.events.MetricAggregateEvent;
import net.iponweb.disthene.events.MetricReceivedEvent;
import net.iponweb.disthene.events.MetricStoreEvent;
package net.iponweb.disthene.service.metric;


/**
 * @author Andrei Ivanov
 */
@Listener(references= References.Strong)
public class MetricService {

    private MBassador<DistheneEvent> bus;
    private BlacklistService blacklistService;
    private DistheneConfiguration distheneConfiguration;

    public MetricService(MBassador<DistheneEvent> bus, BlacklistService blacklistService, DistheneConfiguration distheneConfiguration) {
        this.bus = bus;
        this.blacklistService = blacklistService;
        this.distheneConfiguration = distheneConfiguration;
        bus.subscribe(this);
    }

    @Handler(rejectSubtypes = false)
    public void handle(MetricReceivedEvent metricReceivedEvent) {
        if (!blacklistService.isBlackListed(metricReceivedEvent.getMetric())) {
            if (distheneConfiguration.getCarbon().getAggregateBaseRollup()) {
// Path: src/main/java/net/iponweb/disthene/service/blacklist/BlacklistService.java
// public class BlacklistService {
// 
//     private Map<String, Pattern> rules = new HashMap<>();
// 
//     public BlacklistService(BlackListConfiguration blackListConfiguration) {
//         for(Map.Entry<String, List<String>> entry : blackListConfiguration.getRules().entrySet()) {
//             rules.put(entry.getKey(), Pattern.compile(Joiner.on("|").skipNulls().join(entry.getValue())));
//         }
//     }
// 
//     public boolean isBlackListed(Metric metric) {
//         Pattern pattern = rules.get(metric.getTenant());
//         if (pattern != null) {
//             Matcher matcher = pattern.matcher(metric.getPath());
//             return matcher.matches();
//         } else {
//             return false;
//         }
//     }
// 
//     public void setRules(BlackListConfiguration blackListConfiguration) {
//         Map<String, Pattern> rules = new HashMap<>();
// 
//         for(Map.Entry<String, List<String>> entry : blackListConfiguration.getRules().entrySet()) {
//             rules.put(entry.getKey(), Pattern.compile(Joiner.on("|").skipNulls().join(entry.getValue())));
//         }
// 
//         this.rules = rules;
//     }
// }
// 
// Path: src/main/java/net/iponweb/disthene/config/DistheneConfiguration.java
// @SuppressWarnings("UnusedDeclaration")
// public final class DistheneConfiguration {
//     private CarbonConfiguration carbon;
//     private StoreConfiguration store;
//     private IndexConfiguration index;
//     private StatsConfiguration stats;
// 
// 
//     public CarbonConfiguration getCarbon() {
//         return carbon;
//     }
// 
//     public void setCarbon(CarbonConfiguration carbon) {
//         this.carbon = carbon;
//     }
// 
//     public StoreConfiguration getStore() {
//         return store;
//     }
// 
//     public void setStore(StoreConfiguration store) {
//         this.store = store;
//     }
// 
//     public IndexConfiguration getIndex() {
//         return index;
//     }
// 
//     public void setIndex(IndexConfiguration index) {
//         this.index = index;
//     }
// 
//     public StatsConfiguration getStats() {
//         return stats;
//     }
// 
//     public void setStats(StatsConfiguration stats) {
//         this.stats = stats;
//     }
// 
//     @Override
//     public String toString() {
//         return "DistheneConfiguration{" +
//                 "carbon=" + carbon +
//                 ", store=" + store +
//                 ", index=" + index +
//                 ", stats=" + stats +
//                 '}';
//     }
// }
// 
// Path: src/main/java/net/iponweb/disthene/events/DistheneEvent.java
// public interface DistheneEvent {
// }
// 
// Path: src/main/java/net/iponweb/disthene/events/MetricAggregateEvent.java
// public class MetricAggregateEvent extends AbstractMetricEvent {
// 
//     public MetricAggregateEvent(Metric metric) {
//         super(metric);
//     }
// }
// 
// Path: src/main/java/net/iponweb/disthene/events/MetricReceivedEvent.java
// public class MetricReceivedEvent extends AbstractMetricEvent {
// 
//     public MetricReceivedEvent(Metric metric) {
//         super(metric);
//     }
// }
// 
// Path: src/main/java/net/iponweb/disthene/events/MetricStoreEvent.java
// public class MetricStoreEvent extends AbstractMetricEvent {
//     public MetricStoreEvent(Metric metric) {
//         super(metric);
//     }
// }


// Path: src/main/java/net/iponweb/disthene/service/metric/MetricService.java
import net.engio.mbassy.bus.MBassador;
import net.engio.mbassy.listener.Handler;
import net.engio.mbassy.listener.Listener;
import net.engio.mbassy.listener.References;
import net.iponweb.disthene.service.blacklist.BlacklistService;
import net.iponweb.disthene.config.DistheneConfiguration;
import net.iponweb.disthene.events.DistheneEvent;
import net.iponweb.disthene.events.MetricAggregateEvent;
import net.iponweb.disthene.events.MetricReceivedEvent;
import net.iponweb.disthene.events.MetricStoreEvent;

package net.iponweb.disthene.service.metric;


/**
 * @author Andrei Ivanov
 */
@Listener(references= References.Strong)
public class MetricService {

    private MBassador<DistheneEvent> bus;
    private BlacklistService blacklistService;
    private DistheneConfiguration distheneConfiguration;

    public MetricService(MBassador<DistheneEvent> bus, BlacklistService blacklistService, DistheneConfiguration distheneConfiguration) {
        this.bus = bus;
        this.blacklistService = blacklistService;
        this.distheneConfiguration = distheneConfiguration;
        bus.subscribe(this);
    }

    @Handler(rejectSubtypes = false)
    public void handle(MetricReceivedEvent metricReceivedEvent) {
        if (!blacklistService.isBlackListed(metricReceivedEvent.getMetric())) {
            if (distheneConfiguration.getCarbon().getAggregateBaseRollup()) {
                bus.post(new MetricAggregateEvent(metricReceivedEvent.getMetric())).now();