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