use of pers.cy.iris.commons.network.protocol.response.ErrorResponse in project iris by chicc999.
the class DefaultDispatcherHandler method channelRead0.
@Override
protected void channelRead0(ChannelHandlerContext ctx, Command command) throws Exception {
if (command == null) {
return;
}
logger.debug("dispatcher command : {} {}", command.getHeader().getHeaderType().toString(), command.getHeader().getTypeString());
HeaderType headerType = command.getHeader().getHeaderType();
switch(headerType) {
case REQUEST:
{
// 如果是请求命令, 做请求处理
try {
processRequest(ctx, command);
} catch (Exception e) {
logger.error(e.getMessage(), e);
//如果请求需要响应
if (command.getHeader().getAcknowledge() != Acknowledge.ACK_NO) {
//写出响应,如果出现异常则调用exceptionCaught打印异常关闭连接
ctx.writeAndFlush(new ErrorResponse(-1, e.toString(), command.getRequestId())).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE);
}
}
break;
}
case RESPONSE:
{
// 如果是响应命令, 做响应处理
processResponse(ctx, command);
break;
}
}
}
use of pers.cy.iris.commons.network.protocol.response.ErrorResponse in project iris by chicc999.
the class HandlerTask method run.
@Override
public void run() {
// 处理请求命令
Header header = request.getHeader();
Command response = null;
try {
response = handler.process(ctx, request);
} catch (Throwable e) {
//如果请求需要答复
if (request.getHeader().getAcknowledge() != Acknowledge.ACK_NO) {
//写出响应,如果出现异常则调用exceptionCaught打印异常关闭连接
ctx.writeAndFlush(new ErrorResponse(-1, e.getMessage(), request.getRequestId())).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE);
}
}
response.getHeader().setRequestId(request.getRequestId());
ChannelFutureListener listenner = response.getListenner() == null ? ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE : response.getListenner();
//服务端不处理commandCallback,直接在DispatcherHandler处理对应type.客户端则在发送时指定回调函数.
ctx.writeAndFlush(response).addListener(listenner);
}
use of pers.cy.iris.commons.network.protocol.response.ErrorResponse in project iris by chicc999.
the class PutMessageHandler method process.
@Override
public Command process(ChannelHandlerContext ctx, Command command) throws Exception {
PutMessage putMessage = (PutMessage) command;
System.out.println("收到putMessage请求," + new String(putMessage.getMessages()[0].getBody()));
Message[] messages = putMessage.getMessages();
for (Message message : messages) {
store.putMessage((StoreMessage) message);
}
return new ErrorResponse(200, "", command.getRequestId());
}
Aggregations