Search in sources :

Example 1 with JoinedTupleResponse

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

the class JoinedTupleHandler 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 joined tuple package");
    }
    final JoinedTupleResponse singleTupleResponse = JoinedTupleResponse.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)) {
        resultBuffer.get(sequenceNumber).add(singleTupleResponse.getJoinedTuple());
        // tuple result or a multiple tuple result
        return false;
    }
    // Single tuple is returned
    if (future != null) {
        future.setOperationResult(Arrays.asList(singleTupleResponse.getJoinedTuple()));
        future.fireCompleteEvent();
    }
    return true;
}
Also used : JoinedTupleResponse(org.bboxdb.network.packages.response.JoinedTupleResponse) List(java.util.List)

Example 2 with JoinedTupleResponse

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

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

the class TestNetworkClasses method encodeAndDecodeJoinedTuple.

/**
 * Test the decoding and the encoding of a joined tuple
 * @throws PackageEncodeException
 * @throws IOException
 */
@Test(timeout = 60000)
public void encodeAndDecodeJoinedTuple() throws IOException, PackageEncodeException {
    final Tuple tuple1 = new Tuple("key1", new BoundingBox(1.3244343224, 232.232333343, 34324.343, 343243.0), "abc".getBytes(), 12);
    final Tuple tuple2 = new Tuple("key2", new BoundingBox(1.32443453224, 545334.03, 34324.343, 343243.0), "abc".getBytes(), 12);
    final Tuple tuple3 = new Tuple("key3", new BoundingBox(1.35433224, 5453.43, 34324.343, 343243.0), "abc".getBytes(), 12);
    final short sequenceNumber = sequenceNumberGenerator.getNextSequenceNummber();
    final List<Tuple> tupleList = Arrays.asList(tuple1, tuple2, tuple3);
    final List<String> tableNames = Arrays.asList("abc", "def", "geh");
    final JoinedTuple joinedTuple = new JoinedTuple(tupleList, tableNames);
    final JoinedTupleResponse joinedResponse = new JoinedTupleResponse(sequenceNumber, joinedTuple);
    byte[] encodedVersion = networkPackageToByte(joinedResponse);
    Assert.assertNotNull(encodedVersion);
    final ByteBuffer bb = NetworkPackageDecoder.encapsulateBytes(encodedVersion);
    final JoinedTupleResponse decodedPackage = JoinedTupleResponse.decodePackage(bb);
    final JoinedTuple decodedJoinedTuple = decodedPackage.getJoinedTuple();
    Assert.assertEquals(3, decodedJoinedTuple.getNumberOfTuples());
    for (int i = 0; i < 3; i++) {
        Assert.assertEquals(tupleList.get(i), decodedJoinedTuple.getTuple(i));
        Assert.assertEquals(tableNames.get(i), decodedJoinedTuple.getTupleStoreName(i));
    }
    Assert.assertTrue(joinedResponse.toString().length() > 10);
}
Also used : BoundingBox(org.bboxdb.commons.math.BoundingBox) JoinedTuple(org.bboxdb.storage.entity.JoinedTuple) JoinedTupleResponse(org.bboxdb.network.packages.response.JoinedTupleResponse) 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

JoinedTupleResponse (org.bboxdb.network.packages.response.JoinedTupleResponse)3 ByteBuffer (java.nio.ByteBuffer)1 List (java.util.List)1 BoundingBox (org.bboxdb.commons.math.BoundingBox)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 Test (org.junit.Test)1