Class FlappingEventProvider<V>

java.lang.Object
com.pi4j.crowpi.components.events.FlappingEventProvider<V>
Type Parameters:
V - Type of value which gets passed to event handlers.
All Implemented Interfaces:
EventHandler<V>

public class FlappingEventProvider<V> extends Object implements EventHandler<V>
Generic event provider to trigger a SimpleEventHandler once a value has flapped between two values for a couple times. The threshold once an event should be dispatched as well as the max idle time can be configured. Any instance should be registered in a component using EventProvider.addListener(EventHandler) to actually monitor value changes.
  • Constructor Details

    • FlappingEventProvider

      public FlappingEventProvider(V valueA, V valueB)
      Initializes a new FlappingEventProvider with the two given values. A default maximum idle time between transitions will be used by this method.
      Parameters:
      valueA - First value to watch for transitions to second value
      valueB - Second value to watch for transitions to first value
      See Also:
    • FlappingEventProvider

      public FlappingEventProvider(long maxIdleTime, V valueA, V valueB)
      Initializes a new FlappingEventProvider with the two given values. Whenever the value changes from A to B or vice-versa, an internal counter gets increased. Once a certain threshold has been reached, a user-specified handler will be called.
      Parameters:
      maxIdleTime - Maximum idle time between transitions in milliseconds before counter is reset
      valueA - First value to watch for transitions to second value
      valueB - Second value to watch for transitions to first value
  • Method Details

    • setOptions

      public void setOptions(int threshold, SimpleEventHandler handler)
      Sets the threshold and event handler for this instance. These changes will immediately apply and the counter does not get reset.
      Parameters:
      threshold - Threshold before event should be fired
      handler - Event handler to call, null to disable
    • handle

      public void handle(V value)
      Implementation of EventHandler which must be added as a listener for this event provider to work. It will track all state changes between value A and B and automatically resets or fires the handler accordingly.
      Specified by:
      handle in interface EventHandler<V>
      Parameters:
      value - Event value