use of com.akaxin.common.command.CommandResponse in project openzaly by akaxincom.
the class AbstractCommonHandler method customResponse.
// defined by user
protected CommandResponse customResponse(ErrorCode2 errCode) {
CommandResponse commandResponse = new CommandResponse().setVersion(CommandConst.PROTOCOL_VERSION).setAction(CommandConst.ACTION_RES);
commandResponse.setErrCode2(errCode);
return commandResponse;
}
use of com.akaxin.common.command.CommandResponse in project openzaly by akaxincom.
the class ApiRequestHandler method doApiRequest.
private CommandResponse doApiRequest(final Channel channel, Command command) {
CommandResponse comamndResponse = new ApiRequestService().process(command);
// response
CoreProto.TransportPackageData.Builder packageBuilder = CoreProto.TransportPackageData.newBuilder();
// header
Map<Integer, String> header = new HashMap<Integer, String>();
// 站点业务版本(proto版本)
header.put(CoreProto.HeaderKey.SITE_SERVER_VERSION_VALUE, CommandConst.SITE_VERSION);
packageBuilder.putAllHeader(header);
// errCode
CoreProto.ErrorInfo errinfo = CoreProto.ErrorInfo.newBuilder().setCode(String.valueOf(comamndResponse.getErrCode())).setInfo(comamndResponse.getErrInfo()).build();
packageBuilder.setErr(errinfo);
// data
if (comamndResponse.getParams() != null) {
packageBuilder.setData(ByteString.copyFrom(comamndResponse.getParams())).build();
}
// 协议版本 CommandConst.PROTOCOL_VERSION=1.0
String protocolVersion = CommandConst.PROTOCOL_VERSION;
String action = comamndResponse.getAction() == null ? CommandConst.ACTION_RES : comamndResponse.getAction();
ChannelFuture future = channel.writeAndFlush(new RedisCommand().add(protocolVersion).add(action).add(packageBuilder.build().toByteArray())).addListener(new GenericFutureListener<Future<? super Void>>() {
@Override
public void operationComplete(Future<? super Void> future) throws Exception {
channel.close();
}
});
// future.await(timeoutMillis);
return comamndResponse;
}
Aggregations