本文整理汇总了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);
});
}
示例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());
}