lhotari commented on code in PR #23808:
URL: https://github.com/apache/pulsar/pull/23808#discussion_r1904512173


##########
pulsar-client/src/main/java/org/apache/pulsar/client/impl/PulsarClientImplementationBindingImpl.java:
##########
@@ -208,21 +219,42 @@ public Schema<LocalDateTime> newLocalDateTimeSchema() {
     public <T> Schema<T> newAvroSchema(SchemaDefinition schemaDefinition) {
         return AvroSchema.of(schemaDefinition);
     }
+    
+    public <T> Schema<T> newAvroSchema(Class<T> pojo) {
+        return (Schema<T>) AVRO_CACHE.computeIfAbsent(pojo, 
+            k -> 
AvroSchema.of(SchemaDefinition.builder().withPojo(pojo).build())).clone();
+    }
 
     public <T extends com.google.protobuf.GeneratedMessageV3> Schema<T> 
newProtobufSchema(
             SchemaDefinition schemaDefinition) {
         return ProtobufSchema.of(schemaDefinition);
     }
 
+    public <T extends com.google.protobuf.GeneratedMessageV3> Schema<T> 
newProtobufSchema(Class<T> clazz) {
+        return (Schema<T>) PROTOBUF_CACHE.computeIfAbsent(clazz,
+            k -> 
ProtobufSchema.of(SchemaDefinition.builder().withPojo(clazz).build())).clone();
+    }
+
+    
     public <T extends com.google.protobuf.GeneratedMessageV3> Schema<T> 
newProtobufNativeSchema(
             SchemaDefinition schemaDefinition) {
         return ProtobufNativeSchema.of(schemaDefinition);
     }
 
+    public <T extends com.google.protobuf.GeneratedMessageV3> Schema<T> 
newProtobufNativeSchema(Class<T> clazz) {
+        return (Schema<T>) PROTOBUF_NATIVE_CACHE.computeIfAbsent(clazz, 
+            k -> 
ProtobufNativeSchema.of(SchemaDefinition.builder().withPojo(clazz).build())).clone();
+    }
+
     public <T> Schema<T> newJSONSchema(SchemaDefinition schemaDefinition) {
         return JSONSchema.of(schemaDefinition);
     }
 
+    public <T> Schema<T> newJSONSchema(Class<T> pojo) {
+         return (Schema<T>) JSON_CACHE.computeIfAbsent(pojo, 
+            k -> 
JsonSchema.of(SchemaDefinition.builder().withPojo(pojo).build())).clone();

Review Comment:
   ```suggestion
               k -> 
newJSONSchema(SchemaDefinition.builder().withPojo(pojo).build())).clone();
   ```



##########
pulsar-client/src/main/java/org/apache/pulsar/client/impl/PulsarClientImplementationBindingImpl.java:
##########
@@ -208,21 +219,42 @@ public Schema<LocalDateTime> newLocalDateTimeSchema() {
     public <T> Schema<T> newAvroSchema(SchemaDefinition schemaDefinition) {
         return AvroSchema.of(schemaDefinition);
     }
+    
+    public <T> Schema<T> newAvroSchema(Class<T> pojo) {
+        return (Schema<T>) AVRO_CACHE.computeIfAbsent(pojo, 
+            k -> 
AvroSchema.of(SchemaDefinition.builder().withPojo(pojo).build())).clone();
+    }
 
     public <T extends com.google.protobuf.GeneratedMessageV3> Schema<T> 
newProtobufSchema(
             SchemaDefinition schemaDefinition) {
         return ProtobufSchema.of(schemaDefinition);
     }
 
+    public <T extends com.google.protobuf.GeneratedMessageV3> Schema<T> 
newProtobufSchema(Class<T> clazz) {
+        return (Schema<T>) PROTOBUF_CACHE.computeIfAbsent(clazz,
+            k -> 
ProtobufSchema.of(SchemaDefinition.builder().withPojo(clazz).build())).clone();
+    }
+
+    
     public <T extends com.google.protobuf.GeneratedMessageV3> Schema<T> 
newProtobufNativeSchema(
             SchemaDefinition schemaDefinition) {
         return ProtobufNativeSchema.of(schemaDefinition);
     }
 
+    public <T extends com.google.protobuf.GeneratedMessageV3> Schema<T> 
newProtobufNativeSchema(Class<T> clazz) {
+        return (Schema<T>) PROTOBUF_NATIVE_CACHE.computeIfAbsent(clazz, 
+            k -> 
ProtobufNativeSchema.of(SchemaDefinition.builder().withPojo(clazz).build())).clone();

Review Comment:
   ```suggestion
               k -> 
newProtobufNativeSchema(SchemaDefinition.builder().withPojo(clazz).build())).clone();
   ```



##########
pulsar-client/src/main/java/org/apache/pulsar/client/impl/PulsarClientImplementationBindingImpl.java:
##########
@@ -84,13 +84,24 @@
 import org.apache.pulsar.common.schema.SchemaInfo;
 import org.apache.pulsar.common.schema.SchemaInfoWithVersion;
 import org.apache.pulsar.common.schema.SchemaType;
-
+import com.google.common.collect.MapMaker;
+import java.util.concurrent.ConcurrentMap;
 /**
  * Helper class for class instantiations and it also contains methods to work 
with schemas.
  */
 @SuppressWarnings("unchecked")
 public final class PulsarClientImplementationBindingImpl implements 
PulsarClientImplementationBinding {
 
+    private static final PulsarClientImplementationBinding IMPLEMENTATION;

Review Comment:
   This field seems unnecessary.



##########
pulsar-client/src/main/java/org/apache/pulsar/client/impl/PulsarClientImplementationBindingImpl.java:
##########
@@ -208,21 +219,42 @@ public Schema<LocalDateTime> newLocalDateTimeSchema() {
     public <T> Schema<T> newAvroSchema(SchemaDefinition schemaDefinition) {
         return AvroSchema.of(schemaDefinition);
     }
+    
+    public <T> Schema<T> newAvroSchema(Class<T> pojo) {
+        return (Schema<T>) AVRO_CACHE.computeIfAbsent(pojo, 
+            k -> 
AvroSchema.of(SchemaDefinition.builder().withPojo(pojo).build())).clone();
+    }
 
     public <T extends com.google.protobuf.GeneratedMessageV3> Schema<T> 
newProtobufSchema(
             SchemaDefinition schemaDefinition) {
         return ProtobufSchema.of(schemaDefinition);
     }
 
+    public <T extends com.google.protobuf.GeneratedMessageV3> Schema<T> 
newProtobufSchema(Class<T> clazz) {
+        return (Schema<T>) PROTOBUF_CACHE.computeIfAbsent(clazz,
+            k -> 
ProtobufSchema.of(SchemaDefinition.builder().withPojo(clazz).build())).clone();

Review Comment:
   ```suggestion
               k -> 
newProtobufSchema(SchemaDefinition.builder().withPojo(clazz).build())).clone();
   ```



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

Reply via email to