Search in sources :

Example 1 with LeafChecksumNode

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

the class ProtoChecksumTreeMessageGroup method serialize.

public static void serialize(ByteBuffer buffer, ChecksumNode node) {
    if (node == null) {
        // only supported for root of tree
        writeNullRoot(buffer);
    } else {
        if (node instanceof NonLeafChecksumNode) {
            List<? extends ChecksumNode> children;
            writeNodeHeader(buffer, NodeType.NON_LEAF, node);
            children = node.getChildren();
            for (ChecksumNode child : children) {
                serialize(buffer, child);
            }
        } else if (node instanceof LeafChecksumNode) {
            writeNodeHeader(buffer, NodeType.LEAF, node);
            writeKeyAndVersionChecksums(buffer, (LeafChecksumNode) node);
        } else {
            throw new RuntimeException("panic");
        }
    }
}
Also used : NonLeafChecksumNode(com.ms.silverking.cloud.dht.daemon.storage.convergence.NonLeafChecksumNode) 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)

Example 2 with LeafChecksumNode

use of com.ms.silverking.cloud.dht.daemon.storage.convergence.LeafChecksumNode 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

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