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