Search in sources :

Example 1 with RoutingHeader

use of org.bboxdb.network.routing.RoutingHeader in project bboxdb by jnidzwetzki.

the class ClientConnectionHandler method readNextPackageHeader.

/**
 * Read the next package header from the socket
 * @return The package header, wrapped in a ByteBuffer
 * @throws IOException
 * @throws PackageEncodeException
 */
protected ByteBuffer readNextPackageHeader(final InputStream inputStream) throws IOException, PackageEncodeException {
    final ByteBuffer bb = ByteBuffer.allocate(12);
    ByteStreams.readFully(inputStream, bb.array(), 0, bb.limit());
    final RoutingHeader routingHeader = RoutingHeaderParser.decodeRoutingHeader(inputStream);
    final byte[] routingHeaderBytes = RoutingHeaderParser.encodeHeader(routingHeader);
    final ByteBuffer header = ByteBuffer.allocate(bb.limit() + routingHeaderBytes.length);
    header.put(bb.array());
    header.put(routingHeaderBytes);
    return header;
}
Also used : RoutingHeader(org.bboxdb.network.routing.RoutingHeader) ByteBuffer(java.nio.ByteBuffer)

Example 2 with RoutingHeader

use of org.bboxdb.network.routing.RoutingHeader in project bboxdb by jnidzwetzki.

the class QueryBoundingBoxContinuousRequest method decodeTuple.

/**
 * Decode the encoded package into a object
 *
 * @param encodedPackage
 * @return
 * @throws PackageEncodeException
 * @throws IOException
 */
public static QueryBoundingBoxContinuousRequest decodeTuple(final ByteBuffer encodedPackage) throws PackageEncodeException, IOException {
    final short sequenceNumber = NetworkPackageDecoder.getRequestIDFromRequestPackage(encodedPackage);
    final boolean decodeResult = NetworkPackageDecoder.validateRequestPackageHeader(encodedPackage, NetworkConst.REQUEST_TYPE_QUERY);
    if (decodeResult == false) {
        throw new PackageEncodeException("Unable to decode package");
    }
    final byte queryType = encodedPackage.get();
    if (queryType != NetworkConst.REQUEST_QUERY_CONTINUOUS_BBOX) {
        throw new PackageEncodeException("Wrong query type: " + queryType + " required type is: " + NetworkConst.REQUEST_QUERY_CONTINUOUS_BBOX);
    }
    // 1 unused byte
    encodedPackage.get();
    final short tableLength = encodedPackage.getShort();
    final int bboxLength = encodedPackage.getInt();
    final byte[] tableBytes = new byte[tableLength];
    encodedPackage.get(tableBytes, 0, tableBytes.length);
    final String table = new String(tableBytes);
    final byte[] bboxBytes = new byte[bboxLength];
    encodedPackage.get(bboxBytes, 0, bboxBytes.length);
    final BoundingBox boundingBox = BoundingBox.fromByteArray(bboxBytes);
    if (encodedPackage.remaining() != 0) {
        throw new PackageEncodeException("Some bytes are left after decoding: " + encodedPackage.remaining());
    }
    final RoutingHeader routingHeader = NetworkPackageDecoder.getRoutingHeaderFromRequestPackage(encodedPackage);
    return new QueryBoundingBoxContinuousRequest(sequenceNumber, routingHeader, table, boundingBox);
}
Also used : BoundingBox(org.bboxdb.commons.math.BoundingBox) PackageEncodeException(org.bboxdb.network.packages.PackageEncodeException) RoutingHeader(org.bboxdb.network.routing.RoutingHeader)

Example 3 with RoutingHeader

use of org.bboxdb.network.routing.RoutingHeader in project bboxdb by jnidzwetzki.

the class QueryBoundingBoxTimeRequest method decodeTuple.

/**
 * Decode the encoded package into a object
 *
 * @param encodedPackage
 * @return
 * @throws PackageEncodeException
 * @throws IOException
 */
