Search in sources :

Example 1 with Utf8Array

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

the class JRTClientConfigRequestV3 method getNewPayload.

@Override
public Payload getNewPayload() {
    CompressionInfo compressionInfo = getResponseData().getCompressionInfo();
    Utf8Array payload = new Utf8Array(request.returnValues().get(1).asData());
    return Payload.from(payload, compressionInfo);
}
Also used : Utf8Array(com.yahoo.text.Utf8Array)

Example 2 with Utf8Array

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

the class Payload method withCompression.

/**
 * Returns a copy of this payload where the data is compressed using the given compression
 */
public Payload withCompression(CompressionType requestedCompression) {
    CompressionType responseCompression = compressionInfo.getCompressionType();
    if (requestedCompression == CompressionType.UNCOMPRESSED && responseCompression == CompressionType.LZ4) {
        byte[] buffer = new byte[compressionInfo.getUncompressedSize()];
        compressor.decompress(data.getBytes(), buffer);
        Utf8Array data = new Utf8Array(buffer);
        CompressionInfo info = CompressionInfo.create(CompressionType.UNCOMPRESSED, compressionInfo.getUncompressedSize());
        return Payload.from(data, info);
    } else if (requestedCompression == CompressionType.LZ4 && responseCompression == CompressionType.UNCOMPRESSED) {
        Utf8Array data = new Utf8Array(compressor.compress(this.data.getBytes()));
        CompressionInfo info = CompressionInfo.create(CompressionType.LZ4, this.data.getByteLength());
        return Payload.from(data, info);
    } else {
        return Payload.from(data, compressionInfo);
    }
}
Also used : Utf8Array(com.yahoo.text.Utf8Array)

Example 3 with Utf8Array

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

the class PayloadTest method testEquals.

@Test
public void testEquals() {
    final String foo1 = "foo 1";
    final String foo2 = "foo 2";
    Payload a = Payload.from(foo1);
    Payload b = Payload.from(foo1);
    Payload c = Payload.from(foo2);
    Slime slime = new Slime();
    slime.setString(foo1);
    Payload d = Payload.from(new ConfigPayload(slime));
    slime.setString(foo1);
    Payload e = Payload.from(new ConfigPayload(slime));
    slime.setString("foo 2");
    Payload f = Payload.from(new ConfigPayload(slime));
    Payload g = null;
    Payload h = null;
    Payload i = null;
    Payload j = null;
    try {
        g = Payload.from(new Utf8Array(foo1.getBytes("UTF-8")), CompressionInfo.uncompressed());
        h = Payload.from(new Utf8Array(foo1.getBytes("UTF-8")), CompressionInfo.uncompressed());
        LZ4PayloadCompressor compressor = new LZ4PayloadCompressor();
        CompressionInfo info = CompressionInfo.create(CompressionType.LZ4, foo2.length());
        Utf8Array compressed = new Utf8Array(compressor.compress(foo2.getBytes()));
        i = Payload.from(compressed, info);
        j = Payload.from(compressed, info);
    } catch (UnsupportedEncodingException e1) {
        fail();
    }
    new EqualsTester().addEqualityGroup(a, b, g, h).addEqualityGroup(c).addEqualityGroup(d, e).addEqualityGroup(f).addEqualityGroup(i, j).testEquals();
}
Also used : ConfigPayload(com.yahoo.vespa.config.ConfigPayload) EqualsTester(com.google.common.testing.EqualsTester) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ConfigPayload(com.yahoo.vespa.config.ConfigPayload) LZ4PayloadCompressor(com.yahoo.vespa.config.LZ4PayloadCompressor) Slime(com.yahoo.slime.Slime) Utf8Array(com.yahoo.text.Utf8Array) Test(org.junit.Test)

Example 4 with Utf8Array

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

the class LZ4ConfigResponseFactory method createResponse.

@Override
public ConfigResponse createResponse(ConfigPayload payload, InnerCNode defFile, long generation) {
    Utf8Array rawPayload = payload.toUtf8Array(true);
    String configMd5 = ConfigUtils.getMd5(rawPayload);
    CompressionInfo info = CompressionInfo.create(CompressionType.LZ4, rawPayload.getByteLength());
    Utf8Array compressed = new Utf8Array(compressor.compress(rawPayload.getBytes()));
    return new SlimeConfigResponse(compressed, defFile, generation, configMd5, info);
}
Also used : SlimeConfigResponse(com.yahoo.vespa.config.protocol.SlimeConfigResponse) CompressionInfo(com.yahoo.vespa.config.protocol.CompressionInfo) Utf8Array(com.yahoo.text.Utf8Array)

Example 5 with Utf8Array

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

the class UncompressedConfigResponseFactory method createResponse.

@Override
public ConfigResponse createResponse(ConfigPayload payload, InnerCNode defFile, long generation) {
    Utf8Array rawPayload = payload.toUtf8Array(true);
    String configMd5 = ConfigUtils.getMd5(rawPayload);
    CompressionInfo info = CompressionInfo.create(CompressionType.UNCOMPRESSED, rawPayload.getByteLength());
    return new SlimeConfigResponse(rawPayload, defFile, generation, configMd5, info);
}
Also used : SlimeConfigResponse(com.yahoo.vespa.config.protocol.SlimeConfigResponse) CompressionInfo(com.yahoo.vespa.config.protocol.CompressionInfo) Utf8Array(com.yahoo.text.Utf8Array)

Aggregations

Utf8Array (com.yahoo.text.Utf8Array)15 Version (com.yahoo.component.Version)3 Slime (com.yahoo.slime.Slime)3 CompressionType (com.yahoo.compress.CompressionType)2 EmptyReply (com.yahoo.messagebus.EmptyReply)2 Error (com.yahoo.messagebus.Error)2 Reply (com.yahoo.messagebus.Reply)2 Inspector (com.yahoo.slime.Inspector)2 ConfigPayload (com.yahoo.vespa.config.ConfigPayload)2 LZ4PayloadCompressor (com.yahoo.vespa.config.LZ4PayloadCompressor)2 CompressionInfo (com.yahoo.vespa.config.protocol.CompressionInfo)2 SlimeConfigResponse (com.yahoo.vespa.config.protocol.SlimeConfigResponse)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 Test (org.junit.Test)2 EqualsTester (com.google.common.testing.EqualsTester)1 DefParser (com.yahoo.config.codegen.DefParser)1 InnerCNode (com.yahoo.config.codegen.InnerCNode)1 DataTypeName (com.yahoo.document.DataTypeName)1 DocumentType (com.yahoo.document.DocumentType)1 DocumentTypeManager (com.yahoo.document.DocumentTypeManager)1