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