Search in sources :

Example 6 with ArrayTraverser

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);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Inspector(com.yahoo.slime.Inspector) ArrayTraverser(com.yahoo.slime.ArrayTraverser)

Example 7 with ArrayTraverser

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);
        }
    });
}
Also used : Inspector(com.yahoo.slime.Inspector) ArrayTraverser(com.yahoo.slime.ArrayTraverser)

Example 8 with ArrayTraverser

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));
}
Also used : Cursor(com.yahoo.slime.Cursor) BinaryFormat(com.yahoo.slime.BinaryFormat) Inspector(com.yahoo.slime.Inspector) ArrayTraverser(com.yahoo.slime.ArrayTraverser) IdIdString(com.yahoo.document.idstring.IdIdString) Slime(com.yahoo.slime.Slime) HashMap(java.util.HashMap) Compressor(com.yahoo.compress.Compressor) FastHit(com.yahoo.prelude.fastsearch.FastHit) ArrayList(java.util.ArrayList) List(java.util.List) CompressionType(com.yahoo.compress.CompressionType) Map(java.util.Map) GlobalId(com.yahoo.document.GlobalId) ArrayList(java.util.ArrayList) Compressor(com.yahoo.compress.Compressor) IdIdString(com.yahoo.document.idstring.IdIdString) Slime(com.yahoo.slime.Slime) Cursor(com.yahoo.slime.Cursor) GlobalId(com.yahoo.document.GlobalId) Inspector(com.yahoo.slime.Inspector) HashMap(java.util.HashMap) Map(java.util.Map)

Example 9 with ArrayTraverser

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;
}
Also used : HashSet(java.util.HashSet) Cursor(com.yahoo.slime.Cursor) Inspector(com.yahoo.slime.Inspector) SlimeUtils(com.yahoo.vespa.config.SlimeUtils) ArrayTraverser(com.yahoo.slime.ArrayTraverser) Slime(com.yahoo.slime.Slime) Set(java.util.Set) IOException(java.io.IOException) Inspector(com.yahoo.slime.Inspector) HashSet(java.util.HashSet)

Aggregations

ArrayTraverser (com.yahoo.slime.ArrayTraverser)9 Inspector (com.yahoo.slime.Inspector)9 Slime (com.yahoo.slime.Slime)5 Cursor (com.yahoo.slime.Cursor)4 SlimeUtils (com.yahoo.vespa.config.SlimeUtils)3 IOException (java.io.IOException)3 HashSet (java.util.HashSet)3 Set (java.util.Set)3 LinkedHashSet (java.util.LinkedHashSet)2 List (java.util.List)2 CompressionType (com.yahoo.compress.CompressionType)1 Compressor (com.yahoo.compress.Compressor)1 ApplicationId (com.yahoo.config.provision.ApplicationId)1 GlobalId (com.yahoo.document.GlobalId)1 IdIdString (com.yahoo.document.idstring.IdIdString)1 FastHit (com.yahoo.prelude.fastsearch.FastHit)1 BinaryFormat (com.yahoo.slime.BinaryFormat)1 JsonDecoder (com.yahoo.slime.JsonDecoder)1 TraceNode (com.yahoo.yolean.trace.TraceNode)1 ArrayDeque (java.util.ArrayDeque)1