Class LongSignalPort

java.lang.Object
eu.bandm.sig.adlib2.LongSignalPort
All Implemented Interfaces:
AbstractSignalSource, CompilableDataFlow, LongSignalSource, LongSupplier

public class LongSignalPort extends Object implements LongSignalSource
A receptacle for a signal source than can be plugged at runtime, even if compiled.

An instance of this class, when used directly, acts as a dynamic proxy that delegates all method invocations to a pluggable input signal source. The currently plugged input is looked up via getInput() at every delegation event, such that re-plugging via setInput(LongSignalSource) has immediate effect.

If an instance of this class is compiled, usually as a subcomponent of a complex signal network, then the compiled code shares the pluggable state of the original orig, and will dynamically delegate to the input signal source returned by orig.getInput(). Thus even complex network modules with multiple inputs and outputs can be compiled to monolithic code, but configured dynamically, by

  1. creating an interpreted version of the module with inputs realized as ports, i.e. instances of LongSignalSource and its companion classes,
  2. compiling the module,
  3. retaining references to the ports,
  4. plugging the actual inputs into the ports,
  5. using the output signal sources of the compiled version in place of the interpreted one.

The pluggable input signal source can be set to null, which will cause the getAsLong() method of this object to fail at runtime with NullPointerException.

  • Constructor Details

    • LongSignalPort

      public LongSignalPort()
      Creates a new instance with no specified initial input.
    • LongSignalPort

      public LongSignalPort(LongSignalSource input)
      Creates a new instance with the specified initial input.
      Parameters:
      input - the input signal source
  • Method Details

    • getInput

      public LongSignalSource getInput()
      Returns the current input signal source.
    • setInput

      public void setInput(LongSignalSource input)
      Sets the current input signal source.
    • getAsLong

      public long getAsLong()
      Returns the current value of this signal source.

      The value may be either computed on demand, or retrieved from storage.

      Implementations of this method should have no side effect.

      This implementation always delegates to getInput().getAsLong().

      Specified by:
      getAsLong in interface LongSignalSource
      Specified by:
      getAsLong in interface LongSupplier
      Returns:
      the current value of this signal source
    • compileDataFlow

      public Consumer<CompilationContext> compileDataFlow()
      Description copied from interface: LongSignalSource
      Returns a code generator for outputting the value of this entity.

      This implementation generates code to invoke this.getAsLong().

      Specified by:
      compileDataFlow in interface CompilableDataFlow
      Specified by:
      compileDataFlow in interface LongSignalSource