Search in sources :

Example 1 with AbstractChecksumNode

use of com.ms.silverking.cloud.dht.daemon.storage.convergence.AbstractChecksumNode in project SilverKing by Morgan-Stanley.

the class ProtoChecksumTreeMessageGroup method deserialize.

public static ChecksumNode deserialize(ByteBuffer buffer) {
    NodeType type;
    RingRegion region;
    int numChildren;
    AbstractChecksumNode root;
    type = NodeType.values()[buffer.get()];
    if (type != NodeType.NULL) {
        region = deserializeRegion(buffer);
        numChildren = buffer.getInt();
    } else {
        region = null;
        numChildren = 0;
    }
    switch(type) {
        case NON_LEAF:
            List<ChecksumNode> children;
            children = new ArrayList<>(numChildren);
            for (int i = 0; i < numChildren; i++) {
                children.add(deserialize(buffer));
            }
            root = new NonLeafChecksumNode(region, children);
            break;
        case LEAF:
            List<KeyAndVersionChecksum> keyAndVersionChecksums;
            keyAndVersionChecksums = deserializeKeyAndVersionChecksums(buffer);
            root = new LeafChecksumNode(region, keyAndVersionChecksums);
            break;
        case NULL:
            root = null;
            break;
        default:
            throw new RuntimeException("panic");
    }
    if (root != null) {
        root.freezeIfNotFrozen();
    }
    return root;
}
Also used : KeyAndVersionChecksum(com.ms.silverking.cloud.dht.daemon.storage.KeyAndVersionChecksum) NonLeafChecksumNode(com.ms.silverking.cloud.dht.daemon.storage.convergence.NonLeafChecksumNode) RingRegion(com.ms.silverking.cloud.ring.RingRegion) LeafChecksumNode(com.ms.silverking.cloud.dht.daemon.storage.convergence.LeafChecksumNode) NonLeafChecksumNode(com.ms.silverking.cloud.dht.daemon.storage.convergence.NonLeafChecksumNode) AbstractChecksumNode(com.ms.silverking.cloud.dht.daemon.storage.convergence.AbstractChecksumNode) ChecksumNode(com.ms.silverking.cloud.dht.daemon.storage.convergence.ChecksumNode) LeafChecksumNode(com.ms.silverking.cloud.dht.daemon.storage.convergence.LeafChecksumNode) NonLeafChecksumNode(com.ms.silverking.cloud.dht.daemon.storage.convergence.NonLeafChecksumNode) AbstractChecksumNode(com.ms.silverking.cloud.dht.daemon.storage.convergence.AbstractChecksumNode) ConvergencePoint(com.ms.silverking.cloud.dht.daemon.storage.convergence.ConvergencePoint)

Aggregations

KeyAndVersionChecksum (com.ms.silverking.cloud.dht.daemon.storage.KeyAndVersionChecksum)1 AbstractChecksumNode (com.ms.silverking.cloud.dht.daemon.storage.convergence.AbstractChecksumNode)1 ChecksumNode (com.ms.silverking.cloud.dht.daemon.storage.convergence.ChecksumNode)1 ConvergencePoint (com.ms.silverking.cloud.dht.daemon.storage.convergence.ConvergencePoint)1 LeafChecksumNode (com.ms.silverking.cloud.dht.daemon.storage.convergence.LeafChecksumNode)1 NonLeafChecksumNode (com.ms.silverking.cloud.dht.daemon.storage.convergence.NonLeafChecksumNode)1 RingRegion (com.ms.silverking.cloud.ring.RingRegion)1