SammyVimes commented on a change in pull request #102: URL: https://github.com/apache/ignite-3/pull/102#discussion_r628174653
########## File path: modules/network/src/main/java/org/apache/ignite/network/internal/netty/InboundDecoder.java ########## @@ -0,0 +1,117 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.network.internal.netty; + +import io.netty.buffer.ByteBuf; +import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.codec.ByteToMessageDecoder; +import io.netty.util.Attribute; +import io.netty.util.AttributeKey; +import java.nio.ByteBuffer; +import java.util.List; +import org.apache.ignite.lang.IgniteLogger; +import org.apache.ignite.network.internal.MessageReader; +import org.apache.ignite.network.internal.direct.DirectMarshallingUtils; +import org.apache.ignite.network.internal.direct.DirectMessageReader; +import org.apache.ignite.network.message.MessageDeserializer; +import org.apache.ignite.network.message.MessageSerializationRegistry; +import org.apache.ignite.network.message.NetworkMessage; + +/** + * Decodes {@link ByteBuf}s into {@link NetworkMessage}s. + */ +public class InboundDecoder extends ByteToMessageDecoder { + /** Logger. */ + private static final IgniteLogger LOG = IgniteLogger.forClass(InboundDecoder.class); + + /** Message reader channel attribute key. */ + private static final AttributeKey<MessageReader> READER_KEY = AttributeKey.valueOf("READER"); + + /** Message deserializer channel attribute key. */ + private static final AttributeKey<MessageDeserializer<NetworkMessage>> DESERIALIZER_KEY = AttributeKey.valueOf("DESERIALIZER"); + + /** Serialization registry. */ + private final MessageSerializationRegistry serializationRegistry; + + /** + * Constructor. + * + * @param serializationRegistry Serialization registry. + */ + public InboundDecoder(MessageSerializationRegistry serializationRegistry) { + this.serializationRegistry = serializationRegistry; + } + + /** {@inheritDoc} */ + @Override public void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception { + ByteBuffer buffer = in.nioBuffer(); + + Attribute<MessageReader> readerAttr = ctx.channel().attr(READER_KEY); + MessageReader reader = readerAttr.get(); + + if (reader == null) { + reader = new DirectMessageReader(serializationRegistry, ConnectionManager.DIRECT_PROTOCOL_VERSION); + readerAttr.set(reader); Review comment: No, not really, one channel can't be read from multiple threads -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
