Search in sources :

Example 11 with InsertTupleRequest

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);
}
Also used : RoutingHeader(org.bboxdb.network.routing.RoutingHeader) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) ByteBuffer(java.nio.ByteBuffer) JoinedTuple(org.bboxdb.storage.entity.JoinedTuple) Tuple(org.bboxdb.storage.entity.Tuple) DeletedTuple(org.bboxdb.storage.entity.DeletedTuple) InsertTupleRequest(org.bboxdb.network.packages.request.InsertTupleRequest) Test(org.junit.Test)

Example 12 with InsertTupleRequest

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);
}
Also used : RoutingHeader(org.bboxdb.network.routing.RoutingHeader) InsertTupleRequest(org.bboxdb.network.packages.request.InsertTupleRequest)

Example 13 with 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;
}
Also used : RejectedException(org.bboxdb.commons.RejectedException) RoutingHeader(org.bboxdb.network.routing.RoutingHeader) RoutingHop(org.bboxdb.network.routing.RoutingHop) InsertTupleRequest(org.bboxdb.network.packages.request.InsertTupleRequest) ErrorResponse(org.bboxdb.network.packages.response.ErrorResponse)

Aggregations

InsertTupleRequest (org.bboxdb.network.packages.request.InsertTupleRequest)13 TupleStoreName (org.bboxdb.storage.entity.TupleStoreName)11 Tuple (org.bboxdb.storage.entity.Tuple)10 ByteBuffer (java.nio.ByteBuffer)9 RoutingHeader (org.bboxdb.network.routing.RoutingHeader)9 DeletedTuple (org.bboxdb.storage.entity.DeletedTuple)9 JoinedTuple (org.bboxdb.storage.entity.JoinedTuple)9 Test (org.junit.Test)9 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 CompressionEnvelopeRequest (org.bboxdb.network.packages.request.CompressionEnvelopeRequest)3 InputStream (java.io.InputStream)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Objects (java.util.Objects)1 Collectors (java.util.stream.Collectors)1 RejectedException (org.bboxdb.commons.RejectedException)1 BoundingBox (org.bboxdb.commons.math.BoundingBox)1 NetworkConst (org.bboxdb.network.NetworkConst)1