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;
}
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);
}
}
}
Aggregations