Search in sources :

Example 1 with ClassDescriptorMessage

use of org.apache.ignite.internal.network.message.ClassDescriptorMessage in project ignite-3 by apache.

the class MarshallableTest method write.

/**
 * Writes a map to a buffer through the {@link MessageWithMarshallable}.
 */
private ByteBuffer write(Map<String, SimpleSerializableObject> testMap) throws Exception {
    var serializers = new Serialization();
    var writer = new DirectMessageWriter(serializers.perSessionSerializationService, ConnectionManager.DIRECT_PROTOCOL_VERSION);
    MessageWithMarshallable msg = msgFactory.messageWithMarshallable().marshallableMap(testMap).build();
    IntSet ids = new IntOpenHashSet();
    msg.prepareMarshal(ids, serializers.userObjectSerializer);
    MessageSerializer<NetworkMessage> serializer = registry.createSerializer(msg.groupType(), msg.messageType());
    var catcher = new OutboundByteBufCatcher();
    var channel = new EmbeddedChannel(catcher, new ChunkedWriteHandler(), new OutboundEncoder(serializers.perSessionSerializationService));
    List<ClassDescriptorMessage> classDescriptorsMessages = PerSessionSerializationService.createClassDescriptorsMessages(ids, serializers.descriptorRegistry);
    channel.writeAndFlush(new OutNetworkObject(msg, classDescriptorsMessages));
    channel.flushOutbound();
    ByteBuffer nioBuffer = catcher.buf;
    return nioBuffer;
}
Also used : IntSet(it.unimi.dsi.fastutil.ints.IntSet) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) ByteBuffer(java.nio.ByteBuffer) ClassDescriptorMessage(org.apache.ignite.internal.network.message.ClassDescriptorMessage) IntOpenHashSet(it.unimi.dsi.fastutil.ints.IntOpenHashSet) DirectMessageWriter(org.apache.ignite.internal.network.direct.DirectMessageWriter) ChunkedWriteHandler(io.netty.handler.stream.ChunkedWriteHandler) OutboundEncoder(org.apache.ignite.internal.network.netty.OutboundEncoder) NetworkMessage(org.apache.ignite.network.NetworkMessage) OutNetworkObject(org.apache.ignite.network.OutNetworkObject)

Example 2 with ClassDescriptorMessage

use of org.apache.ignite.internal.network.message.ClassDescriptorMessage in project ignite-3 by apache.

the class PerSessionSerializationService method mergeDescriptors.

/**
 * Merges incoming remote descriptors.
 *
 * @param remoteDescriptors Remote descriptors.
 */
public void mergeDescriptors(Collection<ClassDescriptorMessage> remoteDescriptors) {
    List<ClassDescriptorMessage> leftToProcess = remoteDescriptors.stream().filter(classMessage -> !knownMergedDescriptor(classMessage.descriptorId())).collect(toCollection(LinkedList::new));
    while (!leftToProcess.isEmpty()) {
        boolean processedSomethingDuringThisPass = false;
        Iterator<ClassDescriptorMessage> it = leftToProcess.iterator();
        while (it.hasNext()) {
            ClassDescriptorMessage classMessage = it.next();
            if (knownMergedDescriptor(classMessage.descriptorId())) {
                it.remove();
            } else if (dependenciesAreMerged(classMessage)) {
                Class<?> localClass = classForName(classMessage.className());
                ClassDescriptor mergedDescriptor = messageToMergedClassDescriptor(classMessage, localClass);
                mergedIdToDescriptorMap.put(classMessage.descriptorId(), mergedDescriptor);
                mergedClassToDescriptorMap.put(localClass, mergedDescriptor);
                it.remove();
                processedSomethingDuringThisPass = true;
            }
        }
        if (!processedSomethingDuringThisPass && !leftToProcess.isEmpty()) {
            throw new IllegalStateException("Cannot merge descriptors in the correct order; a cycle? " + leftToProcess);
        }
    }
}
Also used : ClassDescriptorRegistry.shouldBeBuiltIn(org.apache.ignite.internal.network.serialization.ClassDescriptorRegistry.shouldBeBuiltIn) Int2ObjectOpenHashMap(it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap) Iterator(java.util.Iterator) Collection(java.util.Collection) ClassDescriptorMessage(org.apache.ignite.internal.network.message.ClassDescriptorMessage) NetworkMessage(org.apache.ignite.network.NetworkMessage) HashMap(java.util.HashMap) NetworkMessagesFactory(org.apache.ignite.internal.network.NetworkMessagesFactory) FieldDescriptorMessage(org.apache.ignite.internal.network.message.FieldDescriptorMessage) MessageSerializer(org.apache.ignite.network.serialization.MessageSerializer) TestOnly(org.jetbrains.annotations.TestOnly) Collectors.toCollection(java.util.stream.Collectors.toCollection) Nullable(org.jetbrains.annotations.Nullable) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) IntOpenHashSet(it.unimi.dsi.fastutil.ints.IntOpenHashSet) MessageDeserializer(org.apache.ignite.network.serialization.MessageDeserializer) Int2ObjectMap(it.unimi.dsi.fastutil.ints.Int2ObjectMap) Map(java.util.Map) IntSet(it.unimi.dsi.fastutil.ints.IntSet) LinkedList(java.util.LinkedList) ClassDescriptorMessage(org.apache.ignite.internal.network.message.ClassDescriptorMessage)

Aggregations

IntOpenHashSet (it.unimi.dsi.fastutil.ints.IntOpenHashSet)2 IntSet (it.unimi.dsi.fastutil.ints.IntSet)2 ClassDescriptorMessage (org.apache.ignite.internal.network.message.ClassDescriptorMessage)2 NetworkMessage (org.apache.ignite.network.NetworkMessage)2 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)1 ChunkedWriteHandler (io.netty.handler.stream.ChunkedWriteHandler)1 Int2ObjectMap (it.unimi.dsi.fastutil.ints.Int2ObjectMap)1 Int2ObjectOpenHashMap (it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap)1 ByteBuffer (java.nio.ByteBuffer)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 Collectors.toCollection (java.util.stream.Collectors.toCollection)1 Collectors.toList (java.util.stream.Collectors.toList)1 NetworkMessagesFactory (org.apache.ignite.internal.network.NetworkMessagesFactory)1 DirectMessageWriter (org.apache.ignite.internal.network.direct.DirectMessageWriter)1 FieldDescriptorMessage (org.apache.ignite.internal.network.message.FieldDescriptorMessage)1