use of com.yahoo.slime.ArrayTraverser in project vespa by vespa-engine.
the class ProvisionInfo method fromSlime.
private static ProvisionInfo fromSlime(Inspector inspector, Optional<NodeFlavors> nodeFlavors) {
Inspector array = inspector.field(mappingKey);
Set<HostSpec> hosts = new LinkedHashSet<>();
array.traverse(new ArrayTraverser() {
@Override
public void entry(int i, Inspector inspector) {
hosts.add(hostsFromSlime(inspector.field(hostSpecKey), nodeFlavors));
}
});
return new ProvisionInfo(hosts);
}
use of com.yahoo.slime.ArrayTraverser in project vespa by vespa-engine.
the class ConfigPayloadApplier method handleARRAY.
private void handleARRAY(Inspector inspector) {
trace("Array");
inspector.traverse(new ArrayTraverser() {
@Override
public void entry(int idx, Inspector inspector) {
handleArrayEntry(idx, inspector);
}
});
}
use of com.yahoo.slime.ArrayTraverser in project vespa by vespa-engine.
the class MockClient method getDocsums.
@Override
public void getDocsums(List<FastHit> hitsContext, NodeConnection node, CompressionType compression, int uncompressedSize, byte[] compressedSlime, Dispatcher.GetDocsumsResponseReceiver responseReceiver, double timeoutSeconds) {
if (malfunctioning) {
responseReceiver.receive(GetDocsumsResponseOrError.fromError("Malfunctioning"));
return;
}
Inspector request = BinaryFormat.decode(compressor.decompress(compressedSlime, compression, uncompressedSize)).get();
String docsumClass = request.field("class").asString();
List<Map<String, Object>> docsumsToReturn = new ArrayList<>();
request.field("gids").traverse((ArrayTraverser) (index, gid) -> {
GlobalId docId = new GlobalId(gid.asData());
docsumsToReturn.add(docsums.get(new DocsumKey(node.toString(), docId, docsumClass)));
});
Slime responseSlime = new Slime();
Cursor root = responseSlime.setObject();
Cursor docsums = root.setArray("docsums");
for (Map<String, Object> docsumFields : docsumsToReturn) {
Cursor docsumItem = docsums.addObject();
Cursor docsum = docsumItem.setObject("docsum");
for (Map.Entry<String, Object> field : docsumFields.entrySet()) {
if (field.getValue() instanceof Integer)
docsum.setLong(field.getKey(), (Integer) field.getValue());
else if (field.getValue() instanceof String)
docsum.setString(field.getKey(), (String) field.getValue());
else
throw new RuntimeException();
}
}
byte[] slimeBytes = BinaryFormat.encode(responseSlime);
Compressor.Compression compressionResult = compressor.compress(compression, slimeBytes);
GetDocsumsResponse response = new GetDocsumsResponse(compressionResult.type().getCode(), slimeBytes.length, compressionResult.data(), hitsContext);
responseReceiver.receive(GetDocsumsResponseOrError.fromResponse(response));
}
use of com.yahoo.slime.ArrayTraverser in project vespa by vespa-engine.
the class StringSetSerializer method fromJson.
public Set<String> fromJson(byte[] data) {
Inspector inspector = SlimeUtils.jsonToSlime(data).get();
Set<String> stringSet = new HashSet<>();
inspector.traverse((ArrayTraverser) (index, name) -> stringSet.add(name.asString()));
return stringSet;
}
Aggregations