Search in sources :

Example 1 with SMGPExitRespMessage

use of com.zx.sms.codec.smgp.msg.SMGPExitRespMessage in project SMSGate by Lihuanghe.

the class SMGPMessageCodec method fromBytes.

private SMGPBaseMessage fromBytes(byte[] bytes) throws Exception {
    if (bytes == null) {
        return null;
    }
    if (bytes.length < SMGPBaseMessage.SZ_HEADER) {
        return null;
    }
    int commandLength = ByteUtil.byte2int(bytes, 0);
    assert bytes.length == commandLength;
    int commandId = ByteUtil.byte2int(bytes, 4);
    SMGPBaseMessage baseMsg = null;
    switch(commandId) {
        case SMGPConstants.SMGP_LOGIN:
            baseMsg = new SMGPLoginMessage();
            break;
        case SMGPConstants.SMGP_LOGIN_RESP:
            baseMsg = new SMGPLoginRespMessage();
            break;
        case SMGPConstants.SMGP_SUBMIT:
            baseMsg = new SMGPSubmitMessage();
            break;
        case SMGPConstants.SMGP_SUBMIT_RESP:
            baseMsg = new SMGPSubmitRespMessage();
            break;
        case SMGPConstants.SMGP_DELIVER:
            baseMsg = new SMGPDeliverMessage();
            break;
        case SMGPConstants.SMGP_DELIVER_RESP:
            baseMsg = new SMGPDeliverRespMessage();
            break;
        case SMGPConstants.SMGP_ACTIVE_TEST:
            baseMsg = new SMGPActiveTestMessage();
            break;
        case SMGPConstants.SMGP_ACTIVE_TEST_RESP:
            baseMsg = new SMGPActiveTestRespMessage();
            break;
        case SMGPConstants.SMGP_EXIT_TEST:
            baseMsg = new SMGPExitMessage();
            break;
        case SMGPConstants.SMGP_EXIT_RESP:
            baseMsg = new SMGPExitRespMessage();
            break;
        default:
            baseMsg = new SMGPUnknownMessage(commandId);
            break;
    }
    baseMsg.fromBytes(bytes, version);
    return baseMsg;
}
Also used : SMGPDeliverMessage(com.zx.sms.codec.smgp.msg.SMGPDeliverMessage) SMGPExitMessage(com.zx.sms.codec.smgp.msg.SMGPExitMessage) SMGPBaseMessage(com.zx.sms.codec.smgp.msg.SMGPBaseMessage) SMGPDeliverRespMessage(com.zx.sms.codec.smgp.msg.SMGPDeliverRespMessage) SMGPLoginMessage(com.zx.sms.codec.smgp.msg.SMGPLoginMessage) SMGPActiveTestRespMessage(com.zx.sms.codec.smgp.msg.SMGPActiveTestRespMessage) SMGPUnknownMessage(com.zx.sms.codec.smgp.msg.SMGPUnknownMessage) SMGPExitRespMessage(com.zx.sms.codec.smgp.msg.SMGPExitRespMessage) SMGPLoginRespMessage(com.zx.sms.codec.smgp.msg.SMGPLoginRespMessage) SMGPSubmitRespMessage(com.zx.sms.codec.smgp.msg.SMGPSubmitRespMessage) SMGPActiveTestMessage(com.zx.sms.codec.smgp.msg.SMGPActiveTestMessage) SMGPSubmitMessage(com.zx.sms.codec.smgp.msg.SMGPSubmitMessage)

Example 2 with SMGPExitRespMessage

use of com.zx.sms.codec.smgp.msg.SMGPExitRespMessage in project SMSGate by Lihuanghe.

the class SMGPExitMessageHandler method channelRead0.

@Override
protected void channelRead0(final ChannelHandlerContext ctx, SMGPExitMessage msg) throws Exception {
    SMGPExitRespMessage resp = new SMGPExitRespMessage();
    resp.setSequenceNo(msg.getSequenceNo());
    ChannelFuture future = ctx.channel().writeAndFlush(resp);
    final ChannelHandlerContext finalctx = ctx;
    future.addListeners(new GenericFutureListener() {

        @Override
        public void operationComplete(Future future) throws Exception {
            ctx.executor().schedule(new Runnable() {

                @Override
                public void run() {
                    finalctx.channel().close();
                }
            }, 500, TimeUnit.MILLISECONDS);
        }
    });
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) SMGPExitRespMessage(com.zx.sms.codec.smgp.msg.SMGPExitRespMessage) Future(io.netty.util.concurrent.Future) ChannelFuture(io.netty.channel.ChannelFuture) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) GenericFutureListener(io.netty.util.concurrent.GenericFutureListener)

Aggregations

SMGPExitRespMessage (com.zx.sms.codec.smgp.msg.SMGPExitRespMessage)2 SMGPActiveTestMessage (com.zx.sms.codec.smgp.msg.SMGPActiveTestMessage)1 SMGPActiveTestRespMessage (com.zx.sms.codec.smgp.msg.SMGPActiveTestRespMessage)1 SMGPBaseMessage (com.zx.sms.codec.smgp.msg.SMGPBaseMessage)1 SMGPDeliverMessage (com.zx.sms.codec.smgp.msg.SMGPDeliverMessage)1 SMGPDeliverRespMessage (com.zx.sms.codec.smgp.msg.SMGPDeliverRespMessage)1 SMGPExitMessage (com.zx.sms.codec.smgp.msg.SMGPExitMessage)1 SMGPLoginMessage (com.zx.sms.codec.smgp.msg.SMGPLoginMessage)1 SMGPLoginRespMessage (com.zx.sms.codec.smgp.msg.SMGPLoginRespMessage)1 SMGPSubmitMessage (com.zx.sms.codec.smgp.msg.SMGPSubmitMessage)1 SMGPSubmitRespMessage (com.zx.sms.codec.smgp.msg.SMGPSubmitRespMessage)1 SMGPUnknownMessage (com.zx.sms.codec.smgp.msg.SMGPUnknownMessage)1 ChannelFuture (io.netty.channel.ChannelFuture)1 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)1 Future (io.netty.util.concurrent.Future)1 GenericFutureListener (io.netty.util.concurrent.GenericFutureListener)1