Search in sources :

Example 36 with PackageEncodeException

use of org.bboxdb.network.packages.PackageEncodeException in project bboxdb by jnidzwetzki.

the class CreateDistributionGroupRequest method writeToOutputStream.

@Override
public long writeToOutputStream(final OutputStream outputStream) throws PackageEncodeException {
    try {
        final byte[] groupBytes = distributionGroup.getBytes();
        final byte[] placementBytes = distributionGroupConfiguration.getPlacementStrategy().getBytes();
        final byte[] placementConfigBytes = distributionGroupConfiguration.getPlacementStrategyConfig().getBytes();
        final byte[] spacePartitionierBytes = distributionGroupConfiguration.getSpacePartitioner().getBytes();
        final byte[] spacePartitionierConfigBytes = distributionGroupConfiguration.getSpacePartitionerConfig().getBytes();
        final ByteBuffer bb = ByteBuffer.allocate(28);
        bb.order(Const.APPLICATION_BYTE_ORDER);
        bb.putInt(distributionGroupConfiguration.getDimensions());
        bb.putShort(distributionGroupConfiguration.getReplicationFactor());
        bb.putShort((short) groupBytes.length);
        bb.putShort((short) placementBytes.length);
        bb.putShort((short) spacePartitionierBytes.length);
        bb.putInt((int) placementConfigBytes.length);
        bb.putInt((int) spacePartitionierConfigBytes.length);
        bb.putInt(distributionGroupConfiguration.getMaximumRegionSize());
        bb.putInt(distributionGroupConfiguration.getMinimumRegionSize());
        // Body length
        final long bodyLength = bb.capacity() + groupBytes.length + placementBytes.length + placementConfigBytes.length + spacePartitionierBytes.length + spacePartitionierConfigBytes.length;
        final long headerLength = appendRequestPackageHeader(bodyLength, outputStream);
        // Write body
        outputStream.write(bb.array());
        outputStream.write(groupBytes);
        outputStream.write(placementBytes);
        outputStream.write(placementConfigBytes);
        outputStream.write(spacePartitionierBytes);
        outputStream.write(spacePartitionierConfigBytes);
        return headerLength + bodyLength;
    } catch (IOException e) {
        throw new PackageEncodeException("Got exception while converting package into bytes", e);
    }
}
Also used : PackageEncodeException(org.bboxdb.network.packages.PackageEncodeException) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer)

Example 37 with PackageEncodeException

use of org.bboxdb.network.packages.PackageEncodeException in project bboxdb by jnidzwetzki.

the class CreateTableRequest method decodeTuple.

/**
 * Decode the encoded package into a object
 *
 * @param encodedPackage
 * @return
 * @throws PackageEncodeException
 */
public static CreateTableRequest decodeTuple(final ByteBuffer encodedPackage) throws PackageEncodeException {
    final short sequenceNumber = NetworkPackageDecoder.getRequestIDFromRequestPackage(encodedPackage);
    final boolean decodeResult = NetworkPackageDecoder.validateRequestPackageHeader(encodedPackage, NetworkConst.REQUEST_TYPE_CREATE_TABLE);
    if (decodeResult == false) {
        throw new PackageEncodeException("Unable to decode package");
    }
    // Table length
    final short tableLength = encodedPackage.getShort();
    // Allow duplicates
    boolean allowDuplicates = false;
    if (encodedPackage.get() != 0) {
        allowDuplicates = true;
    }
    // Unused
    encodedPackage.get();
    // TTL
    final long ttl = encodedPackage.getLong();
    // Versions
    final int versions = encodedPackage.getInt();
    // Spatial reader length
    final short spatialReaderLength = encodedPackage.getShort();
    // Spatial writer length
    final short spatialWriterLength = encodedPackage.getShort();
    // Table name
    final byte[] tableBytes = new byte[tableLength];
    encodedPackage.get(tableBytes, 0, tableBytes.length);
    final String table = new String(tableBytes);
    // Spatial index reader
    final byte[] spatialReaderBytes = new byte[spatialReaderLength];
    encodedPackage.get(spatialReaderBytes, 0, spatialReaderBytes.length);
    final String spatialIndexReader = new String(spatialReaderBytes);
    // Spatial index writer
    final byte[] spatialWriterBytes = new byte[spatialWriterLength];
    encodedPackage.get(spatialWriterBytes, 0, spatialWriterBytes.length);
    final String spatialIndexWriter = new String(spatialWriterBytes);
    final TupleStoreConfiguration tupleStoreConfiguration = new TupleStoreConfiguration();
    tupleStoreConfiguration.setAllowDuplicates(allowDuplicates);
    tupleStoreConfiguration.setTtl(ttl);
    tupleStoreConfiguration.setVersions(versions);
    tupleStoreConfiguration.setSpatialIndexReader(spatialIndexReader);
    tupleStoreConfiguration.setSpatialIndexWriter(spatialIndexWriter);
    if (encodedPackage.remaining() != 0) {
        throw new PackageEncodeException("Some bytes are left after decoding: " + encodedPackage.remaining());
    }
    return new CreateTableRequest(sequenceNumber, table, tupleStoreConfiguration);
}
Also used : TupleStoreConfiguration(org.bboxdb.storage.entity.TupleStoreConfiguration) PackageEncodeException(org.bboxdb.network.packages.PackageEncodeException)

