• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java SctpMessage类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中io.netty.channel.sctp.SctpMessage的典型用法代码示例。如果您正苦于以下问题:Java SctpMessage类的具体用法?Java SctpMessage怎么用?Java SctpMessage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



SctpMessage类属于io.netty.channel.sctp包,在下文中一共展示了SctpMessage类的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: filterOutboundMessage

import io.netty.channel.sctp.SctpMessage; //导入依赖的package包/类
@Override
protected final Object filterOutboundMessage(Object msg) throws Exception {
    if (msg instanceof SctpMessage) {
        SctpMessage m = (SctpMessage) msg;
        ByteBuf buf = m.content();
        if (buf.isDirect() && buf.nioBufferCount() == 1) {
            return m;
        }

        return new SctpMessage(m.protocolIdentifier(), m.streamIdentifier(), newDirectBuffer(m, buf));
    }

    throw new UnsupportedOperationException(
            "unsupported message type: " + StringUtil.simpleClassName(msg) +
            " (expected: " + StringUtil.simpleClassName(SctpMessage.class));
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:17,代码来源:NioSctpChannel.java


示例2: channelRead

import io.netty.channel.sctp.SctpMessage; //导入依赖的package包/类
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) {
	System.out.println(msg);
	if(msg instanceof SctpMessage){ 
		SctpMessage sctpMsg = (SctpMessage) msg;
		System.out.println(sctpMsg.content().toString(CharsetUtil.UTF_8));
		ctx.write(sctpMsg); 
	}    	
}
 
开发者ID:duchien85,项目名称:netty-cookbook,代码行数:10,代码来源:SimpleSctpServerHandler.java


示例3: filterOutboundMessage

