use of org.bboxdb.network.packages.request.InsertTupleRequest in project bboxdb by jnidzwetzki.
the class TestNetworkClasses method encodeAndDecodeInsertTuple1.
/**
* The the encoding and decoding of an insert tuple package
* @throws IOException
* @throws PackageEncodeException
*/
@Test(timeout = 60000)
public void encodeAndDecodeInsertTuple1() throws IOException, PackageEncodeException {
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_UNROUTED, new TupleStoreName("test"), tuple);
byte[] encodedVersion = networkPackageToByte(insertPackage);
Assert.assertNotNull(encodedVersion);
final ByteBuffer bb = NetworkPackageDecoder.encapsulateBytes(encodedVersion);
final InsertTupleRequest decodedPackage = InsertTupleRequest.decodeTuple(bb);
Assert.assertEquals(insertPackage.getTuple(), decodedPackage.getTuple());
Assert.assertEquals(insertPackage.getTable(), decodedPackage.getTable());
Assert.assertEquals(insertPackage.getRoutingHeader(), 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.InsertTupleRequest in project bboxdb by jnidzwetzki.
the class TestCompressionRatio method handleUncompressedData.
/**
* Handle the uncompressed version
* @param tableName
* @return
*/
protected long handleUncompressedData(final TupleStoreName tableName, final Tuple tuple) {
final RoutingHeader routingHeader = new RoutingHeader(false);
final InsertTupleRequest insertTupleRequest = new InsertTupleRequest((short) 4, routingHeader, tableName, tuple);
return packageToBytes(insertTupleRequest);
}
use of org.bboxdb.network.packages.request.InsertTupleRequest in project bboxdb by jnidzwetzki.
the class InsertTupleHandler method handleRequest.
@Override
public /**
* Handle the insert tuple request
*/
boolean handleRequest(final ByteBuffer encodedPackage, final short packageSequence, final ClientConnectionHandler clientConnectionHandler) throws IOException, PackageEncodeException {
if (logger.isDebugEnabled()) {
logger.debug("Got insert tuple request");
}
try {
final InsertTupleRequest insertTupleRequest = InsertTupleRequest.decodeTuple(encodedPackage);
final RoutingHeader routingHeader = insertTupleRequest.getRoutingHeader();
if (!routingHeader.isRoutedPackage()) {
final String errorMessage = "Error while inserting tuple - package is not routed";
logger.error(errorMessage);
final ErrorResponse responsePackage = new ErrorResponse(packageSequence, errorMessage);
clientConnectionHandler.writeResultPackage(responsePackage);
return true;
}
// Needs to be rerouted?
if (routingHeader.getHop() == -1) {
routingHeader.dispatchToNextHop();
final RoutingHop localHop = routingHeader.getRoutingHop();
if (PackageRouter.checkLocalSystemNameMatches(localHop)) {
processPackageLocally(packageSequence, clientConnectionHandler, insertTupleRequest);
} else {
logger.debug("Rerouting package {}", packageSequence);
forwardRoutedPackage(packageSequence, clientConnectionHandler, insertTupleRequest);
}
} else {
processPackageLocally(packageSequence, clientConnectionHandler, insertTupleRequest);
}
} catch (RejectedException e) {
final ErrorResponse responsePackage = new ErrorResponse(packageSequence, ErrorMessages.ERROR_LOCAL_OPERATION_REJECTED_RETRY + " " + e.getMessage());
clientConnectionHandler.writeResultPackage(responsePackage);
} catch (Throwable e) {
logger.error("Error while inserting tuple", e);
final ErrorResponse responsePackage = new ErrorResponse(packageSequence, ErrorMessages.ERROR_EXCEPTION);
clientConnectionHandler.writeResultPackage(responsePackage);
}
return true;
}
Aggregations