use of com.akaxin.common.command.CommandResponse in project openzaly by akaxincom.
the class NettyServerHandler method channelRead0.
@Override
protected void channelRead0(ChannelHandlerContext ctx, RedisCommand redisCmd) throws Exception {
InetSocketAddress socketAddress = (InetSocketAddress) ctx.channel().remoteAddress();
String clientIp = socketAddress.getAddress().getHostAddress();
ChannelSession channelSession = ctx.channel().attr(ParserConst.CHANNELSESSION).get();
// disconnect tcp connection as channel is unavailable
if (channelSession.getChannel() == null || !channelSession.getChannel().isActive()) {
// 断开连接事件(与对方的连接断开)
ctx.disconnect();
logger.warn("{} close client={} as its channel is not active ", AkxProject.PLN, clientIp);
}
String version = redisCmd.getParameterByIndex(0);
String action = redisCmd.getParameterByIndex(1);
byte[] params = redisCmd.getBytesParamByIndex(2);
CoreProto.TransportPackageData packageData = CoreProto.TransportPackageData.parseFrom(params);
Command command = new Command();
command.setClientIp(clientIp);
command.setSiteUserId(channelSession.getUserId());
command.setDeviceId(channelSession.getDeviceId());
command.setAction(action);
command.setHeader(packageData.getHeaderMap());
command.setParams(packageData.getData().toByteArray());
command.setChannelSession(channelSession);
command.setStartTime(System.currentTimeMillis());
if (!RequestAction.IM_CTS_PING.getName().equalsIgnoreCase(command.getAction())) {
logger.debug("{} client={} -> site version={} action={} params-length={}", AkxProject.PLN, clientIp, version, action, params.length);
} else {
logger.trace("{} client={} ping -> site", AkxProject.PLN, clientIp);
}
if (RequestAction.IM.getName().equals(command.getRety())) {
// 如果是syncFinish,则这里需要修改channel中的syncFinTime
channelSession.setActionForPsn(action);
// 单独处理im.site.hello && im.site.auth
if (RequestAction.SITE.getName().equalsIgnoreCase(command.getService())) {
String anoRequest = command.getRety() + "." + command.getService();
command.setRety(anoRequest);
}
CommandResponse response = this.executor.execute(command.getRety(), command);
if (!RequestAction.IM_CTS_PING.getName().equals(command.getAction())) {
// 输出IM请求结果
LogUtils.requestResultLog(logger, command, response);
}
} else if (RequestAction.API.getName().equalsIgnoreCase(command.getRety())) {
CommandResponse response = this.executor.execute(command.getRety(), command);
// 输出API请求结果
LogUtils.requestResultLog(logger, command, response);
} else {
/**
* <pre>
*
* pipeline.addLast("A", new AHandler());
* pipeline.addLast("B", new BHandler());
* pipeline.addLast("C", new CHandler());
*
* ctx.close() && channel().close();
* ctx.close(): close the channel in current handler,will start from the tail of the ChannelPipeline
* do A.close() ,B.close(),C.close();
* channel().close():close channel in all handler from pointer
* do C.close() , B.close(), A.close();
* </pre>
*/
// 关闭channel事件(关闭自己的连接)
ctx.channel().close();
logger.error("{} client={} siteUserId={} action={} unknow request method", AkxProject.PLN, command.getClientIp(), command.getSiteUserId(), command.getAction());
return;
}
}
use of com.akaxin.common.command.CommandResponse in project openzaly by akaxincom.
the class AbstractCommonHandler method defaultErrorResponse.
// default error ressponse by ErrorCode2.ERROR
protected CommandResponse defaultErrorResponse() {
CommandResponse commandResponse = new CommandResponse().setVersion(CommandConst.PROTOCOL_VERSION).setAction(CommandConst.ACTION_RES);
commandResponse.setErrCode2(ErrorCode2.ERROR);
return commandResponse;
}
use of com.akaxin.common.command.CommandResponse in project openzaly by akaxincom.
the class GroupPsnHandler method writePSN.
private void writePSN(String deviceId) {
CommandResponse commandResponse = new CommandResponse().setVersion(CommandConst.PROTOCOL_VERSION).setAction(CommandConst.IM_STC_PSN);
ImStcPsnProto.ImStcPsnRequest pshRequest = ImStcPsnProto.ImStcPsnRequest.newBuilder().build();
commandResponse.setParams(pshRequest.toByteArray());
commandResponse.setErrCode(ErrorCode.SUCCESS);
ChannelWriter.writeByDeviceId(deviceId, commandResponse);
}
use of com.akaxin.common.command.CommandResponse in project openzaly by akaxincom.
the class UserPsnHandler method writePsn.
private void writePsn(String deviceId) {
CommandResponse commandResponse = new CommandResponse().setVersion(CommandConst.PROTOCOL_VERSION).setAction(CommandConst.IM_STC_PSN);
ImStcPsnProto.ImStcPsnRequest pshRequest = ImStcPsnProto.ImStcPsnRequest.newBuilder().build();
commandResponse.setParams(pshRequest.toByteArray());
commandResponse.setErrCode(ErrorCode.SUCCESS);
ChannelWriter.writeByDeviceId(deviceId, commandResponse);
}
use of com.akaxin.common.command.CommandResponse in project openzaly by akaxincom.
the class ApiDeviceService method list.
public CommandResponse list(Command command) {
CommandResponse commandResponse = new CommandResponse();
ErrorCode2 errCode = ErrorCode2.ERROR;
try {
ApiDeviceListProto.DeviceListInfoRequest request = ApiDeviceListProto.DeviceListInfoRequest.parseFrom(command.getParams());
String siteFriendId = request.getSiteUserId();
LogUtils.requestDebugLog(logger, command, request.toString());
if (StringUtils.isNotBlank(siteFriendId)) {
ApiDeviceListProto.DeviceListInfoResponse.Builder responseBuilder = ApiDeviceListProto.DeviceListInfoResponse.newBuilder();
List<UserDeviceBean> deviceList = UserDeviceDao.getInstance().getActiveDeviceList(siteFriendId);
for (UserDeviceBean device : deviceList) {
DeviceProto.SimpleDeviceProfile deviceProfile = DeviceProto.SimpleDeviceProfile.newBuilder().setDeviceId(String.valueOf(device.getDeviceId())).setDeviceName(String.valueOf(device.getDeviceName())).setUserDevicePubk(String.valueOf(device.getUserDevicePubk())).setLastLoginTime(device.getActiveTime()).build();
responseBuilder.addList(deviceProfile);
}
commandResponse.setParams(responseBuilder.build().toByteArray());
errCode = ErrorCode2.SUCCESS;
} else {
errCode = ErrorCode2.ERROR_PARAMETER;
}
} catch (Exception e) {
errCode = ErrorCode2.ERROR_SYSTEMERROR;
LogUtils.requestErrorLog(logger, command, e);
}
return commandResponse.setErrCode2(errCode);
}
Aggregations