import io.netty.channel.sctp.SctpMessage; //导入依赖的package包/类
@Override
protected Object filterOutboundMessage(Object msg) throws Exception {
    if (msg instanceof SctpMessage) {
        return msg;
    }

    throw new UnsupportedOperationException(
            "unsupported message type: " + StringUtil.simpleClassName(msg) + EXPECTED_TYPE);
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:10,代码来源:OioSctpChannel.java


示例4: doReadMessages

import io.netty.channel.sctp.SctpMessage; //导入依赖的package包/类
@Override
protected int doReadMessages(List<Object> buf) throws Exception {
    SctpChannel ch = javaChannel();

    RecvByteBufAllocator.Handle allocHandle = this.allocHandle;
    if (allocHandle == null) {
        this.allocHandle = allocHandle = config().getRecvByteBufAllocator().newHandle();
    }
    ByteBuf buffer = allocHandle.allocate(config().getAllocator());
    boolean free = true;
    try {
        ByteBuffer data = buffer.internalNioBuffer(buffer.writerIndex(), buffer.writableBytes());
        int pos = data.position();

        MessageInfo messageInfo = ch.receive(data, null, notificationHandler);
        if (messageInfo == null) {
            return 0;
        }
        buf.add(new SctpMessage(messageInfo, buffer.writerIndex(buffer.writerIndex() + data.position() - pos)));
        free = false;
        return 1;
    } catch (Throwable cause) {
        PlatformDependent.throwException(cause);
        return -1;
    }  finally {
        int bytesRead = buffer.readableBytes();
        allocHandle.record(bytesRead);
        if (free) {
            buffer.release();
        }
    }
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:33,代码来源:NioSctpChannel.java


示例5: doWriteMessage

import io.netty.channel.sctp.SctpMessage; //导入依赖的package包/类
@Override
protected boolean doWriteMessage(Object msg, ChannelOutboundBuffer in) throws Exception {
    SctpMessage packet = (SctpMessage) msg;
    ByteBuf data = packet.content();
    int dataLen = data.readableBytes();
    if (dataLen == 0) {
        return true;
    }

    ByteBufAllocator alloc = alloc();
    boolean needsCopy = data.nioBufferCount() != 1;
    if (!needsCopy) {
        if (!data.isDirect() && alloc.isDirectBufferPooled()) {
            needsCopy = true;
        }
    }
    ByteBuffer nioData;
    if (!needsCopy) {
        nioData = data.nioBuffer();
    } else {
        data = alloc.directBuffer(dataLen).writeBytes(data);
        nioData = data.nioBuffer();
    }
    final MessageInfo mi = MessageInfo.createOutgoing(association(), null, packet.streamIdentifier());
    mi.payloadProtocolID(packet.protocolIdentifier());
    mi.streamNumber(packet.streamIdentifier());

    final int writtenBytes = javaChannel().send(nioData, mi);
    return writtenBytes > 0;
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:31,代码来源:NioSctpChannel.java


示例6: acceptInboundMessage

import io.netty.channel.sctp.SctpMessage; //导入依赖的package包/类
@Override
public final boolean acceptInboundMessage(Object msg) throws Exception {
    if (super.acceptInboundMessage(msg)) {
        return acceptInboundMessage((SctpMessage) msg);
    }
    return false;
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:8,代码来源:SctpInboundByteStreamHandler.java


示例7: decode

import io.netty.channel.sctp.SctpMessage; //导入依赖的package包/类
@Override
protected void decode(ChannelHandlerContext ctx, SctpMessage msg, List<Object> out) throws Exception {
    if (!msg.isComplete()) {
        throw new CodecException(String.format("Received SctpMessage is not complete, please add %s in the " +
                "pipeline before this handler", SctpMessageCompletionHandler.class.getSimpleName()));
    }
    out.add(msg.content().retain());
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:9,代码来源:SctpInboundByteStreamHandler.java


示例8: decode

import io.netty.channel.sctp.SctpMessage; //导入依赖的package包/类
@Override
protected void decode(ChannelHandlerContext ctx, SctpMessage msg, List<Object> out) throws Exception {
    final ByteBuf byteBuf = msg.content();
    final int protocolIdentifier = msg.protocolIdentifier();
    final int streamIdentifier = msg.streamIdentifier();
    final boolean isComplete = msg.isComplete();

    ByteBuf frag;
    if (fragments.containsKey(streamIdentifier)) {
        frag = fragments.remove(streamIdentifier);
    } else {
        frag = Unpooled.EMPTY_BUFFER;
    }

    if (isComplete && !frag.isReadable()) {
        //data chunk is not fragmented
        out.add(msg);
    } else if (!isComplete && frag.isReadable()) {
        //more message to complete
        fragments.put(streamIdentifier, Unpooled.wrappedBuffer(frag, byteBuf));
    } else if (isComplete && frag.isReadable()) {
        //last message to complete
        fragments.remove(streamIdentifier);
        SctpMessage assembledMsg = new SctpMessage(
                protocolIdentifier,
                streamIdentifier,
                Unpooled.wrappedBuffer(frag, byteBuf));
        out.add(assembledMsg);
    } else {
        //first incomplete message
        fragments.put(streamIdentifier, byteBuf);
    }
    byteBuf.retain();
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:35,代码来源:SctpMessageCompletionHandler.java


示例9: acceptInboundMessage

import io.netty.channel.sctp.SctpMessage; //导入依赖的package包/类
@Override
public boolean acceptInboundMessage(Object msg) throws Exception {
    if (msg instanceof SctpMessage) {
        SctpMessage sctpMsg = (SctpMessage) msg;
        if (sctpMsg.isComplete()) {
            return true;
        }

        throw new CodecException(String.format("Received SctpMessage is not complete, please add %s in " +
                "the pipeline before this handler", SctpMessageCompletionHandler.class.getSimpleName()));
    } else {
        return false;
    }
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:15,代码来源:SctpMessageToMessageDecoder.java


示例10: doReadMessages

import io.netty.channel.sctp.SctpMessage; //导入依赖的package包/类
@Override
protected int doReadMessages(List<Object> buf) throws Exception {
    SctpChannel ch = javaChannel();

    RecvByteBufAllocator.Handle allocHandle = this.allocHandle;
    if (allocHandle == null) {
        this.allocHandle = allocHandle = config().getRecvByteBufAllocator().newHandle();
    }
    ByteBuf buffer = allocHandle.allocate(config().getAllocator());
    boolean free = true;
    try {
        ByteBuffer data = buffer.internalNioBuffer(buffer.writerIndex(), buffer.writableBytes());
        int pos = data.position();

        MessageInfo messageInfo = ch.receive(data, null, notificationHandler);
        if (messageInfo == null) {
            return 0;
        }
        buf.add(new SctpMessage(messageInfo, buffer.writerIndex(buffer.writerIndex() + (data.position() - pos))));
        free = false;
        return 1;
    } catch (Throwable cause) {
        PlatformDependent.throwException(cause);
        return -1;
    }  finally {
        int bytesRead = buffer.readableBytes();
        allocHandle.record(bytesRead);
        if (free) {
            buffer.release();
        }
    }
}
 
开发者ID:kyle-liu,项目名称:netty4study,代码行数:33,代码来源:NioSctpChannel.java


示例11: doWriteMessage

import io.netty.channel.sctp.SctpMessage; //导入依赖的package包/类
@Override
protected boolean doWriteMessage(Object msg, ChannelOutboundBuffer in) throws Exception {
    SctpMessage packet = (SctpMessage) msg;
    ByteBuf data = packet.content();
    int dataLen = data.readableBytes();
    if (dataLen == 0) {
        return true;
    }

    ByteBufAllocator alloc = alloc();
    boolean needsCopy = data.nioBufferCount() != 1;
    if (!needsCopy) {
        if (!data.isDirect() && alloc.isDirectBufferPooled()) {
            needsCopy = true;
        }
    }
    ByteBuffer nioData;
    if (!needsCopy) {
        nioData = data.nioBuffer();
    } else {
        data = alloc.directBuffer(dataLen).writeBytes(data);
        nioData = data.nioBuffer();
    }

    final MessageInfo mi = MessageInfo.createOutgoing(association(), null, packet.streamIdentifier());
    mi.payloadProtocolID(packet.protocolIdentifier());
    mi.streamNumber(packet.streamIdentifier());

    final int writtenBytes = javaChannel().send(nioData, mi);

    boolean done = writtenBytes > 0;
    if (needsCopy) {
        if (!done) {
            in.current(new SctpMessage(mi, data));
        } else {
            in.current(data);
        }
    }
    return done;
}
 
开发者ID:kyle-liu,项目名称:netty4study,代码行数:41,代码来源:NioSctpChannel.java


示例12: channelActive

import io.netty.channel.sctp.SctpMessage; //导入依赖的package包/类
@Override
public void channelActive(ChannelHandlerContext ctx) {
    ctx.writeAndFlush(new SctpMessage(0, 0, firstMessage));
}
 
开发者ID:cowthan,项目名称:JavaAyo,代码行数:5,代码来源:SctpEchoClientHandler.java


示例13: channelActive

import io.netty.channel.sctp.SctpMessage; //导入依赖的package包/类
@Override
public void channelActive(ChannelHandlerContext ctx) {
    ctx.write(new SctpMessage(0, 0, firstMessage));
    ctx.write(new SctpMessage(0, 0, secondMessage));
    ctx.flush();
}
 
开发者ID:duchien85,项目名称:netty-cookbook,代码行数:7,代码来源:SimpleSctpClientHandler.java


示例14: doReadMessages

import io.netty.channel.sctp.SctpMessage; //导入依赖的package包/类
@Override
protected int doReadMessages(List<Object> msgs) throws Exception {
    if (!readSelector.isOpen()) {
        return 0;
    }

    int readMessages = 0;

    final int selectedKeys = readSelector.select(SO_TIMEOUT);
    final boolean keysSelected = selectedKeys > 0;

    if (!keysSelected) {
        return readMessages;
    }

    Set<SelectionKey> reableKeys = readSelector.selectedKeys();
    try {
        for (SelectionKey ignored : reableKeys) {
            RecvByteBufAllocator.Handle allocHandle = this.allocHandle;
            if (allocHandle == null) {
                this.allocHandle = allocHandle = config().getRecvByteBufAllocator().newHandle();
            }
            ByteBuf buffer = allocHandle.allocate(config().getAllocator());
            boolean free = true;

            try {
                ByteBuffer data = buffer.nioBuffer(buffer.writerIndex(), buffer.writableBytes());
                MessageInfo messageInfo = ch.receive(data, null, notificationHandler);
                if (messageInfo == null) {
                    return readMessages;
                }

                data.flip();
                msgs.add(new SctpMessage(messageInfo, buffer.writerIndex(buffer.writerIndex() + data.remaining())));
                free = false;
                readMessages ++;
            } catch (Throwable cause) {
                PlatformDependent.throwException(cause);
            }  finally {
                int bytesRead = buffer.readableBytes();
                allocHandle.record(bytesRead);
                if (free) {
                    buffer.release();
                }
            }
        }
    } finally {
        reableKeys.clear();
    }
    return readMessages;
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:52,代码来源:OioSctpChannel.java


示例15: doWrite

import io.netty.channel.sctp.SctpMessage; //导入依赖的package包/类
@Override
protected void doWrite(ChannelOutboundBuffer in) throws Exception {
    if (!writeSelector.isOpen()) {
        return;
    }
    final int size = in.size();
    final int selectedKeys = writeSelector.select(SO_TIMEOUT);
    if (selectedKeys > 0) {
        final Set<SelectionKey> writableKeys = writeSelector.selectedKeys();
        if (writableKeys.isEmpty()) {
            return;
        }
        Iterator<SelectionKey> writableKeysIt = writableKeys.iterator();
        int written = 0;
        for (;;) {
            if (written == size) {
                // all written
                return;
            }
            writableKeysIt.next();
            writableKeysIt.remove();

            SctpMessage packet = (SctpMessage) in.current();
            if (packet == null) {
                return;
            }

            ByteBuf data = packet.content();
            int dataLen = data.readableBytes();
            ByteBuffer nioData;

            if (data.nioBufferCount() != -1) {
                nioData = data.nioBuffer();
            } else {
                nioData = ByteBuffer.allocate(dataLen);
                data.getBytes(data.readerIndex(), nioData);
                nioData.flip();
            }

            final MessageInfo mi = MessageInfo.createOutgoing(association(), null, packet.streamIdentifier());
            mi.payloadProtocolID(packet.protocolIdentifier());
            mi.streamNumber(packet.streamIdentifier());

            ch.send(nioData, mi);
            written ++;
            in.remove();

            if (!writableKeysIt.hasNext()) {
                return;
            }
        }
    }
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:54,代码来源:OioSctpChannel.java


示例16: encode

import io.netty.channel.sctp.SctpMessage; //导入依赖的package包/类
@Override
protected void encode(ChannelHandlerContext ctx, ByteBuf msg, List<Object> out) throws Exception {
    out.add(new SctpMessage(streamIdentifier, protocolIdentifier, msg.retain()));
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:5,代码来源:SctpOutboundByteStreamHandler.java


示例17: channelActive

import io.netty.channel.sctp.SctpMessage; //导入依赖的package包/类
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
    ctx.writeAndFlush(new SctpMessage(0, 0, firstMessage));
}
 
开发者ID:edgar615,项目名称:javase-study,代码行数:5,代码来源:SctpEchoClientHandler.java



注:本文中的io.netty.channel.sctp.SctpMessage类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ESSCertIDv2类代码示例发布时间:2022-05-22
下一篇:
Java Arithmetic类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap