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