Class SignalBindingFeature

All Implemented Interfaces:
Serializable

public class SignalBindingFeature extends ServerSideFeature
Node feature for binding Signals to various properties of a node.

For internal use only. May be renamed or removed in a future release.

See Also:
  • Field Details

  • Constructor Details

    • SignalBindingFeature

      public SignalBindingFeature(StateNode node)
      Creates a SignalBindingFeature for the given node.
      Parameters:
      node - the node which supports the feature
  • Method Details

    • setBinding

      public void setBinding(String key, Registration registration, Signal<?> signal)
      Sets a binding for the given key.
      Parameters:
      key - the key
      registration - the registration
      signal - the signal
    • setBinding

      public void setBinding(String key, Registration registration, Signal<?> signal, SerializableConsumer<?> writeCallback)
      Sets a binding for the given key with a write callback.
      Parameters:
      key - the key
      registration - the registration
      signal - the signal
      writeCallback - the callback to propagate value changes back, or null for a read-only binding
    • hasBinding

      public boolean hasBinding(String key)
      Checks whether there is a binding for the given key.
      Parameters:
      key - the key
      Returns:
      true if there is a binding for the given key, false otherwise
    • clearBindings

      public void clearBindings(String keyPrefix)
      Clears all bindings with keys starting with the given prefix.
      Parameters:
      keyPrefix - the key prefix
    • removeBinding

      public void removeBinding(String key)
      Removes the binding for the given key.
      Parameters:
      key - the key
    • getWriteCallback

      public <T> SerializableConsumer<T> getWriteCallback(String key)
      Gets the write callback for the given key.
      Type Parameters:
      T - the type of the consumer value
      Parameters:
      key - the key
      Returns:
      the write callback for the given key, or null if no callback is set
    • getSignal

      public <T extends @Nullable Object> Signal<T> getSignal(String key)
      Gets the signal bound to the given key.
      Type Parameters:
      T - the type of the signal value
      Parameters:
      key - the key
      Returns:
      the signal bound to the given key, or null if no signal is bound
    • updateSignalByWriteCallback

      public <T extends @Nullable Object> boolean updateSignalByWriteCallback(String key, T oldValue, T newValue, SerializableBiPredicate<T,T> valueEquals, SerializableConsumer<T> revertCallback)
      Updates the signal value by invoking the write callback for the given key. The callback is expected to update the signal value, and this method will check whether the signal value was updated to the expected new value. If the signal value differs from the expected new value after the callback, the revert callback will be invoked with the current signal value to revert the change.
      Type Parameters:
      T - the type of the signal value
      Parameters:
      key - the key for which to update the signal value
      oldValue - the old value before the update, used for comparison in case of revert
      newValue - the expected new value to be set by the write callback
      valueEquals - a predicate to compare signal values for equality
      revertCallback - a callback to revert the component value to the updated signal's value if the signal value does not match the expected new value after invoking the write callback
      Returns:
      true if the signal value was updated to the expected new value, false if a revert was performed