public static QueryBoundingBoxTimeRequest decodeTuple(final ByteBuffer encodedPackage) throws PackageEncodeException, IOException {
    final short sequenceNumber = NetworkPackageDecoder.getRequestIDFromRequestPackage(encodedPackage);
    final boolean decodeResult = NetworkPackageDecoder.validateRequestPackageHeader(encodedPackage, NetworkConst.REQUEST_TYPE_QUERY);
    if (decodeResult == false) {
        throw new PackageEncodeException("Unable to decode package");
    }
    final byte queryType = encodedPackage.get();
    if (queryType != NetworkConst.REQUEST_QUERY_BBOX_AND_TIME) {
        throw new PackageEncodeException("Wrong query type: " + queryType + " required type is: " + NetworkConst.REQUEST_QUERY_BBOX_AND_TIME);
    }
    boolean pagingEnabled = false;
    if (encodedPackage.get() != 0) {
        pagingEnabled = true;
    }
    final short tuplesPerPage = encodedPackage.getShort();
    final short tableLength = encodedPackage.getShort();
    // 2 unused bytes
    encodedPackage.get();
    encodedPackage.get();
    final int bboxLength = encodedPackage.getInt();
    final long timestamp = encodedPackage.getLong();
    final byte[] tableBytes = new byte[tableLength];
    encodedPackage.get(tableBytes, 0, tableBytes.length);
    final String table = new String(tableBytes);
    final byte[] bboxBytes = new byte[bboxLength];
    encodedPackage.get(bboxBytes, 0, bboxBytes.length);
    final BoundingBox boundingBox = BoundingBox.fromByteArray(bboxBytes);
    if (encodedPackage.remaining() != 0) {
        throw new PackageEncodeException("Some bytes are left after decoding: " + encodedPackage.remaining());
    }
    final RoutingHeader routingHeader = NetworkPackageDecoder.getRoutingHeaderFromRequestPackage(encodedPackage);
    return new QueryBoundingBoxTimeRequest(sequenceNumber, routingHeader, table, boundingBox, timestamp, pagingEnabled, tuplesPerPage);
}
Also used : BoundingBox(org.bboxdb.commons.math.BoundingBox) PackageEncodeException(org.bboxdb.network.packages.PackageEncodeException) RoutingHeader(org.bboxdb.network.routing.RoutingHeader)

Example 4 with RoutingHeader

use of org.bboxdb.network.routing.RoutingHeader in project bboxdb by jnidzwetzki.

the class QueryKeyRequest method decodeTuple.

/**
 * Decode the encoded package into a object
 *
 * @param encodedPackage
 * @return
 * @throws PackageEncodeException
 * @throws IOException
 */
public static QueryKeyRequest decodeTuple(final ByteBuffer encodedPackage) throws PackageEncodeException, IOException {
    final short sequenceNumber = NetworkPackageDecoder.getRequestIDFromRequestPackage(encodedPackage);
    final boolean decodeResult = NetworkPackageDecoder.validateRequestPackageHeader(encodedPackage, NetworkConst.REQUEST_TYPE_QUERY);
    if (decodeResult == false) {
        throw new PackageEncodeException("Unable to decode package");
    }
    final byte queryType = encodedPackage.get();
    if (queryType != NetworkConst.REQUEST_QUERY_KEY) {
        throw new PackageEncodeException("Wrong query type: " + queryType);
    }
    boolean pagingEnabled = false;
    if (encodedPackage.get() != 0) {
        pagingEnabled = true;
    }
    final short tuplesPerPage = encodedPackage.getShort();
    final short tableLength = encodedPackage.getShort();
    final short keyLength = encodedPackage.getShort();
    final byte[] tableBytes = new byte[tableLength];
    encodedPackage.get(tableBytes, 0, tableBytes.length);
    final String table = new String(tableBytes);
    final byte[] keyBytes = new byte[keyLength];
    encodedPackage.get(keyBytes, 0, keyBytes.length);
    final String key = new String(keyBytes);
    if (encodedPackage.remaining() != 0) {
        throw new PackageEncodeException("Some bytes are left after decoding: " + encodedPackage.remaining());
    }
    final RoutingHeader routingHeader = NetworkPackageDecoder.getRoutingHeaderFromRequestPackage(encodedPackage);
    return new QueryKeyRequest(sequenceNumber, routingHeader, table, key, pagingEnabled, tuplesPerPage);
}
Also used : PackageEncodeException(org.bboxdb.network.packages.PackageEncodeException) RoutingHeader(org.bboxdb.network.routing.RoutingHeader)

