Add ObjectContext class JEP-349-branch
authoregahlin
Mon, 08 Jul 2019 23:10:56 +0200
branchJEP-349-branch
changeset 57461 b72401c57125
parent 57460 bcbc53560c77
child 57463 e8d4ec2bf480
Add ObjectContext class
src/jdk.jfr/share/classes/jdk/jfr/consumer/ObjectContext.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/jdk.jfr/share/classes/jdk/jfr/consumer/ObjectContext.java	Mon Jul 08 23:10:56 2019 +0200
@@ -0,0 +1,39 @@
+package jdk.jfr.consumer;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import jdk.jfr.EventType;
+import jdk.jfr.ValueDescriptor;
+
+final class ObjectContext {
+    private final Map<ValueDescriptor, ObjectContext> contextLookup;
+
+    final EventType eventType;
+    final List<ValueDescriptor> fields;
+    final TimeConverter timeConverter;
+
+    public ObjectContext(EventType eventType, List<ValueDescriptor> fields, TimeConverter timeConverter) {
+        this.contextLookup = new HashMap<>();
+        this.eventType = eventType;
+        this.fields = fields;
+        this.timeConverter = timeConverter;
+    }
+
+    private ObjectContext(ObjectContext root, ValueDescriptor desc) {
+        this.eventType = root.eventType;
+        this.contextLookup = root.contextLookup;
+        this.timeConverter = root.timeConverter;
+        this.fields = desc.getFields();
+    }
+
+    public ObjectContext getInstance(ValueDescriptor desc) {
+        ObjectContext h = contextLookup.get(desc);
+        if (h == null) {
+            h = new ObjectContext(this, desc);
+            contextLookup.put(desc, h);
+        }
+        return h;
+    }
+}
\ No newline at end of file