Vladsz83 commented on code in PR #13421:
URL: https://github.com/apache/ignite/pull/13421#discussion_r3692005736
##########
modules/core/src/main/java/org/apache/ignite/internal/plugin/AbstractMarshallableMessageFactoryProvider.java:
##########
@@ -79,52 +79,72 @@ private static <T extends Message> void
register(IgniteMessageFactory factory, C
if (NonMarshallableMessage.class.isAssignableFrom(cls))
marshaller = null;
else if (MarshallableMessage.class.isAssignableFrom(cls))
- marshaller = requireGenerated(cls, "Marshaller", marsh);
+ marshaller = require(loadMarshaller(cls, marsh), cls,
"Marshaller");
else
- marshaller = loadGenerated(cls, "Marshaller", marsh);
+ marshaller = loadMarshaller(cls, marsh);
// Deployers are generated for GridCacheMessage subclasses only, so
the class lookup is skipped for the rest;
// a DeployableMessage left without a deployer is then rejected at
registration.
GridCacheMessageDeployer<?> deployer =
GridCacheMessage.class.isAssignableFrom(cls)
- ? loadGenerated(cls, "Deployer", marsh)
+ ? loadGenerated(cls, "Deployer")
: null;
factory.register(id, serializer, marshaller, deployer);
}
- /** Loads the generated companion like {@link #loadGenerated}, failing
fast when it is missing. */
- private static <T> T requireGenerated(Class<?> cls, String suffix,
Marshaller marsh) {
- T res = loadGenerated(cls, suffix, marsh);
-
- if (res == null) {
+ /** @return {@code companion}, failing fast when it is missing. */
+ private static <T> T require(@Nullable T companion, Class<?> cls, String
suffix) {
+ if (companion == null) {
throw new IgniteException("No " + cls.getSimpleName() + suffix + "
found for " + cls.getName() +
". Either the class is not processed by codegen or the
generated sources are stale," +
" try 'mvn clean install'.");
}
- return res;
+ return companion;
}
/**
- * Instantiates the generated companion class {@code
<message>Serializer/Marshaller/Deployer}, or returns
- * {@code null} when it does not exist. The sole declared constructor is
used, passing {@code marsh} when it takes
- * one. Constructor lookups, including missing companions, are cached per
message class in {@link #COMPANIONS}.
+ * Instantiates the generated companion class {@code
<message>Serializer/Deployer}, or returns {@code null} when it
+ * does not exist. Neither takes a marshaller: the serializer writes the
wire fields as they are, and the deployer
+ * only walks cache objects.
*/
@SuppressWarnings("unchecked")
- private static <T> @Nullable T loadGenerated(Class<?> cls, String suffix,
Marshaller marsh) {
+ private static <T> @Nullable T loadGenerated(Class<?> cls, String suffix) {
Constructor<?> ctor = COMPANIONS.get(cls).ctor(suffix);
if (ctor == null)
return null;
+ assert ctor.getParameterCount() == 0 : cls.getSimpleName() + suffix +
" must have a no-arg constructor";
+
try {
- return (T)(ctor.getParameterCount() == 0 ? ctor.newInstance() :
ctor.newInstance(marsh));
+ return (T)ctor.newInstance();
}
catch (Exception e) {
throw new IgniteException("Failed to instantiate " +
cls.getSimpleName() + suffix, e);
}
}
+ /**
+ * Instantiates the generated {@code <message>Marshaller}, or returns
{@code null} when it does not exist. The
+ * generator gives it a {@code Marshaller} constructor only when the
message has fields to marshal with one;
+ * otherwise the companion just walks nested messages and cache objects,
and takes no arguments.
+ */
+ @SuppressWarnings("unchecked")
+ private static <T> @Nullable T loadMarshaller(Class<?> cls, Marshaller
marsh) {
Review Comment:
This new method is nearly `loadGenerated(Class<?> cls, String suffix)`. The
difference is faint. Let's join them back
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]