Search in sources :

Example 1 with UnknownVersionException

use of com.linkedin.kafka.cruisecontrol.metricsreporter.exception.UnknownVersionException in project cruise-control by linkedin.

the class PartitionMetricSample method fromBytes.

public static PartitionMetricSample fromBytes(byte[] bytes) throws UnknownVersionException {
    ByteBuffer buffer = ByteBuffer.wrap(bytes);
    // Not used at this point.
    byte version = buffer.get();
    if (version > CURRENT_VERSION) {
        throw new UnknownVersionException("Metric sample version " + version + " is higher than current version " + CURRENT_VERSION);
    }
    switch(version) {
        case 0:
            return readV0(buffer);
        case 1:
            return readV1(buffer);
        default:
            throw new IllegalStateException("Should never be here.");
    }
}
Also used : ByteBuffer(java.nio.ByteBuffer) UnknownVersionException(com.linkedin.kafka.cruisecontrol.metricsreporter.exception.UnknownVersionException)

Example 2 with UnknownVersionException

use of com.linkedin.kafka.cruisecontrol.metricsreporter.exception.UnknownVersionException in project cruise-control by linkedin.

the class BrokerMetricSample method fromBytes.

/**
 * Deserialize the bytes to get a broker metric data.
 * @param bytes the bytes to deserialize.
 * @return the deserialized broker metric sample.
 * @throws UnknownVersionException
 */
public static BrokerMetricSample fromBytes(byte[] bytes) throws UnknownVersionException {
    ByteBuffer buffer = ByteBuffer.wrap(bytes);
    byte version = buffer.get();
    if (version > CURRENT_VERSION) {
        throw new UnknownVersionException("The model broker metric sample version " + version + " is higher than the current" + "version " + CURRENT_VERSION);
    }
    switch(version) {
        case 0:
            return readV0(buffer);
        case 1:
            return readV1(buffer);
        case 2:
            return readV2(buffer);
        case 3:
            return readV3(buffer);
        default:
            throw new IllegalStateException("Should never be here");
    }
}
Also used : ByteBuffer(java.nio.ByteBuffer) UnknownVersionException(com.linkedin.kafka.cruisecontrol.metricsreporter.exception.UnknownVersionException)

Aggregations

UnknownVersionException (com.linkedin.kafka.cruisecontrol.metricsreporter.exception.UnknownVersionException)2 ByteBuffer (java.nio.ByteBuffer)2