Search in sources :

Example 1 with CompressionEnvelopeRequest

use of org.bboxdb.network.packages.request.CompressionEnvelopeRequest in project bboxdb by jnidzwetzki.

the class BBoxDBConnection method flushPendingCompressionPackages.

/**
 * Write all pending compression packages to server, called by the maintainance thread
 */
public void flushPendingCompressionPackages() {
    final List<NetworkRequestPackage> 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 NetworkRequestPackage compressionEnvelopeRequest = new CompressionEnvelopeRequest(NetworkConst.COMPRESSION_TYPE_GZIP, packagesToWrite);
    try {
        writePackageToSocket(compressionEnvelopeRequest);
    } catch (PackageEncodeException | IOException e) {
        logger.error("Got an exception while write pending compression packages to server", e);
        terminateConnection();
    }
}
Also used : CompressionEnvelopeRequest(org.bboxdb.network.packages.request.CompressionEnvelopeRequest) NetworkRequestPackage(org.bboxdb.network.packages.NetworkRequestPackage) ArrayList(java.util.ArrayList) PackageEncodeException(org.bboxdb.network.packages.PackageEncodeException) IOException(java.io.IOException)

Example 2 with CompressionEnvelopeRequest

use of org.bboxdb.network.packages.request.CompressionEnvelopeRequest in project bboxdb by jnidzwetzki.

the class TestCompressionRatio method handleCompressedData.

/**
 * Handle compressed packages
 * @param tableName
 * @param buffer
 * @return
 * @throws PackageEncodeException
 * @throws IOException
 */
protected long handleCompressedData(final TupleStoreName tableName, final List<Tuple> buffer) {
    final RoutingHeader routingHeader = new RoutingHeader(false);
    final List<NetworkRequestPackage> packages = buffer.stream().map(t -> new InsertTupleRequest((short) 4, routingHeader, tableName, t)).collect(Collectors.toList());
    final CompressionEnvelopeRequest compressionEnvelopeRequest = new CompressionEnvelopeRequest(NetworkConst.COMPRESSION_TYPE_GZIP, packages);
    buffer.clear();
    return packageToBytes(compressionEnvelopeRequest);
}
Also used : Arrays(java.util.Arrays) PackageEncodeException(org.bboxdb.network.packages.PackageEncodeException) Logger(org.slf4j.Logger) ByteArrayOutputStream(java.io.ByteArrayOutputStream) NetworkConst(org.bboxdb.network.NetworkConst) InsertTupleRequest(org.bboxdb.network.packages.request.InsertTupleRequest) RoutingHeader(org.bboxdb.network.routing.RoutingHeader) Tuple(org.bboxdb.storage.entity.Tuple) LoggerFactory(org.slf4j.LoggerFactory) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Objects(java.util.Objects) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) List(java.util.List) TupleFileReader(org.bboxdb.tools.TupleFileReader) CompressionEnvelopeRequest(org.bboxdb.network.packages.request.CompressionEnvelopeRequest) NetworkRequestPackage(org.bboxdb.network.packages.NetworkRequestPackage) CompressionEnvelopeRequest(org.bboxdb.network.packages.request.CompressionEnvelopeRequest) NetworkRequestPackage(org.bboxdb.network.packages.NetworkRequestPackage) RoutingHeader(org.bboxdb.network.routing.RoutingHeader) InsertTupleRequest(org.bboxdb.network.packages.request.InsertTupleRequest)

Example 3 with CompressionEnvelopeRequest

use of org.bboxdb.network.packages.request.CompressionEnvelopeRequest in project bboxdb by jnidzwetzki.

the class TestNetworkClasses method testCompression2Request.

/**
 * Test the decoding and the encoding of an compressed request package
 * @throws IOException
 * @throws PackageEncodeException
 */
@Test(timeout = 60000)
public void testCompression2Request() throws IOException, PackageEncodeException {
    final RoutingHeader routingHeader = ROUTING_HEADER_ROUTED;
    final Tuple tuple = new Tuple("abcdefghijklmopqrstuvxyz", BoundingBox.FULL_SPACE, "abcdefghijklmopqrstuvxyzabcdefghijklmopqrstuvxyzabcdefghijklmopqrstuvxyzabcdefghijklmopqrstuvxyzabcdefghijklmopqrstuvxyzabcdefghijklmopqrstuvxyzabcdefghijklmopqrstuvxyzabcdefghijklmopqrstuvxyzabcdefghijklmopqrstuvxyzabcdefghijklmopqrstuvxyz".getBytes(), 12);
    final short sequenceNumber = sequenceNumberGenerator.getNextSequenceNummber();
    final InsertTupleRequest insertPackage = new InsertTupleRequest(sequenceNumber, ROUTING_HEADER_ROUTED, new TupleStoreName("test"), tuple);
    Assert.assertEquals(routingHeader, insertPackage.getRoutingHeader());
    final CompressionEnvelopeRequest compressionPackage = new CompressionEnvelopeRequest(NetworkConst.COMPRESSION_TYPE_GZIP, Arrays.asList(insertPackage));
    final ByteArrayOutputStream bos = new ByteArrayOutputStream();
    compressionPackage.writeToOutputStream(bos);
    bos.close();
    final byte[] encodedVersion = bos.toByteArray();
    Assert.assertNotNull(encodedVersion);
    final ByteBuffer bb = NetworkPackageDecoder.encapsulateBytes(encodedVersion);
    Assert.assertNotNull(bb);
    final InputStream uncompressedByteStream = CompressionEnvelopeRequest.decodePackage(bb);
    final byte[] uncompressedBytes = ByteStreams.toByteArray(uncompressedByteStream);
    final ByteBuffer uncompressedByteBuffer = NetworkPackageDecoder.encapsulateBytes(uncompressedBytes);
    final InsertTupleRequest decodedPackage = InsertTupleRequest.decodeTuple(uncompressedByteBuffer);
    Assert.assertEquals(insertPackage.getTuple(), decodedPackage.getTuple());
    Assert.assertEquals(insertPackage.getTable(), decodedPackage.getTable());
    Assert.assertEquals(routingHeader, decodedPackage.getRoutingHeader());
    Assert.assertFalse(insertPackage.getRoutingHeader().equals(new RoutingHeader(false)));
    Assert.assertEquals(insertPackage, decodedPackage);
    Assert.assertEquals(insertPackage.hashCode(), decodedPackage.hashCode());
    Assert.assertTrue(insertPackage.toString().length() > 10);
}
Also used : CompressionEnvelopeRequest(org.bboxdb.network.packages.request.CompressionEnvelopeRequest) InputStream(java.io.InputStream) RoutingHeader(org.bboxdb.network.routing.RoutingHeader) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteBuffer(java.nio.ByteBuffer) JoinedTuple(org.bboxdb.storage.entity.JoinedTuple) Tuple(org.bboxdb.storage.entity.Tuple) DeletedTuple(org.bboxdb.storage.entity.DeletedTuple) InsertTupleRequest(org.bboxdb.network.packages.request.InsertTupleRequest) Test(org.junit.Test)

