igalshilman commented on a change in pull request #152:
URL: https://github.com/apache/flink-statefun/pull/152#discussion_r492318196



##########
File path: 
statefun-flink/statefun-flink-core/src/main/java/org/apache/flink/statefun/flink/core/message/MessageFactoryKey.java
##########
@@ -0,0 +1,43 @@
+package org.apache.flink.statefun.flink.core.message;
+
+import java.io.Serializable;
+import java.util.Objects;
+
+public class MessageFactoryKey implements Serializable {

Review comment:
       Can this be final?

##########
File path: 
statefun-flink/statefun-flink-core/src/main/java/org/apache/flink/statefun/flink/core/message/MessageFactoryKey.java
##########
@@ -0,0 +1,43 @@
+package org.apache.flink.statefun.flink.core.message;
+
+import java.io.Serializable;
+import java.util.Objects;
+
+public class MessageFactoryKey implements Serializable {
+  private static final long serialVersionUID = 1L;
+
+  private final MessageFactoryType type;
+  private final String customPayloadSerializerClassName;
+
+  private MessageFactoryKey(MessageFactoryType type, String 
customPayloadSerializerClassName) {
+    this.type = type;

Review comment:
       Can this be: `this.type = Objects.requireNonNull(type);`

##########
File path: 
statefun-flink/statefun-flink-core/src/main/java/org/apache/flink/statefun/flink/core/StatefulFunctionsConfigValidator.java
##########
@@ -61,4 +64,26 @@ private static void 
validateParentFirstClassloaderPatterns(Configuration configu
     }
     return parentFirstClassloaderPatterns;
   }
+
+  private static void validateCustomPayloadSerializerClassName(Configuration 
configuration) {
+
+    MessageFactoryType factoryType =
+        configuration.get(StatefulFunctionsConfig.USER_MESSAGE_SERIALIZER);
+    String customPayloadSerializerClassName =
+        
configuration.get(StatefulFunctionsConfig.USER_MESSAGE_CUSTOM_PAYLOAD_SERIALIZER_CLASS);
+
+    if (factoryType == MessageFactoryType.WITH_CUSTOM_PAYLOADS) {
+      if 
(StringUtils.isNullOrWhitespaceOnly(customPayloadSerializerClassName)) {

Review comment:
       I think that you are right, let's leave that as it is 👍 

##########
File path: 
statefun-flink/statefun-flink-core/src/main/java/org/apache/flink/statefun/flink/core/message/MessageFactoryKey.java
##########
@@ -0,0 +1,43 @@
+package org.apache.flink.statefun.flink.core.message;
+
+import java.io.Serializable;
+import java.util.Objects;
+
+public class MessageFactoryKey implements Serializable {
+  private static final long serialVersionUID = 1L;
+
+  private final MessageFactoryType type;
+  private final String customPayloadSerializerClassName;
+
+  private MessageFactoryKey(MessageFactoryType type, String 
customPayloadSerializerClassName) {
+    this.type = type;
+    this.customPayloadSerializerClassName = customPayloadSerializerClassName;
+  }
+
+  public static MessageFactoryKey forType(
+      MessageFactoryType type, String customPayloadSerializerClassName) {
+    return new MessageFactoryKey(type, customPayloadSerializerClassName);
+  }
+
+  public MessageFactoryType getType() {
+    return this.type;
+  }
+
+  public String getCustomPayloadSerializerClassName() {

Review comment:
       That is a good point!
   In that case, what do you think about making this method return an 
`Optional<String>`,
   and version 2 would write an extra byte to indicate if the optional is 
present or not.
   
   Something along the lines:
   ```
   if (className.isPresent()) {
      out.writeBooolean(true);
      out.writeUtf8String(className.get());
   } else {
      out.writeBooolean(false);
   }
   ```
   

##########
File path: 
statefun-flink/statefun-flink-core/src/main/java/org/apache/flink/statefun/flink/core/message/MessageFactoryKey.java
##########
@@ -0,0 +1,43 @@
+package org.apache.flink.statefun.flink.core.message;
+
+import java.io.Serializable;
+import java.util.Objects;
+
+public class MessageFactoryKey implements Serializable {
+  private static final long serialVersionUID = 1L;
+
+  private final MessageFactoryType type;
+  private final String customPayloadSerializerClassName;
+
+  private MessageFactoryKey(MessageFactoryType type, String 
customPayloadSerializerClassName) {
+    this.type = type;
+    this.customPayloadSerializerClassName = customPayloadSerializerClassName;
+  }
+
+  public static MessageFactoryKey forType(
+      MessageFactoryType type, String customPayloadSerializerClassName) {
+    return new MessageFactoryKey(type, customPayloadSerializerClassName);
+  }
+
+  public MessageFactoryType getType() {
+    return this.type;
+  }
+
+  public String getCustomPayloadSerializerClassName() {

Review comment:
       > 
   > So the serialized format would already seem to be what you've requested! 
But if you'd prefer it get written without using 
`StringUtils.writeNullableString`, I'm happy to make that change.
   
   Oh I see. My original thinking here was to prevent a future NPE by someone 
who would expect (mistakenly) that 
`messageFactoryKey.getCustomPayloadSerializerClassName()`  would always return 
a class name. Making the method return `Optional` would signal to the user of 
that class that it is not necessarily true.
   
   And regarding `StringUtils` I'd rather to keep that logic local to the 
`Snapshot` class, to protect from accidental change in `StringUtils`.
   
    
   




----------------------------------------------------------------
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]


Reply via email to