Search in sources :

Example 1 with CmppTerminateResponseMessage

use of com.zx.sms.codec.cmpp.msg.CmppTerminateResponseMessage in project SMSGate by Lihuanghe.

the class CmppTerminateResponseMessageCodec method decode.

@Override
protected void decode(ChannelHandlerContext ctx, Message msg, List<Object> out) throws Exception {
    int commandId = msg.getHeader().getCommandId();
    if (packetType.getCommandId() != commandId) {
        // 不解析,交给下一个codec
        out.add(msg);
        return;
    }
    ;
    CmppTerminateResponseMessage responseMessage = new CmppTerminateResponseMessage(msg.getHeader());
    out.add(responseMessage);
}
Also used : CmppTerminateResponseMessage(com.zx.sms.codec.cmpp.msg.CmppTerminateResponseMessage)

Example 2 with CmppTerminateResponseMessage

use of com.zx.sms.codec.cmpp.msg.CmppTerminateResponseMessage in project SMSGate by Lihuanghe.

the class CmppTerminateRequestMessageHandler method channelRead0.

/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.jboss.netty.channel.SimpleChannelUpstreamHandler#messageReceived(
	 * org.jboss.netty.channel.ChannelHandlerContext,
	 * org.jboss.netty.channel.MessageEvent)
	 */
@Override
public void channelRead0(final ChannelHandlerContext ctx, CmppTerminateRequestMessage e) throws Exception {
    CmppTerminateResponseMessage responseMessage = new CmppTerminateResponseMessage(e.getHeader().getSequenceId());
    ChannelFuture future = ctx.channel().writeAndFlush(responseMessage);
    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) Future(io.netty.util.concurrent.Future) ChannelFuture(io.netty.channel.ChannelFuture) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) GenericFutureListener(io.netty.util.concurrent.GenericFutureListener) CmppTerminateResponseMessage(com.zx.sms.codec.cmpp.msg.CmppTerminateResponseMessage)

Example 3 with CmppTerminateResponseMessage

use of com.zx.sms.codec.cmpp.msg.CmppTerminateResponseMessage in project SMSGate by Lihuanghe.

the class TestCmppTerminateResponseMessageCodec method testCodec.

@Test
public void testCodec() {
    CmppTerminateResponseMessage msg = new CmppTerminateResponseMessage(1);
    ByteBuf buf = encode(msg);
    ByteBuf copybuf = buf.copy();
    Assert.assertEquals(12, buf.readableBytes());
    Assert.assertEquals(12, buf.readInt());
    Assert.assertEquals(msg.getPacketType().getCommandId(), buf.readInt());
    Assert.assertEquals(msg.getHeader().getSequenceId(), buf.readInt());
    CmppTerminateResponseMessage result = decode(copybuf);
    Assert.assertTrue(result instanceof CmppTerminateResponseMessage);
    Assert.assertEquals(msg.getHeader().getSequenceId(), ((CmppTerminateResponseMessage) result).getHeader().getSequenceId());
}
Also used : ByteBuf(io.netty.buffer.ByteBuf) CmppTerminateResponseMessage(com.zx.sms.codec.cmpp.msg.CmppTerminateResponseMessage) Test(org.junit.Test)

Aggregations

CmppTerminateResponseMessage (com.zx.sms.codec.cmpp.msg.CmppTerminateResponseMessage)3 ByteBuf (io.netty.buffer.ByteBuf)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 Test (org.junit.Test)1