quarks.samples.apps

Class ApplicationUtilities

  • java.lang.Object
    • quarks.samples.apps.ApplicationUtilities


  • public class ApplicationUtilities
    extends java.lang.Object
    Some general purpose application configuration driven utilities.

    Utilities include:

    • Get a property name for a sensor configuration item
    • Get a Range value for a sensor range item
    • Log a stream
    • Conditionally trace a stream
    • Constructor Summary

      Constructors 
      Constructor and Description
      ApplicationUtilities(java.util.Properties props) 
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      <T> Range<T> getRange(java.lang.String sensorId, java.lang.String label, java.lang.Class<T> clazz)
      Get the Range for a sensor range configuration item.
      java.lang.String getSensorPropertyName(java.lang.String sensorId, java.lang.String label, java.lang.String kind)
      Get the property name for a sensor's configuration item.
      <T> TStream<T> logStream(TStream<T> stream, java.lang.String eventTag, java.lang.String baseName)
      Log every tuple on the stream using the FileStreams connector.
      <T> TStream<T> traceStream(TStream<T> stream, java.lang.String sensorId, Supplier<java.lang.String> label)
      Trace a stream to System.out if the sensor id's "label" has been configured to enable tracing.
      <T> TStream<T> traceStream(TStream<T> stream, Supplier<java.lang.String> label)
      Trace a stream to System.out if the "label" has been configured to enable tracing.
      • Methods inherited from class java.lang.Object

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

      • ApplicationUtilities

        public ApplicationUtilities(java.util.Properties props)
    • Method Detail

      • traceStream

        public <T> TStream<T> traceStream(TStream<T> stream,
                                          java.lang.String sensorId,
                                          Supplier<java.lang.String> label)
        Trace a stream to System.out if the sensor id's "label" has been configured to enable tracing.

        If tracing has not been enabled in the config, the topology will not be augmented to trace the stream.

        Parameters:
        stream - the stream to trace
        label - some unique label
        Returns:
        the input stream
      • traceStream

        public <T> TStream<T> traceStream(TStream<T> stream,
                                          Supplier<java.lang.String> label)
        Trace a stream to System.out if the "label" has been configured to enable tracing.

        If tracing has not been enabled in the config, the topology will not be augmented to trace the stream.

        Parameters:
        stream - the stream to trace
        label - some unique label
        Returns:
        the input stream
      • getSensorPropertyName

        public java.lang.String getSensorPropertyName(java.lang.String sensorId,
                                                      java.lang.String label,
                                                      java.lang.String kind)
        Get the property name for a sensor's configuration item.
        Parameters:
        sensorId - the sensor's id
        label - the label for an instance of "kind" (e.g., "tempThreshold")
        kind - the kind of configuration item (e.g., "range")
        Returns:
        the configuration property name
      • getRange

        public <T> Range<T> getRange(java.lang.String sensorId,
                                     java.lang.String label,
                                     java.lang.Class<T> clazz)
        Get the Range for a sensor range configuration item.
        Parameters:
        sensorId - the sensor's id
        label - the range's label
        clazz - the Range's type (e.g., Integer.class)
        Returns:
        the Range
      • logStream

        public <T> TStream<T> logStream(TStream<T> stream,
                                        java.lang.String eventTag,
                                        java.lang.String baseName)
        Log every tuple on the stream using the FileStreams connector.

        The logs are added to the directory as specified by the "application.log.dir" property. The directory will be created as needed.

        The "active" (open / being written) log file name is .<baseName>.
        Completed stable logs have a name of <baseName>_YYYYMMDD_HHMMSS.

        The log entry format being used is: [<date>] [<eventTag>] <tuple>.toString()

        See FileStreams.textFileWriter(TStream, quarks.function.Supplier, quarks.function.Supplier)

        Parameters:
        stream - the TStream
        baseName - the base log name
        eventTag - a tag that gets added to the log entry
        Returns:
        the input stream

Copyright IBM 2015,2016 - 2f6ad0e-20160307-0902