Search in sources :

Example 1 with RequestData

use of com.tencent.angel.ps.server.data.request.RequestData in project angel by Tencent.

the class WorkerPool method handle.

/**
 * Handle rpc
 *
 * @param requestHeader request meta data
 * @param in request data
 * @param ctx netty channel context
 */
private void handle(RequestHeader requestHeader, ByteBuf in, ChannelHandlerContext ctx) {
    ResponseData responseData = null;
    ResponseHeader responseHeader;
    ServerState state = runningContext.getState();
    if (state == ServerState.BUSY) {
        responseHeader = new ResponseHeader(requestHeader.seqId, requestHeader.methodId, ServerState.BUSY, ResponseType.SERVER_IS_BUSY, "server is busy now, retry later");
    } else {
        // Idle, handle the request
        // Parse head success
        Handler handler = methodIdToHandler.get(requestHeader.methodId);
        // Handle request
        if (handler != null) {
            try {
                ByteBufSerdeUtils.deserializeBoolean(in);
                RequestData request = handler.parseRequest(in);
                requestSize.addAndGet(request.requestSize);
                responseData = handler.handle(requestHeader, request);
                requestSize.addAndGet(responseData.bufferLen());
                responseHeader = new ResponseHeader(requestHeader.seqId, requestHeader.methodId, state, ResponseType.SUCCESS);
            } catch (Throwable e) {
                // Handle error, generate response
                responseHeader = new ResponseHeader(requestHeader.seqId, requestHeader.methodId, state, ResponseType.SERVER_HANDLE_FAILED, StringUtils.stringifyException(e));
            }
        } else {
            responseHeader = new ResponseHeader(requestHeader.seqId, requestHeader.methodId, state, ResponseType.UNSUPPORT_REQUEST);
        }
    }
    // Release the input buffer
    ByteBufUtils.releaseBuf(in);
    // Create response
    Response response = new Response(responseHeader, responseData);
    // LOG.info("Response header = " + responseHeader);
    // Serialize the response
    // 2. Serialize the response
    ByteBuf out = ByteBufUtils.serializeResponse(response, context.isUseDirectBuffer());
    // Send the serialized response
    if (out != null) {
        sendResult(requestHeader, ctx, out);
        return;
    } else {
        runningContext.after(requestHeader.clientId, requestHeader.seqId);
        return;
    }
}
Also used : Response(com.tencent.angel.ps.server.data.response.Response) ResponseHeader(com.tencent.angel.ps.server.data.response.ResponseHeader) RequestData(com.tencent.angel.ps.server.data.request.RequestData) ResponseData(com.tencent.angel.ps.server.data.response.ResponseData) GetPartHandler(com.tencent.angel.ps.server.data.handler.GetPartHandler) BasicStreamUpdateHandler(com.tencent.angel.ps.server.data.handler.BasicStreamUpdateHandler) StreamIndexGetRowHandler(com.tencent.angel.ps.server.data.handler.StreamIndexGetRowHandler) IndexGetRowHandler(com.tencent.angel.ps.server.data.handler.IndexGetRowHandler) IndexGetRowsHandler(com.tencent.angel.ps.server.data.handler.IndexGetRowsHandler) GetRowsHandler(com.tencent.angel.ps.server.data.handler.GetRowsHandler) Handler(com.tencent.angel.ps.server.data.handler.Handler) PSFUpdateHandler(com.tencent.angel.ps.server.data.handler.PSFUpdateHandler) PSFGetHandler(com.tencent.angel.ps.server.data.handler.PSFGetHandler) GetRowHandler(com.tencent.angel.ps.server.data.handler.GetRowHandler) StreamIndexGetRowsHandler(com.tencent.angel.ps.server.data.handler.StreamIndexGetRowsHandler) ByteBuf(io.netty.buffer.ByteBuf)

Aggregations

BasicStreamUpdateHandler (com.tencent.angel.ps.server.data.handler.BasicStreamUpdateHandler)1 GetPartHandler (com.tencent.angel.ps.server.data.handler.GetPartHandler)1 GetRowHandler (com.tencent.angel.ps.server.data.handler.GetRowHandler)1 GetRowsHandler (com.tencent.angel.ps.server.data.handler.GetRowsHandler)1 Handler (com.tencent.angel.ps.server.data.handler.Handler)1 IndexGetRowHandler (com.tencent.angel.ps.server.data.handler.IndexGetRowHandler)1 IndexGetRowsHandler (com.tencent.angel.ps.server.data.handler.IndexGetRowsHandler)1 PSFGetHandler (com.tencent.angel.ps.server.data.handler.PSFGetHandler)1 PSFUpdateHandler (com.tencent.angel.ps.server.data.handler.PSFUpdateHandler)1 StreamIndexGetRowHandler (com.tencent.angel.ps.server.data.handler.StreamIndexGetRowHandler)1 StreamIndexGetRowsHandler (com.tencent.angel.ps.server.data.handler.StreamIndexGetRowsHandler)1 RequestData (com.tencent.angel.ps.server.data.request.RequestData)1 Response (com.tencent.angel.ps.server.data.response.Response)1 ResponseData (com.tencent.angel.ps.server.data.response.ResponseData)1 ResponseHeader (com.tencent.angel.ps.server.data.response.ResponseHeader)1 ByteBuf (io.netty.buffer.ByteBuf)1