kieker-monitoring / kieker

Kieker's main repository
Apache License 2.0
70 stars 41 forks source link

[KIEKER-1322] Convenience (abstract) implementation for record types with many attributes #2800

Closed rju closed 1 week ago

rju commented 1 week ago

JIRA Issue: KIEKER-1322 Convenience (abstract) implementation for record types with many attributes Original Reporter: Andre van Hoorn


We needed to create a record with many attributes (in this case 64). This is, of course, possible with Kieker --- however quite cumbersome. We hacked the below-listed implementation based on enums and HashMaps, which is certainly not in its final shape (and may contain bugs we will discover ). Also, we have to see how the implementation (including serialization/deserialization; access to attribute values) performs because the underlying raw data to be imported to and processed by Kieker is a number of GBs large.

But: There might be a potential to generalize things.

#!java

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import kieker.common.record.*;

public class SMARTDataRecord extends AbstractMonitoringRecord implements
                IMonitoringRecord.Factory {
        private static final long serialVersionUID = 42L;
        private static final Class<?>[] TYPES = new Class<?>[64];
        static {
                Attributes[] attributes = Attributes.values(); 
                for (int i=0; i<attributes.length; i++) {
                        TYPES[i] = attributes[i].getType();
                }
        }

        public static enum Attributes {
                serial(Integer.class),
                frame(Double.class),
                Hours(Double.class),
                HoursBeforeFail(Double.class),
                Temp1(Double.class),
                Temp2(Double.class),
                Temp3(Double.class),
                Temp4(Double.class),
                FlyHeight1(Double.class),
                FlyHeight2(Double.class),
                FlyHeight3(Double.class),
                FlyHeight4(Double.class),
                GList1(Double.class),
                PList(Double.class),
                Servo1(Double.class),
                Servo2(Double.class),
                Servo3(Double.class),
                CSS(Double.class),
                Servo4(Double.class),
                Servo5(Double.class),
                Servo6(Double.class),
                Reads(Double.class),
                Writes(Double.class),
                ReadError1(Double.class),
                ReadError2(Double.class),
                ReadError3(Double.class),
                ReadError4(Double.class),
                ReadError5(Double.class),
                ReadError6(Double.class),
                ReadError7(Double.class),
                ReadError8(Double.class),
                ReadError9(Double.class),
                ReadError10(Double.class),
                ReadError11(Double.class),
                ReadError12(Double.class),
                ReadError13(Double.class),
                ReadError14(Double.class),
                ReadError15(Double.class),
                ReadError16(Double.class),
                FlyHeight5(Double.class),
                FlyHeight6(Double.class),
                FlyHeight7(Double.class),
                FlyHeight8(Double.class),
                FlyHeight9(Double.class),
                FlyHeight10(Double.class),
                FlyHeight11(Double.class),
                FlyHeight12(Double.class),
                FlyHeight13(Double.class),
                FlyHeight14(Double.class),
                FlyHeight15(Double.class),
                FlyHeight16(Double.class),
                Temp5(Double.class),
                Temp6(Double.class),
                WriteError(Double.class),
                ReadError18(Double.class),
                ReadError19(Double.class),
                Servo7(Double.class),
                Servo8(Double.class),
                ReadError20(Double.class),
                GList2(Double.class),
                GList3(Double.class),
                Servo9(Double.class),
                Servo10(Double.class),
                classValue(boolean.class);

                private final Class<?> type;

                private Attributes(final Class<?> type) {
                        this.type = type;
                }

                public Class<?> getType() {
                        return this.type;
                }

        }

        public static Object UNINITIALIZED = new String("Uninitialized");

        private final ConcurrentHashMap<Attributes,Object> values = new ConcurrentHashMap<Attributes,Object>(Attributes.values().length);

        public SMARTDataRecord(Map<Attributes,Object> values) {
                for (Attributes a : Attributes.values())                {
                        this.values.put(a, values.get(a));
                }
        }

        public SMARTDataRecord() {
                for (int i=0; i<Attributes.values().length; i++) {
                        this.values.put(Attributes.values()[i], UNINITIALIZED);
                }
        }

        public SMARTDataRecord(final Object[] values) {
                AbstractMonitoringRecord.checkArray(values, SMARTDataRecord.TYPES);

                for (int i=0; i<values.length; i++) {
                        this.values.put(Attributes.values()[i], values[i]);
                }
        }

        public final void initFromArray(final Object[] values) {
                throw new UnsupportedOperationException();
        }

        public final Object[] toArray() {
                Object[] returnArray = new Object[SMARTDataRecord.TYPES.length];
                for (int i=0; i<returnArray.length; i++) {
                        returnArray[i] = this.values.get(Attributes.values()[i]);
                }
                return returnArray;
        }

        public Class<?>[] getValueTypes() {
                return SMARTDataRecord.TYPES.clone();
        }

        public Object getAttributeValue(Attributes a) {
                return this.values.get(a);
        }

}
rju commented 1 week ago

author Jan Waller -- Fri, 3 May 2013 08:57:35 +0200

Reiner Jung:
This would be a scenario for model driven generation of records (and probes).

rju commented 1 week ago

author rju -- Wed, 31 Jul 2013 12:42:58 +0200

I will address this in conjunction with the KIEKER-953 Done in a proposal and a discussion ticket.

rju commented 1 week ago

author rju -- Wed, 6 Aug 2014 22:26:19 +0200

The IRL supports arrays already. Maybe this can be fixed. If not, it should be specified how this feature should be realized. For example, associative arrays.

rju commented 1 week ago

author André van Hoorn -- Thu, 4 Sep 2014 16:36:17 +0200

Topic for 1.11.

rju commented 1 week ago

author nils-christian -- Mon, 23 Feb 2015 16:34:46 +0100

We discuss this after the release.

rju commented 1 week ago

author rju -- Fri, 4 Sep 2015 11:25:08 +0200

Is this not the same as KIEKER-1040 Done ?

rju commented 1 week ago

author André van Hoorn -- Thu, 17 Sep 2015 13:31:54 +0200

The issue has been resolved thanks to the IRL and the generator.

See also (comment from a time before we had the IRL):

Replying to [jwa|comment:1]:
> Reiner Jung:
> This would be a scenario for model driven generation of records (and probes).