Class TimeContext

  • All Implemented Interfaces:
    SensorValueListener

    public class TimeContext
    extends Context
    implements SensorValueListener
    This class is a time-based context defined by given start and end times of the time scale when the context is active. The class extends the base class Context.
    In order to receive the time updates, this context should be registered as a SensorValueListener for the sensor providing the time updates. For example, time updates from the TimeSensor {@see eu.h2020.helios_social.core.sensor.ext.TimeSensor}:
          TimeContext timecontext1 = new TimeContext("timecontext1", startTime, endTime);
          TimeSensor timeSensor = new TimeSensor(1000);  // update interval = 1000 milliseconds
          timeSensor.registerValueListener(timecontext1);
          timeSensor.startUpdates();
     
    The context active value is updated using the setActive method. The current value of the context can always be checked using the isActive method of the context.
    If the application needs to track the changes in the active value of the context then the application should implement also the ContextListener interface {@see eu.h2020.helios_social.core.context.ContextListener} and register the context for the listener.
    • Constructor Detail

      • TimeContext

        public TimeContext​(java.lang.String name,
                           long startTime,
                           long endTime)
        Creates a TimeContext
        Parameters:
        name - the name of the context
        startTime - the start moment of the time interval (milliseconds since epoch)
        endTime - the end moment of the time interval (milliseconds since epoch)
      • TimeContext

        public TimeContext​(java.lang.String id,
                           java.lang.String name,
                           long startTime,
                           long endTime)
        Creates a TimeContext
        Parameters:
        id - the identifier of the context
        name - the name of the context
        startTime - the start moment of the time interval (milliseconds since epoch)
        endTime - the end moment of the time interval (milliseconds since epoch)
      • TimeContext

        public TimeContext​(java.lang.String id,
                           java.lang.String name,
                           long startTime,
                           long endTime,
                           int repeat)
        Creates a TimeContext
        Parameters:
        id - the identifier of the context
        name - the name of the context
        startTime - the start moment of the time interval (milliseconds since epoch)
        endTime - the end moment of the time interval (milliseconds since epoch)
        repeat - the repeat interval (REPEAT_NONE,REPEAT_DAILY or REPEAT_WEEKLY)
    • Method Detail

      • getStartTime

        public long getStartTime()
        Returns start time
        Returns:
        the start time (milliseconds since epoch)
      • getEndTime

        public long getEndTime()
        Returns end time
        Returns:
        the end time (milliseconds since epoch)
      • getRepeat

        public int getRepeat()
        Returns repeat interval value (REPEAT_NONE, REPEAT_DAILY, REPEAT_WEEKLY
        Returns:
        the repeat interval
      • receiveValue

        public void receiveValue​(java.lang.Object value)
        Receive updated time values from the time sensor. For example, from the TimeSensor {@see eu.h2020.helios_social.core.sensor.ext.TimeSensor}. In order to receive the time updates, this context should be registered as a SensorValueListener for the sensor.
        Specified by:
        receiveValue in interface SensorValueListener
        Parameters:
        value - the received value