Class InfluxConnector


  • public class InfluxConnector
    extends java.lang.Object
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.util.concurrent.ThreadPoolExecutor executor  
      static java.lang.String MEASUREMENT  
      protected java.util.concurrent.BlockingQueue<com.influxdb.client.write.Point> pointsQueue  
    • Constructor Summary

      Constructors 
      Constructor Description
      InfluxConnector​(QueryLanguageConfig queryLanguage, java.net.URI url, java.lang.String org, java.lang.String apiKey, java.lang.String bucket, boolean isReadOnly, int poolSize, int maxQueueSize, java.util.function.Consumer<java.lang.Throwable> onWriteError)
      The Constructor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void deactivate()
      Close current InfluxDBClient.
      protected InfluxConnector.InfluxConnection getInfluxConnection()
      Get InfluxDB Connection.
      java.util.SortedMap<java.time.ZonedDateTime,​java.util.SortedMap<ChannelAddress,​com.google.gson.JsonElement>> queryHistoricData​(java.util.Optional<java.lang.Integer> influxEdgeId, java.time.ZonedDateTime fromDate, java.time.ZonedDateTime toDate, java.util.Set<ChannelAddress> channels, Resolution resolution)
      Queries historic data.
      java.util.SortedMap<ChannelAddress,​com.google.gson.JsonElement> queryHistoricEnergy​(java.util.Optional<java.lang.Integer> influxEdgeId, java.time.ZonedDateTime fromDate, java.time.ZonedDateTime toDate, java.util.Set<ChannelAddress> channels)
      Queries historic energy.
      java.util.SortedMap<java.time.ZonedDateTime,​java.util.SortedMap<ChannelAddress,​com.google.gson.JsonElement>> queryHistoricEnergyPerPeriod​(java.util.Optional<java.lang.Integer> influxEdgeId, java.time.ZonedDateTime fromDate, java.time.ZonedDateTime toDate, java.util.Set<ChannelAddress> channels, Resolution resolution)
      Queries historic energy per period.
      void write​(com.influxdb.client.write.Point point)
      Actually write the Point to InfluxDB.
      • Methods inherited from class java.lang.Object

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

      • executor

        protected final java.util.concurrent.ThreadPoolExecutor executor
      • pointsQueue

        protected final java.util.concurrent.BlockingQueue<com.influxdb.client.write.Point> pointsQueue
    • Constructor Detail

      • InfluxConnector

        public InfluxConnector​(QueryLanguageConfig queryLanguage,
                               java.net.URI url,
                               java.lang.String org,
                               java.lang.String apiKey,
                               java.lang.String bucket,
                               boolean isReadOnly,
                               int poolSize,
                               int maxQueueSize,
                               java.util.function.Consumer<java.lang.Throwable> onWriteError)
        The Constructor.
        Parameters:
        queryLanguage - A QueryLanguageConfig
        url - URL of the InfluxDB-Server (http://ip:port)
        org - The organisation; '-' for InfluxDB v1
        apiKey - The apiKey; 'username:password' for InfluxDB v1
        bucket - The bucket name; 'database/retentionPolicy' for InfluxDB v1
        isReadOnly - If true, a 'Read-Only-Mode' is activated, where no data is actually written to the database
        poolSize - the number of threads dedicated to handle the tasks
        maxQueueSize - queue size limit for executor
        onWriteError - A consumer for write-errors
    • Method Detail

      • deactivate

        public void deactivate()
        Close current InfluxDBClient.
      • queryHistoricEnergy

        public java.util.SortedMap<ChannelAddress,​com.google.gson.JsonElement> queryHistoricEnergy​(java.util.Optional<java.lang.Integer> influxEdgeId,
                                                                                                         java.time.ZonedDateTime fromDate,
                                                                                                         java.time.ZonedDateTime toDate,
                                                                                                         java.util.Set<ChannelAddress> channels)
                                                                                                  throws OpenemsError.OpenemsNamedException
        Queries historic energy.
        Parameters:
        influxEdgeId - the unique, numeric Edge-ID; or Empty to query all Edges
        fromDate - the From-Date
        toDate - the To-Date
        channels - the Channels to query
        Returns:
        a map between ChannelAddress and value
        Throws:
        OpenemsException - on error
        OpenemsError.OpenemsNamedException
      • queryHistoricEnergyPerPeriod

        public java.util.SortedMap<java.time.ZonedDateTime,​java.util.SortedMap<ChannelAddress,​com.google.gson.JsonElement>> queryHistoricEnergyPerPeriod​(java.util.Optional<java.lang.Integer> influxEdgeId,
                                                                                                                                                                     java.time.ZonedDateTime fromDate,
                                                                                                                                                                     java.time.ZonedDateTime toDate,
                                                                                                                                                                     java.util.Set<ChannelAddress> channels,
                                                                                                                                                                     Resolution resolution)
                                                                                                                                                              throws OpenemsError.OpenemsNamedException
        Queries historic energy per period.
        Parameters:
        influxEdgeId - the unique, numeric Edge-ID; or Empty to query all Edges
        fromDate - the From-Date
        toDate - the To-Date
        channels - the Channels to query
        resolution - the resolution in seconds
        Returns:
        the historic data as Map
        Throws:
        OpenemsException - on error
        OpenemsError.OpenemsNamedException
      • queryHistoricData

        public java.util.SortedMap<java.time.ZonedDateTime,​java.util.SortedMap<ChannelAddress,​com.google.gson.JsonElement>> queryHistoricData​(java.util.Optional<java.lang.Integer> influxEdgeId,
                                                                                                                                                          java.time.ZonedDateTime fromDate,
                                                                                                                                                          java.time.ZonedDateTime toDate,
                                                                                                                                                          java.util.Set<ChannelAddress> channels,
                                                                                                                                                          Resolution resolution)
                                                                                                                                                   throws OpenemsError.OpenemsNamedException
        Queries historic data.
        Parameters:
        influxEdgeId - the unique, numeric Edge-ID; or Empty to query all Edges
        fromDate - the From-Date
        toDate - the To-Date
        channels - the Channels to query
        resolution - the resolution in seconds
        Returns:
        the historic data as Map
        Throws:
        OpenemsException - on error
        OpenemsError.OpenemsNamedException
      • write

        public void write​(com.influxdb.client.write.Point point)
        Actually write the Point to InfluxDB.
        Parameters:
        point - the InfluxDB Point
        Throws:
        OpenemsException - on error