IGNITE-27414 : Use MessageSerializer for TcpDiscoveryClientReconnectMessage v2#12821
IGNITE-27414 : Use MessageSerializer for TcpDiscoveryClientReconnectMessage v2#12821Vladsz83 wants to merge 40 commits intoapache:masterfrom
Conversation
This reverts commit 4adf01a.
This reverts commit 1064805.
# Conflicts: # modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/DiscoveryMessageFactory.java # modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoveryIoSession.java
…ssage # Conflicts: # modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/DiscoveryMessageFactory.java
…ssage # Conflicts: # modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/messages/TcpDiscoveryNodeAddFinishedMessage.java
…nectMessage_v2' into IGNITE-27414-TcpDiscoveryClientReconnectMessage_v2 # Conflicts: # modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoveryIoSession.java
shishkovilja
left a comment
There was a problem hiding this comment.
- I suggest to revert unnecessary replacements of getters and setters. It can be done (if necessary) in a separate pull request.
- I suggest alternate approach of invoking marshalling methods. Let's add wrappers to
DiscoveryMessageFactory. Code sample:
public class DiscoveryMessageFactory implements MessageFactoryProvider {
private final Marshaller marsh;
private final ClassLoader clsLdr;
/**
* @param marsh Marshaller.
* @param clsLdr Class loader.
*/
public DiscoveryMessageFactory(Marshaller marsh, ClassLoader clsLdr) {
this.marsh = marsh;
this.clsLdr = clsLdr;
}
/** {@inheritDoc} */
@Override public void registerAll(MessageFactory factory) {
factory.register((short)-108, TcpDiscoveryCollectionMessage::new, wrap(new TcpDiscoveryCollectionMessageSerializer()));
...
}
/** */
private MarshallingSerializer wrap(MessageSerializer delegate) {
return new MarshallingSerializer(delegate, marsh, clsLdr);
}
/** */
private static class MarshallingSerializer implements MessageSerializer {
/** */
private final MessageSerializer delegate;
/** */
private final Marshaller marsh;
/** */
private final ClassLoader clsLdr;
/** */
private MarshallingSerializer(MessageSerializer delegate, Marshaller marsh, ClassLoader clsLdr) {
this.delegate = delegate;
this.marsh = marsh;
this.clsLdr = clsLdr;
}
/** {@inheritDoc} */
@Override public boolean writeTo(Message msg, MessageWriter writer) {
boolean res = delegate.writeTo(msg, writer);
if (res)
((TcpDiscoveryMarshallableMessage)msg).prepareMarshal(marsh);
return res;
}
/** {@inheritDoc} */
@Override public boolean readFrom(Message msg, MessageReader reader) {
boolean res = delegate.readFrom(msg, reader);
if (res)
((TcpDiscoveryMarshallableMessage)msg).finishUnmarshal(marsh, clsLdr);
return res;
}
}
In such case we call marshalling only for those messages for which wrappers was registered in the factory.
Unfortunately, such leads to propagation of context to factory. Also, failures of IgniteDiscoveryMessageSerializationTest caused by calls of marshliing methods should be fixed (see IgniteIoCommunicationMessageSerializationTest.TestIoMessageReader#readByteArray in order to solve problem).
| @Override public MessageSerializer serializer(short type) { | ||
| MessageSerializer serializer = mf.serializer(type); | ||
|
|
||
| return new MessageSerializer() { |
There was a problem hiding this comment.
Such approach leads to situation, that we create new serializer each time, when we writing and reading message. I suggest to use seralizers from MessageFactory, but for marshallable message we can add a wrapper.
…ssage_v2 # Conflicts: # modules/core/src/main/java/org/apache/ignite/internal/direct/DirectMessageReader.java # modules/core/src/main/java/org/apache/ignite/internal/direct/DirectMessageWriter.java
Didn't catch you. This test seems to work in current PR. |
This interferes with the new clear-message-methods strategy indroduced by @anton-vinogradov in the previous tickets. @anton-vinogradov asked me not to use get/set methods in new messages refactored. |
Thank you for submitting the pull request to the Apache Ignite.
In order to streamline the review of the contribution
we ask you to ensure the following steps have been taken:
The Contribution Checklist
The description explains WHAT and WHY was made instead of HOW.
The following pattern must be used:
IGNITE-XXXX Change summarywhereXXXX- number of JIRA issue.(see the Maintainers list)
the
green visaattached to the JIRA ticket (see TC.Bot: Check PR)Notes
If you need any help, please email dev@ignite.apache.org or ask anу advice on http://asf.slack.com #ignite channel.