当前位置: 首页>>代码示例>>Java>>正文


Java ChannelConfig.getMaxChunkCount方法代码示例

本文整理汇总了Java中com.digitalpetri.opcua.stack.core.channel.ChannelConfig.getMaxChunkCount方法的典型用法代码示例。如果您正苦于以下问题:Java ChannelConfig.getMaxChunkCount方法的具体用法?Java ChannelConfig.getMaxChunkCount怎么用?Java ChannelConfig.getMaxChunkCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.digitalpetri.opcua.stack.core.channel.ChannelConfig的用法示例。


在下文中一共展示了ChannelConfig.getMaxChunkCount方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onAcknowledge

import com.digitalpetri.opcua.stack.core.channel.ChannelConfig; //导入方法依赖的package包/类
private void onAcknowledge(ChannelHandlerContext ctx, ByteBuf buffer) {
    if (helloTimeout != null && !helloTimeout.cancel()) {
        helloTimeout = null;
        handshakeFuture.completeExceptionally(
                new UaException(StatusCodes.Bad_Timeout,
                        "timed out waiting for acknowledge"));
        ctx.close();
        return;
    }

    logger.debug("Received Acknowledge message on channel={}.", ctx.channel());

    buffer.skipBytes(3 + 1 + 4); // Skip messageType, chunkType, and messageSize

    AcknowledgeMessage acknowledge = AcknowledgeMessage.decode(buffer);

    long remoteProtocolVersion = acknowledge.getProtocolVersion();
    long remoteReceiveBufferSize = acknowledge.getReceiveBufferSize();
    long remoteSendBufferSize = acknowledge.getSendBufferSize();
    long remoteMaxMessageSize = acknowledge.getMaxMessageSize();
    long remoteMaxChunkCount = acknowledge.getMaxChunkCount();

    if (PROTOCOL_VERSION > remoteProtocolVersion) {
        logger.warn("Client protocol version ({}) does not match server protocol version ({}).",
                PROTOCOL_VERSION, remoteProtocolVersion);
    }

    ChannelConfig config = client.getChannelConfig();

    /* Our receive buffer size is determined by the remote send buffer size. */
    long localReceiveBufferSize = Math.min(remoteSendBufferSize, config.getMaxChunkSize());

    /* Our send buffer size is determined by the remote receive buffer size. */
    long localSendBufferSize = Math.min(remoteReceiveBufferSize, config.getMaxChunkSize());

    /* Max message size the remote can send us; not influenced by remote configuration. */
    long localMaxMessageSize = config.getMaxMessageSize();

    /* Max chunk count the remote can send us; not influenced by remote configuration. */
    long localMaxChunkCount = config.getMaxChunkCount();

    ChannelParameters parameters = new ChannelParameters(
            Ints.saturatedCast(localMaxMessageSize),
            Ints.saturatedCast(localReceiveBufferSize),
            Ints.saturatedCast(localSendBufferSize),
            Ints.saturatedCast(localMaxChunkCount),
            Ints.saturatedCast(remoteMaxMessageSize),
            Ints.saturatedCast(remoteReceiveBufferSize),
            Ints.saturatedCast(remoteSendBufferSize),
            Ints.saturatedCast(remoteMaxChunkCount)
    );

    ctx.channel().attr(KEY_AWAITING_HANDSHAKE).set(awaitingHandshake);

    ctx.executor().execute(() -> {
        int maxArrayLength = client.getChannelConfig().getMaxArrayLength();
        int maxStringLength = client.getChannelConfig().getMaxStringLength();

        SerializationQueue serializationQueue = new SerializationQueue(
                client.getConfig().getExecutor(),
                parameters,
                maxArrayLength,
                maxStringLength
        );

        UaTcpClientMessageHandler handler = new UaTcpClientMessageHandler(
                client,
                secureChannel,
                serializationQueue,
                handshakeFuture
        );

        ctx.pipeline().addLast(handler);
    });
}
 
开发者ID:digitalpetri,项目名称:opc-ua-stack,代码行数:76,代码来源:UaTcpClientAcknowledgeHandler.java