Example 4 with CompressionEnvelopeRequest

use of org.bboxdb.network.packages.request.CompressionEnvelopeRequest in project bboxdb by jnidzwetzki.

the class TestNetworkClasses method testCompression1Request.

/**
 * Test the decoding and the encoding of an compressed request package
 * @throws IOException
 * @throws PackageEncodeException
 */
@Test(timeout = 60000)
public void testCompression1Request() throws IOException, PackageEncodeException {
    final RoutingHeader routingHeader = ROUTING_HEADER_ROUTED;
    final Tuple tuple = new Tuple("key", BoundingBox.FULL_SPACE, "abc".getBytes(), 12);
    final short sequenceNumber = sequenceNumberGenerator.getNextSequenceNummber();
    final InsertTupleRequest insertPackage = new InsertTupleRequest(sequenceNumber, ROUTING_HEADER_ROUTED, new TupleStoreName("test"), tuple);
    Assert.assertEquals(routingHeader, insertPackage.getRoutingHeader());
    final CompressionEnvelopeRequest compressionPackage = new CompressionEnvelopeRequest(NetworkConst.COMPRESSION_TYPE_GZIP, Arrays.asList(insertPackage));
    final ByteArrayOutputStream bos = new ByteArrayOutputStream();
    compressionPackage.writeToOutputStream(bos);
    bos.close();
    final byte[] encodedVersion = bos.toByteArray();
    Assert.assertNotNull(encodedVersion);
    final ByteBuffer bb = NetworkPackageDecoder.encapsulateBytes(encodedVersion);
    Assert.assertNotNull(bb);
    final InputStream uncompressedByteStream = CompressionEnvelopeRequest.decodePackage(bb);
    final byte[] uncompressedBytes = ByteStreams.toByteArray(uncompressedByteStream);
    final ByteBuffer uncompressedByteBuffer = NetworkPackageDecoder.encapsulateBytes(uncompressedBytes);
    final InsertTupleRequest decodedPackage = InsertTupleRequest.decodeTuple(uncompressedByteBuffer);
    Assert.assertEquals(insertPackage.getTuple(), decodedPackage.getTuple());
    Assert.assertEquals(insertPackage.getTable(), decodedPackage.getTable());
    Assert.assertEquals(routingHeader, decodedPackage.getRoutingHeader());
    Assert.assertFalse(insertPackage.getRoutingHeader().equals(new RoutingHeader(false)));
    Assert.assertEquals(insertPackage, decodedPackage);
    Assert.assertEquals(insertPackage.hashCode(), decodedPackage.hashCode());
    Assert.assertTrue(insertPackage.toString().length() > 10);
}
Also used : CompressionEnvelopeRequest(org.bboxdb.network.packages.request.CompressionEnvelopeRequest) InputStream(java.io.InputStream) RoutingHeader(org.bboxdb.network.routing.RoutingHeader) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteBuffer(java.nio.ByteBuffer) JoinedTuple(org.bboxdb.storage.entity.JoinedTuple) Tuple(org.bboxdb.storage.entity.Tuple) DeletedTuple(org.bboxdb.storage.entity.DeletedTuple) InsertTupleRequest(org.bboxdb.network.packages.request.InsertTupleRequest) Test(org.junit.Test)

Aggregations

CompressionEnvelopeRequest (org.bboxdb.network.packages.request.CompressionEnvelopeRequest)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 InsertTupleRequest (org.bboxdb.network.packages.request.InsertTupleRequest)3 RoutingHeader (org.bboxdb.network.routing.RoutingHeader)3 Tuple (org.bboxdb.storage.entity.Tuple)3 TupleStoreName (org.bboxdb.storage.entity.TupleStoreName)3 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 ByteBuffer (java.nio.ByteBuffer)2 ArrayList (java.util.ArrayList)2 NetworkRequestPackage (org.bboxdb.network.packages.NetworkRequestPackage)2 PackageEncodeException (org.bboxdb.network.packages.PackageEncodeException)2 DeletedTuple (org.bboxdb.storage.entity.DeletedTuple)2 JoinedTuple (org.bboxdb.storage.entity.JoinedTuple)2 Test (org.junit.Test)2 Arrays (java.util.Arrays)1 List (java.util.List)1 Objects (java.util.Objects)1 Collectors (java.util.stream.Collectors)1 NetworkConst (org.bboxdb.network.NetworkConst)1