/** * 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; }
/** * Helper for serializing the messages. * * @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 messageType The {@link MessageType type of the message}. * @param payload The serialized version of the message. * @return A {@link ByteBuf} containing the serialized message. */ private static ByteBuf writePayload( final ByteBufAllocator alloc, final long requestId, final MessageType messageType, final byte[] payload) { final int frameLength = HEADER_LENGTH + REQUEST_ID_SIZE + payload.length; final ByteBuf buf = alloc.ioBuffer(frameLength + Integer.BYTES); buf.writeInt(frameLength); writeHeader(buf, messageType); buf.writeLong(requestId); buf.writeBytes(payload); return buf; }
/** * 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; }
/** * 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; }
/** * 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; }
/** * 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; }
/** * Helper for serializing the messages. * * @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 messageType The {@link MessageType type of the message}. * @param payload The serialized version of the message. * @return A {@link ByteBuf} containing the serialized message. */ private static ByteBuf writePayload( final ByteBufAllocator alloc, final long requestId, final MessageType messageType, final byte[] payload) { final int frameLength = HEADER_LENGTH + REQUEST_ID_SIZE + payload.length; final ByteBuf buf = alloc.ioBuffer(frameLength + Integer.BYTES); buf.writeInt(frameLength); writeHeader(buf, messageType); buf.writeLong(requestId); buf.writeBytes(payload); return buf; }
/** * 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; }
/** * Helper for serializing the messages. * * @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 messageType The {@link MessageType type of the message}. * @param payload The serialized version of the message. * @return A {@link ByteBuf} containing the serialized message. */ private static ByteBuf writePayload( final ByteBufAllocator alloc, final long requestId, final MessageType messageType, final byte[] payload) { final int frameLength = HEADER_LENGTH + REQUEST_ID_SIZE + payload.length; final ByteBuf buf = alloc.ioBuffer(frameLength + Integer.BYTES); buf.writeInt(frameLength); writeHeader(buf, messageType); buf.writeLong(requestId); buf.writeBytes(payload); return buf; }