// Path: src/main/java/net/iponweb/disthene/bean/Metric.java
// public class Metric {
// 
//     private MetricKey key;
//     private double value;
// 
//     public Metric(String input, Rollup rollup) {
//         String[] splitInput = input.split("\\s");
//         // We were interning tenant and path here - we are going to store them all (or almost so) constantly anyhow in multiple places
//         // In fact this also work for a moderate metrics stream. Once we start receiving 10s of millions different metrics, it tends to degrade quite a bit
//         // So, leaving this only for tenant
//         this.key = new MetricKey(
//                 splitInput.length >=4 ? splitInput[3].intern() : "NONE",
//                 splitInput[0],
//                 rollup.getRollup(),
//                 rollup.getPeriod(),
//                 normalizeTimestamp(Long.parseLong(splitInput[2]), rollup));
//         this.value = Double.parseDouble(splitInput[1]);
//     }
// 
//     public Metric(String tenant, String path, int rollup, int period, double value, long timestamp) {
//         this.key = new MetricKey(tenant, path, rollup, period, timestamp);
//         this.value = value;
//     }
// 
//     public Metric(MetricKey key, double value) {
//         this.key = key;
//         this.value = value;
//     }
// 
//     private long normalizeTimestamp(long timestamp, Rollup rollup) {
//         return (timestamp / rollup.getRollup()) * rollup.getRollup();
//     }
// 
//     public String getId() {
//         return getTenant() + "_" + getPath();
//     }
// 
//     public String getTenant() {
//         return key.getTenant();
//     }
// 
//     public String getPath() {
//         return key.getPath();
//     }
// 
//     public int getRollup() {
//         return key.getRollup();
//     }
// 
//     public int getPeriod() {
//         return key.getPeriod();
//     }
// 
//     public double getValue() {
//         return value;
//     }
// 
//     public void setValue(double value) {
//         this.value = value;
//     }
// 
//     public long getTimestamp() {
//         return key.getTimestamp();
//     }
// 
//     @Override
//     public String toString() {
//         return "Metric{" +
//                 "key=" + key +
//                 ", value=" + value +
//                 '}';
//     }
// }
// 
// Path: src/main/java/net/iponweb/disthene/config/Rollup.java
// public class Rollup {
// 
//     private int rollup;
//     private int period;
// 
//     public Rollup(String s) {
//         String[] ss = s.split(":");
//         rollup = Integer.parseInt(ss[0].substring(0, ss[0].length() - 1));
//         period = (int) (Long.parseLong(ss[1].substring(0, ss[1].length() - 1)) / rollup);
//     }
// 
//     public int getRollup() {
//         return rollup;
//     }
// 
//     public void setRollup(int rollup) {
//         this.rollup = rollup;
//     }
// 
//     public int getPeriod() {
//         return period;
//     }
// 
//     public void setPeriod(int period) {
//         this.period = period;
//     }
// 
//     @Override
//     public String toString() {
//         return "Rollup{" +
//                 "rollup=" + rollup +
//                 ", period=" + period +
//                 '}';
//     }
// }
// 
// Path: src/main/java/net/iponweb/disthene/events/DistheneEvent.java
// public interface DistheneEvent {
// }
// 
// Path: src/main/java/net/iponweb/disthene/events/MetricReceivedEvent.java
// public class MetricReceivedEvent extends AbstractMetricEvent {
// 
//     public MetricReceivedEvent(Metric metric) {
//         super(metric);
//     }
// }


import com.google.common.base.CharMatcher;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.util.CharsetUtil;
import net.engio.mbassy.bus.MBassador;
import net.iponweb.disthene.bean.Metric;
import net.iponweb.disthene.config.Rollup;
import net.iponweb.disthene.events.DistheneEvent;
import net.iponweb.disthene.events.MetricReceivedEvent;
import org.apache.log4j.Logger;

package net.iponweb.disthene.carbon;


/**
 * @author Andrei Ivanov
 */