Example 38 with PackageEncodeException

use of org.bboxdb.network.packages.PackageEncodeException in project bboxdb by jnidzwetzki.

the class CreateTableRequest method writeToOutputStream.

@Override
public long writeToOutputStream(final OutputStream outputStream) throws PackageEncodeException {
    try {
        final byte[] tableBytes = table.getFullnameBytes();
        final ByteBuffer bb = ByteBuffer.allocate(20);
        bb.putShort((short) tableBytes.length);
        if (ssTableConfiguration.isAllowDuplicates()) {
            bb.put((byte) 0x01);
        } else {
            bb.put((byte) 0x00);
        }
        // Unused
        bb.put((byte) 0x00);
        // TTL
        bb.putLong(ssTableConfiguration.getTTL());
        // Versions
        bb.putInt(ssTableConfiguration.getVersions());
        // Spatial index reader
        final byte[] spatialIndexReaderBytes = ssTableConfiguration.getSpatialIndexReader().getBytes();
        bb.putShort((short) spatialIndexReaderBytes.length);
        // Spatial index writer
        final byte[] spatialIndexWriterBytes = ssTableConfiguration.getSpatialIndexWriter().getBytes();
        bb.putShort((short) spatialIndexWriterBytes.length);
        // Body length
        final long bodyLength = bb.capacity() + tableBytes.length + spatialIndexReaderBytes.length + spatialIndexWriterBytes.length;
        final long headerLength = appendRequestPackageHeader(bodyLength, outputStream);
        // Write body
        outputStream.write(bb.array());
        outputStream.write(tableBytes);
        outputStream.write(spatialIndexReaderBytes);
        outputStream.write(spatialIndexWriterBytes);
        return headerLength + bodyLength;
    } catch (IOException e) {
        throw new PackageEncodeException("Got exception while converting package into bytes", e);
    }
}
Also used : PackageEncodeException(org.bboxdb.network.packages.PackageEncodeException) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer)

Example 39 with PackageEncodeException

use of org.bboxdb.network.packages.PackageEncodeException in project bboxdb by jnidzwetzki.

the class DeleteDistributionGroupRequest method writeToOutputStream.

@Override
public long writeToOutputStream(final OutputStream outputStream) throws PackageEncodeException {
    try {
        final byte[] groupBytes = distributionGroup.getBytes();
        final ByteBuffer bb = DataEncoderHelper.shortToByteBuffer((short) groupBytes.length);
        // Body length
        final long bodyLength = bb.capacity() + groupBytes.length;
        final long headerLength = appendRequestPackageHeader(bodyLength, outputStream);
        // Write body
        outputStream.write(bb.array());
        outputStream.write(groupBytes);
        return headerLength + bodyLength;
    } catch (IOException e) {
        throw new PackageEncodeException("Got exception while converting package into bytes", e);
    }
}
Also used : PackageEncodeException(org.bboxdb.network.packages.PackageEncodeException) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer)

Example 40 with PackageEncodeException

use of org.bboxdb.network.packages.PackageEncodeException in project bboxdb by jnidzwetzki.

the class DeleteTableRequest method writeToOutputStream.

@Override
public long writeToOutputStream(final OutputStream outputStream) throws PackageEncodeException {
    try {
        final byte[] tableBytes = table.getFullnameBytes();
        final ByteBuffer bb = DataEncoderHelper.shortToByteBuffer((short) tableBytes.length);
        // Body length
        final long bodyLength = bb.capacity() + tableBytes.length;
        final long headerLength = appendRequestPackageHeader(bodyLength, outputStream);
        // Write body
        outputStream.write(bb.array());
        outputStream.write(tableBytes);
        return headerLength + bodyLength;
    } catch (IOException e) {
        throw new PackageEncodeException("Got exception while converting package into bytes", e);
    }
}
Also used : PackageEncodeException(org.bboxdb.network.packages.PackageEncodeException) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer)

Aggregations

PackageEncodeException (org.bboxdb.network.packages.PackageEncodeException)68 IOException (java.io.IOException)31 ByteBuffer (java.nio.ByteBuffer)21 ErrorResponse (org.bboxdb.network.packages.response.ErrorResponse)16 TupleStoreName (org.bboxdb.storage.entity.TupleStoreName)14 RoutingHeader (org.bboxdb.network.routing.RoutingHeader)12 ByteArrayOutputStream (java.io.ByteArrayOutputStream)9 ArrayList (java.util.ArrayList)9 BoundingBox (org.bboxdb.commons.math.BoundingBox)9 List (java.util.List)8 SuccessResponse (org.bboxdb.network.packages.response.SuccessResponse)6 Tuple (org.bboxdb.storage.entity.Tuple)6 StreamClientQuery (org.bboxdb.network.server.StreamClientQuery)5 OperatorTreeBuilder (org.bboxdb.storage.queryprocessor.OperatorTreeBuilder)5 NetworkRequestPackage (org.bboxdb.network.packages.NetworkRequestPackage)4 Operator (org.bboxdb.storage.queryprocessor.operator.Operator)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ExceptionSafeRunnable (org.bboxdb.commons.concurrent.ExceptionSafeRunnable)3 CompressionEnvelopeRequest (org.bboxdb.network.packages.request.CompressionEnvelopeRequest)3 ClientQuery (org.bboxdb.network.server.ClientQuery)3