Search in sources :

Example 51 with PackageEncodeException

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

the class HelloResponse method writeToOutputStream.

@Override
public long writeToOutputStream(final OutputStream outputStream) throws PackageEncodeException {
    try {
        final ByteBuffer bb = DataEncoderHelper.intToByteBuffer(protocolVersion);
        final byte[] peerCapabilitiesBytes = peerCapabilities.toByteArray();
        // Body length
        final long bodyLength = bb.capacity() + peerCapabilitiesBytes.length;
        final long headerLength = appendResponsePackageHeader(bodyLength, outputStream);
        // Write body
        outputStream.write(bb.array());
        outputStream.write(peerCapabilitiesBytes);
        return headerLength + bodyLength;
    } catch (Exception e) {
        throw new PackageEncodeException("Got exception while converting package into bytes", e);
    }
}
Also used : PackageEncodeException(org.bboxdb.network.packages.PackageEncodeException) ByteBuffer(java.nio.ByteBuffer) PackageEncodeException(org.bboxdb.network.packages.PackageEncodeException)

Example 52 with PackageEncodeException

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

the class ListTablesResponse method writeToOutputStream.

@Override
public long writeToOutputStream(final OutputStream outputStream) throws PackageEncodeException {
    try {
        final byte[] bodyBytes = createBody();
        final long headerLength = appendResponsePackageHeader(bodyBytes.length, outputStream);
        outputStream.write(bodyBytes);
        return headerLength + bodyBytes.length;
    } 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)

Example 53 with PackageEncodeException

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

the class TupleResponse method writeToOutputStream.

@Override
public long writeToOutputStream(final OutputStream outputStream) throws PackageEncodeException {
    try {
        final byte[] encodedBytes = NetworkTupleEncoderDecoder.encode(tuple, table);
        final long headerLength = appendResponsePackageHeader(encodedBytes.length, outputStream);
        outputStream.write(encodedBytes);
        return headerLength + encodedBytes.length;
    } 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)

Example 54 with PackageEncodeException

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

the class ResponseHandlerHelper method castAndSetFutureResult.

/**
 * Cast the content on the result list according to the future type
 * @param future
 * @param resultList
 * @param completeResult
 * @throws PackageEncodeException
 */
public static void castAndSetFutureResult(final NetworkOperationFuture future, final List<PagedTransferableEntity> resultList, final boolean completeResult) throws PackageEncodeException {
    if (resultList.isEmpty()) {
        future.setCompleteResult(completeResult);
        future.setOperationResult(new ArrayList<>());
        future.fireCompleteEvent();
        return;
    }
    final PagedTransferableEntity firstElement = resultList.get(0);
    if (firstElement instanceof Tuple) {
        final List<Tuple> tupleList = new ArrayList<>();
        for (final PagedTransferableEntity entity : resultList) {
            tupleList.add((Tuple) entity);
        }
        future.setCompleteResult(completeResult);
        future.setOperationResult(tupleList);
        future.fireCompleteEvent();
    } else if (firstElement instanceof JoinedTuple) {
        final List<JoinedTuple> tupleList = new ArrayList<>();
        for (final PagedTransferableEntity entity : resultList) {
            tupleList.add((JoinedTuple) entity);
        }
        future.setCompleteResult(completeResult);
        future.setOperationResult(tupleList);
        future.fireCompleteEvent();
    } else {
        throw new PackageEncodeException("Unknown future type: " + firstElement);
    }
}
Also used : PagedTransferableEntity(org.bboxdb.storage.entity.PagedTransferableEntity) ArrayList(java.util.ArrayList) JoinedTuple(org.bboxdb.storage.entity.JoinedTuple) PackageEncodeException(org.bboxdb.network.packages.PackageEncodeException) List(java.util.List) ArrayList(java.util.ArrayList) JoinedTuple(org.bboxdb.storage.entity.JoinedTuple) Tuple(org.bboxdb.storage.entity.Tuple)

Example 55 with PackageEncodeException

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

the class CancelQueryRequest method writeToOutputStream.

@Override
public long writeToOutputStream(final OutputStream outputStream) throws PackageEncodeException {
    try {
        final ByteBuffer bb = ByteBuffer.allocate(2);
        bb.order(Const.APPLICATION_BYTE_ORDER);
        bb.putShort((short) querySequenceNumber);
        // Calculate body length
        final long bodyLength = bb.capacity();
        final long headerLength = appendRequestPackageHeader(bodyLength, outputStream);
        // Write body
        outputStream.write(bb.array());
        return headerLength + bodyLength;
    } catch (Exception e) {
        throw new PackageEncodeException("Got exception while converting package into bytes", e);
    }
}
Also used : PackageEncodeException(org.bboxdb.network.packages.PackageEncodeException) ByteBuffer(java.nio.ByteBuffer) PackageEncodeException(org.bboxdb.network.packages.PackageEncodeException)

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