public class CarbonServerHandler extends ChannelInboundHandlerAdapter {
    private Logger logger = Logger.getLogger(CarbonServerHandler.class);


// Path: src/main/java/net/iponweb/disthene/bean/Metric.java
// public class Metric {
// 
//     private MetricKey key;
//     private double value;
// 
//     public Metric(String input, Rollup rollup) {
//         String[] splitInput = input.split("\\s");
//         // We were interning tenant and path here - we are going to store them all (or almost so) constantly anyhow in multiple places
//         // In fact this also work for a moderate metrics stream. Once we start receiving 10s of millions different metrics, it tends to degrade quite a bit
//         // So, leaving this only for tenant
//         this.key = new MetricKey(
//                 splitInput.length >=4 ? splitInput[3].intern() : "NONE",
//                 splitInput[0],
//                 rollup.getRollup(),
//                 rollup.getPeriod(),
//                 normalizeTimestamp(Long.parseLong(splitInput[2]), rollup));
//         this.value = Double.parseDouble(splitInput[1]);
//     }
// 
//     public Metric(String tenant, String path, int rollup, int period, double value, long timestamp) {
//         this.key = new MetricKey(tenant, path, rollup, period, timestamp);
//         this.value = value;
//     }
// 
//     public Metric(MetricKey key, double value) {
//         this.key = key;
//         this.value = value;
//     }
// 
//     private long normalizeTimestamp(long timestamp, Rollup rollup) {
//         return (timestamp / rollup.getRollup()) * rollup.getRollup();
//     }
// 
//     public String getId() {
//         return getTenant() + "_" + getPath();
//     }
// 
//     public String getTenant() {
//         return key.getTenant();
//     }
// 
//     public String getPath() {
//         return key.getPath();
//     }
// 
//     public int getRollup() {
//         return key.getRollup();
//     }
// 
//     public int getPeriod() {
//         return key.getPeriod();
//     }
// 
//     public double getValue() {
//         return value;
//     }
// 
//     public void setValue(double value) {
//         this.value = value;
//     }
// 
//     public long getTimestamp() {
//         return key.getTimestamp();
//     }
// 
//     @Override
//     public String toString() {
//         return "Metric{" +
//                 "key=" + key +
//                 ", value=" + value +
//                 '}';
//     }
// }
// 
// Path: src/main/java/net/iponweb/disthene/config/Rollup.java
// public class Rollup {
// 
//     private int rollup;
//     private int period;
// 
//     public Rollup(String s) {
//         String[] ss = s.split(":");
//         rollup = Integer.parseInt(ss[0].substring(0, ss[0].length() - 1));
//         period = (int) (Long.parseLong(ss[1].substring(0, ss[1].length() - 1)) / rollup);
//     }
// 
//     public int getRollup() {
//         return rollup;
//     }
// 
//     public void setRollup(int rollup) {
//         this.rollup = rollup;
//     }
// 
//     public int getPeriod() {
//         return period;
//     }
// 
//     public void setPeriod(int period) {
//         this.period = period;
//     }
// 
//     @Override
//     public String toString() {
//         return "Rollup{" +
//                 "rollup=" + rollup +
//                 ", period=" + period +
//                 '}';
//     }
// }
// 
// Path: src/main/java/net/iponweb/disthene/events/DistheneEvent.java
// public interface DistheneEvent {
// }
// 
// 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/carbon/CarbonServerHandler.java
import com.google.common.base.CharMatcher;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.util.CharsetUtil;
import net.engio.mbassy.bus.MBassador;
import net.iponweb.disthene.bean.Metric;
import net.iponweb.disthene.config.Rollup;
import net.iponweb.disthene.events.DistheneEvent;
import net.iponweb.disthene.events.MetricReceivedEvent;
import org.apache.log4j.Logger;

package net.iponweb.disthene.carbon;


/**
 * @author Andrei Ivanov
 */
public class CarbonServerHandler extends ChannelInboundHandlerAdapter {
    private Logger logger = Logger.getLogger(CarbonServerHandler.class);


    private MBassador<DistheneEvent> bus;
