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();
}
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();
}
}
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();
}
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();
}
}
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();
}
Aggregations