Search in sources :

Example 1 with IStreamResponse

use of com.tencent.angel.ps.server.data.response.IStreamResponse in project angel by Tencent.

the class ByteBufUtils method serializeResponse.

public static ByteBuf serializeResponse(Response response, boolean useDirectorBuffer) {
    ResponseData data = response.getData();
    // If is stream response, just return bytebuf
    if (data != null && (data instanceof IStreamResponse) && (((IStreamResponse) data).getOutputBuffer() != null)) {
        return ((IStreamResponse) data).getOutputBuffer();
    }
    ByteBuf buf = null;
    try {
        buf = allocResultBuf(response, useDirectorBuffer);
        response.serialize(buf);
    } catch (Throwable x) {
        LOG.error("serialize response failed ", x);
        if (buf != null) {
            buf.release();
        }
        if (response.getResponseType() == ResponseType.SUCCESS) {
            // Reset the response and allocate buffer again
            response.setResponseType(ResponseType.SERVER_IS_BUSY);
            response.setDetail("can not serialize the response");
            // Release response data
            response.setData(null);
            buf = allocResultBuf(response, useDirectorBuffer);
            response.serialize(buf);
        } else {
            throw x;
        }
    }
    return buf;
}
Also used : ResponseData(com.tencent.angel.ps.server.data.response.ResponseData) ByteBuf(io.netty.buffer.ByteBuf) IStreamResponse(com.tencent.angel.ps.server.data.response.IStreamResponse)

Aggregations

IStreamResponse (com.tencent.angel.ps.server.data.response.IStreamResponse)1 ResponseData (com.tencent.angel.ps.server.data.response.ResponseData)1 ByteBuf (io.netty.buffer.ByteBuf)1