adutra commented on code in PR #3293:
URL: https://github.com/apache/polaris/pull/3293#discussion_r2665517180


##########
runtime/service/src/main/java/org/apache/polaris/service/events/PolarisEvent.java:
##########
@@ -18,10 +18,66 @@
  */
 package org.apache.polaris.service.events;
 
-/** Represents an event emitted by Polaris. */
-public interface PolarisEvent {
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
 
-  PolarisEventType type();
+/**
+ * Represents an event emitted by Polaris. Events have a type, metadata, and a 
map of typed
+ * attributes. Use {@link #builder(PolarisEventType, PolarisEventMetadata)} to 
create instances.
+ */
+public record PolarisEvent(
+    PolarisEventType type, PolarisEventMetadata metadata, Map<AttributeKey<?>, 
Object> attributes) {

Review Comment:
   Nit: exposing a `Map<AttributeKey<?>, Object>` parameter is a bit low-level. 
It would be better to introduce an `AttributeMap` class with type-safe 
operations for get and put. That's what Netty does, cf. 
`io.netty.util.AttributeMap`.
   
   Very simple impl suggestion:
   
   ```java
   public final class AttributeMap {
   
     private final Map<AttributeKey<?>, Object> attributes = new HashMap<>();
   
     @SuppressWarnings("unchecked")
     public <T> Optional<T> get(AttributeKey<T> key) {
       return Optional.ofNullable((T) attributes.get(key));
     }
   
     public <T> T getRequired(AttributeKey<T> key) {
       return get(key)
           .orElseThrow(() -> new IllegalStateException("Required attribute " + 
key + " not found"));
     }
   }
   ```



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