Search in sources :

Example 1 with Utf8String

use of com.yahoo.text.Utf8String in project vespa by vespa-engine.

the class QueryPacket method encodeBody.

public void encodeBody(ByteBuffer buffer) {
    queryPacketData = new QueryPacketData();
    final int relativeZero = buffer.position();
    boolean sendSessionKey = query.getGroupingSessionCache() || query.getRanking().getQueryCache();
    int featureFlag = getFeatureInt(sendSessionKey);
    buffer.putInt(featureFlag);
    ignoreableOffset = buffer.position() - relativeZero;
    IntegerCompressor.putCompressedPositiveNumber(getOffset(), buffer);
    IntegerCompressor.putCompressedPositiveNumber(getHits(), buffer);
    // Safety to avoid sending down 0 or negative number
    buffer.putInt(Math.max(1, (int) query.getTimeLeft()));
    ignoreableSize = buffer.position() - relativeZero - ignoreableOffset;
    buffer.putInt(getFlagInt());
    int startOfFieldToSave = buffer.position();
    Item.putString(query.getRanking().getProfile(), buffer);
    queryPacketData.setRankProfile(buffer, startOfFieldToSave);
    if ((featureFlag & QF_PROPERTIES) != 0) {
        startOfFieldToSave = buffer.position();
        query.encodeAsProperties(buffer, true);
        queryPacketData.setPropertyMaps(buffer, startOfFieldToSave);
    }
    if ((featureFlag & QF_SORTSPEC) != 0) {
        int sortSpecLengthPosition = buffer.position();
        buffer.putInt(0);
        int sortSpecLength = query.getRanking().getSorting().encode(buffer);
        buffer.putInt(sortSpecLengthPosition, sortSpecLength);
    }
    if ((featureFlag & QF_GROUPSPEC) != 0) {
        List<Grouping> groupingList = GroupingExecutor.getGroupingList(query);
        BufferSerializer gbuf = new BufferSerializer(new GrowableByteBuffer());
        gbuf.putInt(null, groupingList.size());
        for (Grouping g : groupingList) {
            g.serialize(gbuf);
        }
        gbuf.getBuf().flip();
        byte[] blob = new byte[gbuf.getBuf().limit()];
        gbuf.getBuf().get(blob);
        buffer.putInt(blob.length);
        buffer.put(blob);
    }
    sessionOffset = buffer.position() - relativeZero;
    if (sendSessionKey) {
        Utf8String key = query.getSessionId(true).asUtf8String();
        sessionSize = key.getByteLength();
        buffer.putInt(key.getByteLength());
        buffer.put(key.getBytes());
    }
    if ((featureFlag & QF_LOCATION) != 0) {
        startOfFieldToSave = buffer.position();
        int locationLengthPosition = buffer.position();
        buffer.putInt(0);
        int locationLength = query.getRanking().getLocation().encode(buffer);
        buffer.putInt(locationLengthPosition, locationLength);
        queryPacketData.setLocation(buffer, startOfFieldToSave);
    }
    startOfFieldToSave = buffer.position();
    int stackItemPosition = buffer.position();
    // Number of stack items written below
    buffer.putInt(0);
    int stackLengthPosition = buffer.position();
    buffer.putInt(0);
    int stackPosition = buffer.position();
    int stackItemCount = query.encode(buffer);
    int stackLength = buffer.position() - stackPosition;
    buffer.putInt(stackItemPosition, stackItemCount);
    buffer.putInt(stackLengthPosition, stackLength);
    queryPacketData.setQueryStack(buffer, startOfFieldToSave);
}
Also used : Utf8String(com.yahoo.text.Utf8String) BufferSerializer(com.yahoo.vespa.objects.BufferSerializer) GrowableByteBuffer(com.yahoo.io.GrowableByteBuffer) Grouping(com.yahoo.searchlib.aggregation.Grouping)

Example 2 with Utf8String

use of com.yahoo.text.Utf8String in project vespa by vespa-engine.

the class DefaultTemplateSet method writeOpenFieldElement.

