Search in sources :

Example 1 with Errors

use of org.apache.flink.shaded.netty4.io.netty.channel.unix.Errors in project flink by apache.

the class MessageSerializer method deserializeRequestFailure.

/**
 * De-serializes the {@link RequestFailure} sent to the {@link
 * org.apache.flink.queryablestate.network.Client} in case of protocol related errors.
 *
 * <pre>
 *  <b>The buffer is expected to be at the correct position.</b>
 * </pre>
 *
 * @param buf The {@link ByteBuf} containing the serialized failure message.
 * @return The failure message.
 */
public static RequestFailure deserializeRequestFailure(final ByteBuf buf) throws IOException, ClassNotFoundException {
    long requestId = buf.readLong();
    Throwable cause;
    try (ByteBufInputStream bis = new ByteBufInputStream(buf);
        ObjectInputStream in = new ObjectInputStream(bis)) {
        cause = (Throwable) in.readObject();
    }
    return new RequestFailure(requestId, cause);
}
Also used : ByteBufInputStream(org.apache.flink.shaded.netty4.io.netty.buffer.ByteBufInputStream) ObjectInputStream(java.io.ObjectInputStream)

Example 2 with Errors

use of org.apache.flink.shaded.netty4.io.netty.channel.unix.Errors in project flink by apache.

the class MessageSerializer method serializeRequestFailure.

/**
 * Serializes the exception containing the failure message sent to the {@link
 * org.apache.flink.queryablestate.network.Client} in case of protocol related errors.
 *
 * @param alloc The {@link ByteBufAllocator} used to allocate the buffer to serialize the
 *     message into.
 * @param requestId The id of the request to which the message refers to.
 * @param cause The exception thrown at the server.
 * @return A {@link ByteBuf} containing the serialized message.
 */
public static ByteBuf serializeRequestFailure(final ByteBufAllocator alloc, final long requestId, final Throwable cause) throws IOException {
    final ByteBuf buf = alloc.ioBuffer();
    // Frame length is set at the end
    buf.writeInt(0);
    writeHeader(buf, MessageType.REQUEST_FAILURE);
    buf.writeLong(requestId);
    try (ByteBufOutputStream bbos = new ByteBufOutputStream(buf);
        ObjectOutput out = new ObjectOutputStream(bbos)) {
        out.writeObject(cause);
    }
    // Set frame length
    int frameLength = buf.readableBytes() - Integer.BYTES;
    buf.setInt(0, frameLength);
    return buf;
}
Also used : ByteBufOutputStream(org.apache.flink.shaded.netty4.io.netty.buffer.ByteBufOutputStream) ObjectOutput(java.io.ObjectOutput) ByteBuf(org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf) ObjectOutputStream(java.io.ObjectOutputStream)

Example 3 with Errors

use of org.apache.flink.shaded.netty4.io.netty.channel.unix.Errors in project flink by apache.

the class MessageSerializer method serializeServerFailure.

/**
 * Serializes the failure message sent to the {@link
 * org.apache.flink.queryablestate.network.Client} in case of server related errors.
 *
 * @param alloc The {@link ByteBufAllocator} used to allocate the buffer to serialize the
 *     message into.
 * @param cause The exception thrown at the server.
 * @return The failure message.
 */
public static ByteBuf serializeServerFailure(final ByteBufAllocator alloc, final Throwable cause) throws IOException {
    final ByteBuf buf = alloc.ioBuffer();
    // Frame length is set at end
    buf.writeInt(0);
    writeHeader(buf, MessageType.SERVER_FAILURE);
    try (ByteBufOutputStream bbos = new ByteBufOutputStream(buf);
        ObjectOutput out = new ObjectOutputStream(bbos)) {
        out.writeObject(cause);
    }
    // Set frame length
    int frameLength = buf.readableBytes() - Integer.BYTES;
    buf.setInt(0, frameLength);
    return buf;
}
Also used : ByteBufOutputStream(org.apache.flink.shaded.netty4.io.netty.buffer.ByteBufOutputStream) ObjectOutput(java.io.ObjectOutput) ByteBuf(org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf) ObjectOutputStream(java.io.ObjectOutputStream)

Aggregations

ObjectOutput (java.io.ObjectOutput)2 ObjectOutputStream (java.io.ObjectOutputStream)2 ByteBuf (org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf)2 ByteBufOutputStream (org.apache.flink.shaded.netty4.io.netty.buffer.ByteBufOutputStream)2 ObjectInputStream (java.io.ObjectInputStream)1 ByteBufInputStream (org.apache.flink.shaded.netty4.io.netty.buffer.ByteBufInputStream)1