Class MetricStore


  • public final class MetricStore
    extends java.lang.Object
    MetricStore stores metric data which will be used by web visualize interface, logging, and so on. All metric classes should be JSON-serializable by ObjectMapper.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void dumpAllMetricToFile​(java.lang.String filePath)
      Same as dumpAllMetricToJson(), but this will save it to the file.
      java.lang.String dumpAllMetricToJson()
      Dumps JSON-serialized string of all stored metric.
      <T extends Metric>
      java.lang.String
      dumpMetricToJson​(java.lang.Class<T> metricClass)
      Dumps JSON-serialized string of specific metric.
      <T extends Metric>
      java.lang.Class<T>
      getMetricClassByName​(java.lang.String className)
      Get the metric class by its name.
      <T extends Metric>
      java.util.Map<java.lang.String,​java.lang.Object>
      getMetricMap​(java.lang.Class<T> metricClass)
      Fetch metric map by its metric class instance.
      <T extends Metric>
      T
      getMetricWithId​(java.lang.Class<T> metricClass, java.lang.String id)
      Fetch metric by its metric class instance and its id.
      <T extends Metric>
      T
      getOrCreateMetric​(java.lang.Class<T> metricClass, java.lang.String id)
      Same as getMetricWithId(), but if there is no such metric, it will try to create new metric object using its constructor, which takes an id as a parameter.
      static MetricStore getStore()
      Getter for singleton instance.
      static MetricStore newInstance()
      Static class for creating a new instance.
      <T extends Metric>
      void
      putMetric​(T metric)
      Store a metric object.
      void saveOptimizationMetricsToDB​(java.lang.String address, java.lang.String jobId, java.lang.String dbId, java.lang.String dbPasswd)
      Save the job metrics for the optimization to the DB, in the form of LibSVM, to a remote DB, if applicable.
      <T extends Metric>
      void
      triggerBroadcast​(java.lang.Class<T> metricClass, java.lang.String id)
      Send changed metric data to MetricBroadcaster, which will broadcast it to all active WebSocket sessions.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • getStore

        public static MetricStore getStore()
        Getter for singleton instance.
        Returns:
        MetricStore object.
      • newInstance

        public static MetricStore newInstance()
        Static class for creating a new instance.
        Returns:
        a new MetricStore instance.
      • getMetricClassByName

        public <T extends Metric> java.lang.Class<T> getMetricClassByName​(java.lang.String className)
        Get the metric class by its name.
        Type Parameters:
        T - type of the metric.
        Parameters:
        className - the name of the class.
        Returns:
        the class of the type of the metric.
      • putMetric

        public <T extends Metric> void putMetric​(T metric)
        Store a metric object. Metric object should implement Metric interface. This method will store a metric into a Map, which have metric's id as its key.
        Type Parameters:
        T - class of metric
        Parameters:
        metric - metric object.
      • getMetricWithId

        public <T extends Metric> T getMetricWithId​(java.lang.Class<T> metricClass,
                                                    java.lang.String id)
        Fetch metric by its metric class instance and its id.
        Type Parameters:
        T - class of metric
        Parameters:
        metricClass - class instance of metric.
        id - metric id, which can be fetched by getPlanId() method.
        Returns:
        a metric object.
      • getMetricMap

        public <T extends Metric> java.util.Map<java.lang.String,​java.lang.Object> getMetricMap​(java.lang.Class<T> metricClass)
        Fetch metric map by its metric class instance.
        Type Parameters:
        T - class of metric
        Parameters:
        metricClass - class instance of metric.
        Returns:
        a metric object.
      • getOrCreateMetric

        public <T extends Metric> T getOrCreateMetric​(java.lang.Class<T> metricClass,
                                                      java.lang.String id)
        Same as getMetricWithId(), but if there is no such metric, it will try to create new metric object using its constructor, which takes an id as a parameter.
        Type Parameters:
        T - class of metric
        Parameters:
        metricClass - class of metric.
        id - metric id, which can be fetched by getPlanId() method.
        Returns:
        a metric object. If there was no such metric, newly create one.
      • dumpMetricToJson

        public <T extends Metric> java.lang.String dumpMetricToJson​(java.lang.Class<T> metricClass)
                                                             throws java.io.IOException
        Dumps JSON-serialized string of specific metric.
        Type Parameters:
        T - type of the metric to dump
        Parameters:
        metricClass - class of metric.
        Returns:
        dumped JSON string of all metric.
        Throws:
        java.io.IOException - when failed to write json.
      • dumpAllMetricToJson

        public java.lang.String dumpAllMetricToJson()
                                             throws java.io.IOException
        Dumps JSON-serialized string of all stored metric.
        Returns:
        dumped JSON string of all metric.
        Throws:
        java.io.IOException - when failed to write file.
      • dumpAllMetricToFile

        public void dumpAllMetricToFile​(java.lang.String filePath)
        Same as dumpAllMetricToJson(), but this will save it to the file.
        Parameters:
        filePath - path to dump JSON.
      • saveOptimizationMetricsToDB

        public void saveOptimizationMetricsToDB​(java.lang.String address,
                                                java.lang.String jobId,
                                                java.lang.String dbId,
                                                java.lang.String dbPasswd)
        Save the job metrics for the optimization to the DB, in the form of LibSVM, to a remote DB, if applicable. The metrics are as follows: the JCT (duration), and the IR DAG execution properties.
        Parameters:
        address - Address to the DB.
        jobId - Job ID, of which we record the metrics.
        dbId - the ID of the DB.
        dbPasswd - the Password to the DB.
      • triggerBroadcast

        public <T extends Metric> void triggerBroadcast​(java.lang.Class<T> metricClass,
                                                        java.lang.String id)
        Send changed metric data to MetricBroadcaster, which will broadcast it to all active WebSocket sessions. This method should be called manually if you want to send changed metric data to the frontend client. Also this method is synchronized.
        Type Parameters:
        T - type of the metric to broadcast
        Parameters:
        metricClass - class of the metric.
        id - id of the metric.