private void writeOpenFieldElement(String fieldName, XMLWriter writer) throws IOException {
    Utf8String utf8 = fieldNameMap.get(fieldName);
    if (utf8 == null) {
        utf8 = new Utf8String(fieldName);
        fieldNameMap.put(fieldName, utf8);
    }
    writer.openTag(FIELD).attribute(NAME, utf8);
    writer.closeStartTag();
}
Also used : Utf8String(com.yahoo.text.Utf8String)

Example 3 with Utf8String

use of com.yahoo.text.Utf8String in project vespa by vespa-engine.

the class DefaultRenderer method writeOpenFieldElement.

private void writeOpenFieldElement(XMLWriter writer, String relevancyFieldName) throws IOException {
    Utf8String utf8 = fieldNameMap.get(relevancyFieldName);
    if (utf8 == null) {
        utf8 = new Utf8String(relevancyFieldName);
        fieldNameMap.put(relevancyFieldName, utf8);
    }
    writer.openTag(FIELD).attribute(NAME, utf8);
    writer.closeStartTag();
}
Also used : Utf8String(com.yahoo.text.Utf8String)

Example 4 with Utf8String

use of com.yahoo.text.Utf8String in project vespa by vespa-engine.

the class SyncDefaultRenderer method writeOpenFieldElement.

private void writeOpenFieldElement(XMLWriter writer, String relevancyFieldName) throws IOException {
    Utf8String utf8 = fieldNameMap.get(relevancyFieldName);
    if (utf8 == null) {
        utf8 = new Utf8String(relevancyFieldName);
        fieldNameMap.put(relevancyFieldName, utf8);
    }
    writer.openTag(FIELD).attribute(NAME, utf8);
    writer.closeStartTag();
}
Also used : Utf8String(com.yahoo.text.Utf8String)

Example 5 with Utf8String

use of com.yahoo.text.Utf8String in project vespa by vespa-engine.

the class StatusResponse method render.

@Override
public void render(OutputStream stream) throws IOException {
    XMLWriter writer = new XMLWriter(new OutputStreamWriter(stream));
    writer.openTag("status");
    if (verbosity >= 2) {
        writer.attribute(new Utf8String("description"), "Metrics since start");
    }
    if (snapshotTime == 0) {
        MetricSnapshot snapshot = (new MetricSnapshot("Total metrics from start until current time", 0, manager.getActiveMetrics().getMetrics(), false));
        manager.getTotalMetricSnapshot().addToSnapshot(snapshot, (int) (System.currentTimeMillis() / 1000), false);
        snapshot.printXml(manager, "", verbosity, writer);
    } else {
        try {
            manager.getMetricSnapshotSet(snapshotTime).getSnapshot().printXml(manager, "", verbosity, writer);
        } catch (Exception e) {
            writer.openTag("error");
            writer.attribute(new Utf8String("details"), "No metric snapshot with period " + snapshotTime + " was found. Legal snapshot periods are: " + manager.getSnapshotPeriods());
            writer.closeTag();
        }
    }
    writer.closeTag();
    writer.flush();
}
Also used : Utf8String(com.yahoo.text.Utf8String) OutputStreamWriter(java.io.OutputStreamWriter) XMLWriter(com.yahoo.text.XMLWriter) MetricSnapshot(com.yahoo.metrics.MetricSnapshot) IOException(java.io.IOException)

Aggregations

Utf8String (com.yahoo.text.Utf8String)7 XMLWriter (com.yahoo.text.XMLWriter)2 OutputStreamWriter (java.io.OutputStreamWriter)2 DataTypeName (com.yahoo.document.DataTypeName)1 DocumentType (com.yahoo.document.DocumentType)1 GrowableByteBuffer (com.yahoo.io.GrowableByteBuffer)1 MetricSnapshot (com.yahoo.metrics.MetricSnapshot)1 Grouping (com.yahoo.searchlib.aggregation.Grouping)1 Utf8Array (com.yahoo.text.Utf8Array)1 BufferSerializer (com.yahoo.vespa.objects.BufferSerializer)1 IOException (java.io.IOException)1