use of com.tencent.angel.ps.server.data.response.Response in project angel by Tencent.
the class GetUDFHandler method handle.
@Override
public void handle(FutureResult finalResult, UserRequest userRequest, ResponseCache responseCache) {
GetPSFRequest getPSFRequest = (GetPSFRequest) userRequest;
MapResponseCache cache = (MapResponseCache) responseCache;
// Adaptor to Get PSF merge
ConcurrentHashMap<Request, Response> responses = cache.getResponses();
int responseNum = responses.size();
List<PartitionGetResult> partGetResults = new ArrayList<>(responseNum);
for (Response response : responses.values()) {
partGetResults.add(((GetUDFResponse) response.getData()).getPartResult());
}
// Merge the sub-results
try {
finalResult.set(getPSFRequest.getGetFunc().merge(partGetResults));
} catch (Exception x) {
LOG.error("merge row failed ", x);
finalResult.setExecuteException(new ExecutionException(x));
}
}
use of com.tencent.angel.ps.server.data.response.Response in project angel by Tencent.
the class IndexGetRowHandler method handle.
@Override
public void handle(FutureResult finalResult, UserRequest userRequest, ResponseCache responseCache) {
IndexGetRowRequest indexGetRowRequest = (IndexGetRowRequest) userRequest;
MapResponseCache cache = (MapResponseCache) responseCache;
ConcurrentHashMap<Request, Response> responses = cache.getResponses();
// Merge
Vector result = merge(indexGetRowRequest, responses);
// Set matrix/row meta
result.setMatrixId(indexGetRowRequest.getMatrixId());
result.setRowId(indexGetRowRequest.getRowId());
// Set final result
finalResult.set(result);
}
use of com.tencent.angel.ps.server.data.response.Response 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;
}
}
Aggregations