Search in sources :

Example 1 with CompressionEnvelopeResponse

use of org.bboxdb.network.packages.response.CompressionEnvelopeResponse in project bboxdb by jnidzwetzki.

the class ClientConnectionHandler method flushPendingCompressionPackages.

/**
 * Write all pending compression packages to server, called by the maintainance thread
 */
protected void flushPendingCompressionPackages() {
    final List<NetworkResponsePackage> packagesToWrite = new ArrayList<>();
    synchronized (pendingCompressionPackages) {
        if (pendingCompressionPackages.isEmpty()) {
            return;
        }
        packagesToWrite.addAll(pendingCompressionPackages);
        pendingCompressionPackages.clear();
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Chunk size is: {}", packagesToWrite.size());
    }
    final NetworkResponsePackage compressionEnvelopeRequest = new CompressionEnvelopeResponse(NetworkConst.COMPRESSION_TYPE_GZIP, packagesToWrite);
    try {
        writePackageToSocket(compressionEnvelopeRequest);
    } catch (PackageEncodeException | IOException e) {
        logger.error("Got an exception while write pending compression packages to client", e);
    }
}
Also used : CompressionEnvelopeResponse(org.bboxdb.network.packages.response.CompressionEnvelopeResponse) NetworkResponsePackage(org.bboxdb.network.packages.NetworkResponsePackage) ArrayList(java.util.ArrayList) PackageEncodeException(org.bboxdb.network.packages.PackageEncodeException) IOException(java.io.IOException)

Example 2 with CompressionEnvelopeResponse

use of org.bboxdb.network.packages.response.CompressionEnvelopeResponse in project bboxdb by jnidzwetzki.

the class TestNetworkClasses method testCompressionReponse2.

/**
 * Test the compression response
 * @throws IOException
 * @throws PackageEncodeException
 */
@Test(timeout = 60000)
public void testCompressionReponse2() throws IOException, PackageEncodeException {
    final PeerCapabilities peerCapabilities = new PeerCapabilities();
    peerCapabilities.setGZipCompression();
    final short sequenceNumber = sequenceNumberGenerator.getNextSequenceNummber();
    final HelloResponse helloPackage = new HelloResponse(sequenceNumber, 2, peerCapabilities);
    final CompressionEnvelopeResponse compressionEnvelopeResponse = new CompressionEnvelopeResponse(NetworkConst.COMPRESSION_TYPE_GZIP, Arrays.asList(helloPackage));
    final byte[] encodedPackage = networkPackageToByte(compressionEnvelopeResponse);
    Assert.assertNotNull(encodedPackage);
    final ByteBuffer bb = NetworkPackageDecoder.encapsulateBytes(encodedPackage);
    final InputStream uncompressedByteStream = CompressionEnvelopeResponse.decodePackage(bb);
    final byte[] uncompressedBytes = ByteStreams.toByteArray(uncompressedByteStream);
    final ByteBuffer uncompressedByteBuffer = NetworkPackageDecoder.encapsulateBytes(uncompressedBytes);
    final HelloResponse decodedPackage = HelloResponse.decodePackage(uncompressedByteBuffer);
    Assert.assertEquals(helloPackage, decodedPackage);
    Assert.assertTrue(helloPackage.getPeerCapabilities().hasGZipCompression());
    Assert.assertTrue(decodedPackage.getPeerCapabilities().hasGZipCompression());
    Assert.assertEquals(helloPackage.toString(), decodedPackage.toString());
}
Also used : CompressionEnvelopeResponse(org.bboxdb.network.packages.response.CompressionEnvelopeResponse) InputStream(java.io.InputStream) HelloResponse(org.bboxdb.network.packages.response.HelloResponse) PeerCapabilities(org.bboxdb.network.capabilities.PeerCapabilities) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 3 with CompressionEnvelopeResponse

use of org.bboxdb.network.packages.response.CompressionEnvelopeResponse in project bboxdb by jnidzwetzki.

the class TestNetworkClasses method testCompressionReponse1.

/**
 * Test the compression response
 * @throws IOException
 * @throws PackageEncodeException
 */
@Test(timeout = 60000)
public void testCompressionReponse1() throws IOException, PackageEncodeException {
    final String tablename = "table1";
    final Tuple tuple = new Tuple("abc", BoundingBox.FULL_SPACE, "databytes".getBytes());
    final TupleResponse singleTupleResponse = new TupleResponse((short) 4, tablename, tuple);
    final CompressionEnvelopeResponse compressionEnvelopeResponse = new CompressionEnvelopeResponse(NetworkConst.COMPRESSION_TYPE_GZIP, Arrays.asList(singleTupleResponse));
    final byte[] encodedPackage = networkPackageToByte(compressionEnvelopeResponse);
    Assert.assertNotNull(encodedPackage);
    final ByteBuffer bb = NetworkPackageDecoder.encapsulateBytes(encodedPackage);
    final InputStream uncompressedByteStream = CompressionEnvelopeResponse.decodePackage(bb);
    final byte[] uncompressedBytes = ByteStreams.toByteArray(uncompressedByteStream);
    final ByteBuffer uncompressedByteBuffer = NetworkPackageDecoder.encapsulateBytes(uncompressedBytes);
    final TupleResponse responseDecoded = TupleResponse.decodePackage(uncompressedByteBuffer);
    Assert.assertEquals(singleTupleResponse.getTable(), responseDecoded.getTable());
    Assert.assertEquals(singleTupleResponse.getTuple(), responseDecoded.getTuple());
    Assert.assertTrue(singleTupleResponse.toString().length() > 10);
}
Also used : TupleResponse(org.bboxdb.network.packages.response.TupleResponse) JoinedTupleResponse(org.bboxdb.network.packages.response.JoinedTupleResponse) CompressionEnvelopeResponse(org.bboxdb.network.packages.response.CompressionEnvelopeResponse) InputStream(java.io.InputStream) ByteBuffer(java.nio.ByteBuffer) JoinedTuple(org.bboxdb.storage.entity.JoinedTuple) Tuple(org.bboxdb.storage.entity.Tuple) DeletedTuple(org.bboxdb.storage.entity.DeletedTuple) Test(org.junit.Test)

Aggregations

CompressionEnvelopeResponse (org.bboxdb.network.packages.response.CompressionEnvelopeResponse)3 InputStream (java.io.InputStream)2 ByteBuffer (java.nio.ByteBuffer)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 PeerCapabilities (org.bboxdb.network.capabilities.PeerCapabilities)1 NetworkResponsePackage (org.bboxdb.network.packages.NetworkResponsePackage)1 PackageEncodeException (org.bboxdb.network.packages.PackageEncodeException)1 HelloResponse (org.bboxdb.network.packages.response.HelloResponse)1 JoinedTupleResponse (org.bboxdb.network.packages.response.JoinedTupleResponse)1 TupleResponse (org.bboxdb.network.packages.response.TupleResponse)1 DeletedTuple (org.bboxdb.storage.entity.DeletedTuple)1 JoinedTuple (org.bboxdb.storage.entity.JoinedTuple)1 Tuple (org.bboxdb.storage.entity.Tuple)1