Search in sources :

Example 1 with SecondaryTarget

use of com.ms.silverking.cloud.dht.SecondaryTarget in project SilverKing by Morgan-Stanley.

the class RingMapState method createSecondarySet.

private Set<IPAndPort> createSecondarySet(Set<SecondaryTarget> secondaryTargets) {
    ImmutableSet.Builder<IPAndPort> members;
    members = ImmutableSet.builder();
    for (SecondaryTarget target : secondaryTargets) {
        Set<IPAndPort> targetReplicas;
        switch(target.getType()) {
            case NodeID:
                targetReplicas = getTargetsByNodeID(target.getTarget());
                break;
            case AncestorClass:
                targetReplicas = getTargetsByAncestorClass(target.getTarget());
                break;
            default:
                throw new RuntimeException("Type not handled " + target.getType());
        }
        members.addAll(targetReplicas);
    }
    return members.build();
}
Also used : SecondaryTarget(com.ms.silverking.cloud.dht.SecondaryTarget) IPAndPort(com.ms.silverking.net.IPAndPort) ImmutableSet(com.google.common.collect.ImmutableSet)

Example 2 with SecondaryTarget

use of com.ms.silverking.cloud.dht.SecondaryTarget in project SilverKing by Morgan-Stanley.

the class SecondaryTargetSerializer method deserialize.

public static Set<SecondaryTarget> deserialize(byte[] multiDef) {
    try {
        ImmutableSet.Builder<SecondaryTarget> specs;
        int i;
        specs = ImmutableSet.builder();
        i = 0;
        while (i < multiDef.length) {
            SecondaryTargetType type;
            int targetSize;
            byte[] targetBytes;
            String target;
            type = SecondaryTargetType.values()[multiDef[i++]];
            targetSize = NumConversion.bytesToShort(multiDef, i);
            i += NumConversion.BYTES_PER_SHORT;
            targetBytes = new byte[targetSize];
            System.arraycopy(multiDef, i, targetBytes, 0, targetSize);
            i += targetSize;
            target = new String(targetBytes);
            specs.add(new SecondaryTarget(type, target));
        }
        return specs.build();
    } catch (Exception e) {
        Log.logErrorWarning(e);
        return ImmutableSet.of();
    }
}
Also used : SecondaryTarget(com.ms.silverking.cloud.dht.SecondaryTarget) ImmutableSet(com.google.common.collect.ImmutableSet) SecondaryTargetType(com.ms.silverking.cloud.dht.client.SecondaryTargetType)

Example 3 with SecondaryTarget

use of com.ms.silverking.cloud.dht.SecondaryTarget in project SilverKing by Morgan-Stanley.

the class SecondaryTargetSerializer method serialize.

public static byte[] serialize(Set<SecondaryTarget> specs) {
    ByteList list;
    list = new ByteArrayList(initialBufferSize);
    for (SecondaryTarget spec : specs) {
        byte[] targetBytes;
        list.add((byte) spec.getType().ordinal());
        targetBytes = spec.getTarget().getBytes();
        list.addElements(list.size(), NumConversion.shortToBytes((short) targetBytes.length));
        list.addElements(list.size(), targetBytes);
    }
    return list.toByteArray();
}
Also used : SecondaryTarget(com.ms.silverking.cloud.dht.SecondaryTarget) ByteList(it.unimi.dsi.fastutil.bytes.ByteList) ByteArrayList(it.unimi.dsi.fastutil.bytes.ByteArrayList)

Example 4 with SecondaryTarget

use of com.ms.silverking.cloud.dht.SecondaryTarget in project SilverKing by Morgan-Stanley.

the class ObjectDefParserTest method main.

/**
 * @param args
 */
public static void main(String[] args) {
    try {
        ObjectDefParserTest test;
        String def;
        NamespaceOptions nsOptions;
        DHTUtil.currentTimeMillis();
        System.out.println();
        System.out.println("\n\n=================================\n\n");
        // System.out.println(DHTConstants.standardPutOptions);
        // System.out.println(DHTConstants.standardGetOptions);
        /*
            try {
                NamespaceOptions.parse("");
            } catch (Exception e) {
            }
            try {
                def = new SecondaryTarget(SecondaryTargetType.AncestorClass, "").toString();
            } catch (Exception e) {
            }
            */
        new SecondaryTarget(null, null);
        def = "defaultPutOptions={secondaryTargets={{type=AncestorClass,target=Campus}}}";
        nsOptions = ObjectDefParser2.parse(NamespaceOptions.class, def);
        System.exit(0);
        def = new NamespaceOptions(DHTConstants.defaultStorageType, DHTConstants.defaultConsistencyProtocol, DHTConstants.defaultVersionMode, DHTConstants.defaultRevisionMode, DHTConstants.standardPutOptions.secondaryTargets(new SecondaryTarget(SecondaryTargetType.AncestorClass, "Region")), DHTConstants.standardInvalidationOptions, DHTConstants.standardGetOptions, DHTConstants.standardWaitOptions, 0, 0, false).toString();
        /*
            def = new NamespaceOptions(DHTConstants.defaultStorageType, DHTConstants.defaultConsistencyProtocol, 
                    DHTConstants.defaultVersionMode, DHTConstants.standardPutOptions,
                    DHTConstants.standardGetOptions, DHTConstants.standardWaitOptions).toString();
                    */
        System.out.println(def);
        System.out.println();
        nsOptions = ObjectDefParser2.parse(NamespaceOptions.class, def);
        System.out.println(nsOptions);
        for (SecondaryTarget target : nsOptions.getDefaultPutOptions().getSecondaryTargets()) {
            System.out.println(target);
        }
    // test = new ObjectDefParserTest();
    // test.test(def);
    /*
            for (String arg : args) {
                test.test(arg);
            }
            */
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : SecondaryTarget(com.ms.silverking.cloud.dht.SecondaryTarget) NamespaceOptions(com.ms.silverking.cloud.dht.NamespaceOptions)

Example 5 with SecondaryTarget

use of com.ms.silverking.cloud.dht.SecondaryTarget in project SilverKing by Morgan-Stanley.

the class RingMapState2 method createSecondarySet.

private Set<IPAndPort> createSecondarySet(Set<SecondaryTarget> secondaryTargets) {
    ImmutableSet.Builder<IPAndPort> members;
    members = ImmutableSet.builder();
    for (SecondaryTarget target : secondaryTargets) {
        Set<IPAndPort> targetReplicas;
        switch(target.getType()) {
            case NodeID:
                targetReplicas = getTargetsByNodeID(target.getTarget());
                break;
            case AncestorClass:
                targetReplicas = getTargetsByAncestorClass(target.getTarget());
                break;
            default:
                throw new RuntimeException("Type not handled " + target.getType());
        }
        members.addAll(targetReplicas);
    }
    return members.build();
}
Also used : SecondaryTarget(com.ms.silverking.cloud.dht.SecondaryTarget) IPAndPort(com.ms.silverking.net.IPAndPort) ImmutableSet(com.google.common.collect.ImmutableSet)

Aggregations

SecondaryTarget (com.ms.silverking.cloud.dht.SecondaryTarget)5 ImmutableSet (com.google.common.collect.ImmutableSet)3 IPAndPort (com.ms.silverking.net.IPAndPort)2 NamespaceOptions (com.ms.silverking.cloud.dht.NamespaceOptions)1 SecondaryTargetType (com.ms.silverking.cloud.dht.client.SecondaryTargetType)1 ByteArrayList (it.unimi.dsi.fastutil.bytes.ByteArrayList)1 ByteList (it.unimi.dsi.fastutil.bytes.ByteList)1