示例2: onHello

import com.digitalpetri.opcua.stack.core.channel.ChannelConfig; //导入方法依赖的package包/类
private void onHello(ChannelHandlerContext ctx, ByteBuf buffer) throws UaException {
    logger.debug("[remote={}] Received Hello message.", ctx.channel().remoteAddress());

    HelloMessage hello = TcpMessageDecoder.decodeHello(buffer);

    UaTcpStackServer server = socketServer.getServer(hello.getEndpointUrl());

    if (server == null) {
        throw new UaException(StatusCodes.Bad_TcpEndpointUrlInvalid,
                "unrecognized endpoint url: " + hello.getEndpointUrl());
    }

    ctx.channel().attr(ENDPOINT_URL_KEY).set(hello.getEndpointUrl());

    long remoteProtocolVersion = hello.getProtocolVersion();
    long remoteReceiveBufferSize = hello.getReceiveBufferSize();
    long remoteSendBufferSize = hello.getSendBufferSize();
    long remoteMaxMessageSize = hello.getMaxMessageSize();
    long remoteMaxChunkCount = hello.getMaxChunkCount();

    if (remoteProtocolVersion < PROTOCOL_VERSION) {
        throw new UaException(StatusCodes.Bad_ProtocolVersionUnsupported,
                "unsupported protocol version: " + remoteProtocolVersion);
    }

    ChannelConfig config = server.getChannelConfig();

    /* Our receive buffer size is determined by the remote send buffer size. */
    long localReceiveBufferSize = Math.min(remoteSendBufferSize, config.getMaxChunkSize());

    /* Our send buffer size is determined by the remote receive buffer size. */
    long localSendBufferSize = Math.min(remoteReceiveBufferSize, config.getMaxChunkSize());

    /* Max chunk count the remote can send us; not influenced by remote configuration. */
    long localMaxChunkCount = config.getMaxChunkCount();

    /* Max message size the remote can send us. Determined by our max chunk count and receive buffer size. */
    long localMaxMessageSize = Math.min(localReceiveBufferSize * localMaxChunkCount, config.getMaxMessageSize());

    ChannelParameters parameters = new ChannelParameters(
            Ints.saturatedCast(localMaxMessageSize),
            Ints.saturatedCast(localReceiveBufferSize),
            Ints.saturatedCast(localSendBufferSize),
            Ints.saturatedCast(localMaxChunkCount),
            Ints.saturatedCast(remoteMaxMessageSize),
            Ints.saturatedCast(remoteReceiveBufferSize),
            Ints.saturatedCast(remoteSendBufferSize),
            Ints.saturatedCast(remoteMaxChunkCount)
    );

    int maxArrayLength = config.getMaxArrayLength();
    int maxStringLength = config.getMaxStringLength();

    SerializationQueue serializationQueue = new SerializationQueue(
            server.getConfig().getExecutor(),
            parameters,
            maxArrayLength,
            maxStringLength
    );

    ctx.pipeline().addLast(new UaTcpServerAsymmetricHandler(server, serializationQueue));
    ctx.pipeline().remove(this);

    logger.debug("[remote={}] Removed HelloHandler, added AsymmetricHandler.", ctx.channel().remoteAddress());

    AcknowledgeMessage acknowledge = new AcknowledgeMessage(
            PROTOCOL_VERSION,
            localReceiveBufferSize,
            localSendBufferSize,
            localMaxMessageSize,
            localMaxChunkCount
    );

    ByteBuf messageBuffer = TcpMessageEncoder.encode(acknowledge);

    ctx.executor().execute(() -> ctx.writeAndFlush(messageBuffer));

    logger.debug("[remote={}] Sent Acknowledge message.", ctx.channel().remoteAddress());
}
 
开发者ID:digitalpetri,项目名称:opc-ua-stack,代码行数:80,代码来源:UaTcpServerHelloHandler.java


注:本文中的com.digitalpetri.opcua.stack.core.channel.ChannelConfig.getMaxChunkCount方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。