Search in sources :

Example 1 with TupleResponse

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

the class TestNetworkClasses method testSingleTupleResponse.

/**
 * Try to encode and decode the single tuple response
 * @throws PackageEncodeException
 * @throws IOException
 */
@Test(timeout = 60000)
public void testSingleTupleResponse() throws PackageEncodeException, IOException {
    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 byte[] encodedPackage = networkPackageToByte(singleTupleResponse);
    Assert.assertNotNull(encodedPackage);
    final ByteBuffer bb = NetworkPackageDecoder.encapsulateBytes(encodedPackage);
    final TupleResponse responseDecoded = TupleResponse.decodePackage(bb);
    Assert.assertEquals(singleTupleResponse.getTable(), responseDecoded.getTable());
    Assert.assertEquals(singleTupleResponse.getTuple(), responseDecoded.getTuple());
    Assert.assertFalse(singleTupleResponse.getTuple() instanceof DeletedTuple);
    Assert.assertTrue(singleTupleResponse.toString().length() > 10);
}
Also used : TupleResponse(org.bboxdb.network.packages.response.TupleResponse) JoinedTupleResponse(org.bboxdb.network.packages.response.JoinedTupleResponse) DeletedTuple(org.bboxdb.storage.entity.DeletedTuple) 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)

Example 2 with TupleResponse

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

the class TestNetworkClasses method testSingleTupleDeletedResponse.

/**
 * Try to encode and decode the single tuple response - with deleted tuple
 * @throws PackageEncodeException
 * @throws IOException
 */
@Test(timeout = 60000)
public void testSingleTupleDeletedResponse() throws PackageEncodeException, IOException {
    final String tablename = "table1";
    final Tuple tuple = new DeletedTuple("abc", 12);
    final TupleResponse singleTupleResponse = new TupleResponse((short) 4, tablename, tuple);
    final byte[] encodedPackage = networkPackageToByte(singleTupleResponse);
    Assert.assertNotNull(encodedPackage);
    final ByteBuffer bb = NetworkPackageDecoder.encapsulateBytes(encodedPackage);
    final TupleResponse responseDecoded = TupleResponse.decodePackage(bb);
    Assert.assertEquals(singleTupleResponse.getTable(), responseDecoded.getTable());
    Assert.assertEquals(singleTupleResponse.getTuple(), responseDecoded.getTuple());
    Assert.assertTrue(singleTupleResponse.getTuple() instanceof DeletedTuple);
    Assert.assertEquals(singleTupleResponse.toString(), responseDecoded.toString());
}
Also used : TupleResponse(org.bboxdb.network.packages.response.TupleResponse) JoinedTupleResponse(org.bboxdb.network.packages.response.JoinedTupleResponse) DeletedTuple(org.bboxdb.storage.entity.DeletedTuple) 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)

Example 3 with TupleResponse

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

the class ClientConnectionHandler method writeResultTuple.

/**
 * Send a new result tuple to the client
 * @param packageSequence
 * @param requestTable
 * @param tuple
 * @throws PackageEncodeException
 * @throws IOException
 */
public void writeResultTuple(final short packageSequence, final JoinedTuple joinedTuple) throws IOException, PackageEncodeException {
    if (joinedTuple.getNumberOfTuples() == 1) {
        final TupleResponse responsePackage = new TupleResponse(packageSequence, joinedTuple.getTupleStoreName(0), joinedTuple.getTuple(0));
        writeResultPackage(responsePackage);
    } else {
        final JoinedTupleResponse responsePackage = new JoinedTupleResponse(packageSequence, joinedTuple);
        writeResultPackage(responsePackage);
    }
}
Also used : TupleResponse(org.bboxdb.network.packages.response.TupleResponse) JoinedTupleResponse(org.bboxdb.network.packages.response.JoinedTupleResponse) JoinedTupleResponse(org.bboxdb.network.packages.response.JoinedTupleResponse)

Example 4 with TupleResponse

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

the class TupleHandler method handleServerResult.

/**
 * Handle a single tuple as result
 * @return
 */
@Override
public boolean handleServerResult(final BBoxDBConnection bBoxDBConnection, final ByteBuffer encodedPackage, final NetworkOperationFuture future) throws PackageEncodeException {
    if (logger.isDebugEnabled()) {
        logger.debug("Handle tuple package");
    }
    final TupleResponse singleTupleResponse = TupleResponse.decodePackage(encodedPackage);
    final short sequenceNumber = singleTupleResponse.getSequenceNumber();
    // Tuple is part of a multi tuple result
    final Map<Short, List<PagedTransferableEntity>> resultBuffer = bBoxDBConnection.getResultBuffer();
    if (resultBuffer.containsKey(sequenceNumber)) {
        final List<PagedTransferableEntity> packageResult = resultBuffer.get(sequenceNumber);
        packageResult.add(singleTupleResponse.getTuple());
        // tuple result or a multiple tuple result
        return false;
    }
    // Single tuple is returned
    if (future != null) {
        future.setOperationResult(Arrays.asList(singleTupleResponse.getTuple()));
        future.fireCompleteEvent();
    }
    return true;
}
Also used : TupleResponse(org.bboxdb.network.packages.response.TupleResponse) PagedTransferableEntity(org.bboxdb.storage.entity.PagedTransferableEntity) List(java.util.List)

Example 5 with TupleResponse

use of org.bboxdb.network.packages.response.TupleResponse 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

TupleResponse (org.bboxdb.network.packages.response.TupleResponse)5 JoinedTupleResponse (org.bboxdb.network.packages.response.JoinedTupleResponse)4 ByteBuffer (java.nio.ByteBuffer)3 DeletedTuple (org.bboxdb.storage.entity.DeletedTuple)3 JoinedTuple (org.bboxdb.storage.entity.JoinedTuple)3 Tuple (org.bboxdb.storage.entity.Tuple)3 Test (org.junit.Test)3 InputStream (java.io.InputStream)1 List (java.util.List)1 CompressionEnvelopeResponse (org.bboxdb.network.packages.response.CompressionEnvelopeResponse)1 PagedTransferableEntity (org.bboxdb.storage.entity.PagedTransferableEntity)1