Search in sources :

Example 81 with CommandResponse

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;
}
Also used : CommandResponse(com.akaxin.common.command.CommandResponse)

Example 82 with 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;
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) CoreProto(com.akaxin.proto.core.CoreProto) HashMap(java.util.HashMap) CommandResponse(com.akaxin.common.command.CommandResponse) ByteString(com.google.protobuf.ByteString) RedisCommand(com.akaxin.common.command.RedisCommand) ApiRequestService(com.akaxin.site.business.service.ApiRequestService) ChannelFuture(io.netty.channel.ChannelFuture) Future(io.netty.util.concurrent.Future)

Aggregations

CommandResponse (com.akaxin.common.command.CommandResponse)82 ErrorCode2 (com.akaxin.common.constant.ErrorCode2)68 UserProto (com.akaxin.proto.core.UserProto)12 PluginBean (com.akaxin.site.storage.bean.PluginBean)7 ByteString (com.google.protobuf.ByteString)7 GroupProto (com.akaxin.proto.core.GroupProto)6 GroupProfileBean (com.akaxin.site.storage.bean.GroupProfileBean)6 SimpleUserBean (com.akaxin.site.storage.bean.SimpleUserBean)6 UserProfileBean (com.akaxin.site.storage.bean.UserProfileBean)6 UserDeviceBean (com.akaxin.site.storage.bean.UserDeviceBean)5 Command (com.akaxin.common.command.Command)4 DeviceProto (com.akaxin.proto.core.DeviceProto)4 ProtocolStringList (com.google.protobuf.ProtocolStringList)4 ConfigProto (com.akaxin.proto.core.ConfigProto)3 GroupMemberBean (com.akaxin.site.storage.bean.GroupMemberBean)3 UserGroupBean (com.akaxin.site.storage.bean.UserGroupBean)3 RedisCommand (com.akaxin.common.command.RedisCommand)2 ImStcPsnProto (com.akaxin.proto.client.ImStcPsnProto)2 CoreProto (com.akaxin.proto.core.CoreProto)2 FileProto (com.akaxin.proto.core.FileProto)2