src/jdk.jfr/share/classes/jdk/jfr/consumer/ObjectFactory.java
branchJEP-349-branch
changeset 57460 bcbc53560c77
parent 57360 5d043a159d5c
equal deleted inserted replaced
57459:df39f8d8f4d6 57460:bcbc53560c77
    23  * questions.
    23  * questions.
    24  */
    24  */
    25 
    25 
    26 package jdk.jfr.consumer;
    26 package jdk.jfr.consumer;
    27 
    27 
    28 import java.util.List;
       
    29 
       
    30 import jdk.jfr.ValueDescriptor;
       
    31 import jdk.jfr.internal.Type;
    28 import jdk.jfr.internal.Type;
    32 
    29 
    33 /**
    30 /**
    34  * Abstract factory for creating specialized types
    31  * Abstract factory for creating specialized types
    35  */
    32  */
    63             return RecordedClass.createFactory(type, timeConverter);
    60             return RecordedClass.createFactory(type, timeConverter);
    64         }
    61         }
    65         return null;
    62         return null;
    66     }
    63     }
    67 
    64 
    68     private final List<ValueDescriptor> valueDescriptors;
    65     private final ObjectContext objectContext;
    69 
    66 
    70     ObjectFactory(Type type) {
    67     ObjectFactory(Type type, TimeConverter timeConverter) {
    71         this.valueDescriptors = type.getFields();
    68         this.objectContext = new ObjectContext(null, type.getFields(), timeConverter);
    72     }
    69     }
    73 
    70 
    74     T createObject(long id, Object value) {
    71     T createObject(long id, Object value) {
    75         if (value == null) {
    72         if (value == null) {
    76             return null;
    73             return null;
    77         }
    74         }
    78         if (value instanceof Object[]) {
    75         if (value instanceof Object[]) {
    79             return createTyped(valueDescriptors, id, (Object[]) value);
    76             return createTyped(objectContext, id, (Object[]) value);
    80         }
    77         }
    81         throw new InternalError("Object factory must have struct type. Type was " + value.getClass().getName());
    78         throw new InternalError("Object factory must have struct type. Type was " + value.getClass().getName());
    82     }
    79     }
    83 
    80 
    84     abstract T createTyped(List<ValueDescriptor> valueDescriptors, long id, Object[] values);
    81     abstract T createTyped(ObjectContext objectContextm, long id, Object[] values);
    85 }
    82 }