Example 5 with RoutingHeader

use of org.bboxdb.network.routing.RoutingHeader in project bboxdb by jnidzwetzki.

the class LockTupleRequest method decodeTuple.

/**
 * Decode the encoded package into a object
 *
 * @param encodedPackage
 * @return
 * @throws PackageEncodeException
 * @throws IOException
 */
public static LockTupleRequest decodeTuple(final ByteBuffer encodedPackage) throws PackageEncodeException, IOException {
    final short sequenceNumber = NetworkPackageDecoder.getRequestIDFromRequestPackage(encodedPackage);
    final boolean decodeResult = NetworkPackageDecoder.validateRequestPackageHeader(encodedPackage, NetworkConst.REQUEST_TYPE_LOCK_TUPLE);
    if (decodeResult == false) {
        throw new PackageEncodeException("Unable to decode package");
    }
    final short tablenameLength = encodedPackage.getShort();
    final short keyLength = encodedPackage.getShort();
    final long version = encodedPackage.getLong();
    // Tablename
    final byte[] tableBytes = new byte[tablenameLength];
    encodedPackage.get(tableBytes, 0, tableBytes.length);
    final String tablename = new String(tableBytes);
    // Key
    final byte[] keyBytes = new byte[keyLength];
    encodedPackage.get(keyBytes, 0, keyBytes.length);
    final String key = new String(keyBytes);
    if (encodedPackage.remaining() != 0) {
        throw new PackageEncodeException("Some bytes are left after decoding: " + encodedPackage.remaining());
    }
    final RoutingHeader routingHeader = NetworkPackageDecoder.getRoutingHeaderFromRequestPackage(encodedPackage);
    return new LockTupleRequest(sequenceNumber, routingHeader, tablename, key, version);
}
Also used : PackageEncodeException(org.bboxdb.network.packages.PackageEncodeException) RoutingHeader(org.bboxdb.network.routing.RoutingHeader)

Aggregations

RoutingHeader (org.bboxdb.network.routing.RoutingHeader)52 Test (org.junit.Test)18 NetworkOperationFuture (org.bboxdb.network.client.future.NetworkOperationFuture)16 RoutingHop (org.bboxdb.network.routing.RoutingHop)15 ArrayList (java.util.ArrayList)12 JoinedTupleListFuture (org.bboxdb.network.client.future.JoinedTupleListFuture)12 BBoxDBInstance (org.bboxdb.distribution.membership.BBoxDBInstance)11 PackageEncodeException (org.bboxdb.network.packages.PackageEncodeException)11 Tuple (org.bboxdb.storage.entity.Tuple)11 TupleStoreName (org.bboxdb.storage.entity.TupleStoreName)11 List (java.util.List)10 DistributionRegion (org.bboxdb.distribution.region.DistributionRegion)10 TupleListFuture (org.bboxdb.network.client.future.TupleListFuture)10 ByteBuffer (java.nio.ByteBuffer)9 InsertTupleRequest (org.bboxdb.network.packages.request.InsertTupleRequest)9 DeletedTuple (org.bboxdb.storage.entity.DeletedTuple)9 DoNothingDuplicateResolver (org.bboxdb.storage.sstable.duplicateresolver.DoNothingDuplicateResolver)8 BoundingBox (org.bboxdb.commons.math.BoundingBox)6 BBoxDBException (org.bboxdb.misc.BBoxDBException)6 JoinedTuple (org.bboxdb.storage.entity.JoinedTuple)6