A
- the type of values produced by this signal sourcepublic class SignalPort<A> extends Object implements SignalSource<A>
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(SignalSource)
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
SignalSource
and its companion classes,The pluggable input signal source can be set to null
, which will
cause the get()
method of this object to fail at runtime
with NullPointerException
.
Constructor and Description |
---|
SignalPort(Class<? super A> valueClass,
SignalSource<A> input)
Creates a new instance with the specified initial input.
|
SignalPort(Class<A> valueClass)
Creates a new instance with no specified initial input.
|
Modifier and Type | Method and Description |
---|---|
Consumer<CompilationContext> |
compileDataFlow()
Returns a code generator for outputting the value of this entity.
|
A |
get()
Returns the current value of this signal source.
|
SignalSource<? super A> |
getInput()
Returns the current input signal source.
|
Class<? super A> |
getValueClass()
Returns the type of values produced by this entity.
|
void |
setInput(SignalSource<A> input)
Sets the current input signal source.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
choose, choose, choose, choose, clock, compileMainSignalSource, constant, constant, delayed, delayed, delayedFeedback, delayedFeedback, eq, getConstant, guard, hasConstant, invariant, map, map, neq, power, probe, publishStoredValueVariable, relateWith, sampleAndHold, stored, zipWith
compileDataFlowTo, hasDataFlowIO
public SignalPort(Class<A> valueClass)
valueClass
- the type of values produced by this signal sourcepublic SignalPort(Class<? super A> valueClass, SignalSource<A> input)
valueClass
- the type of values produced by this signal sourceinput
- the input signal sourceClassCastException
- if the type of values produced by the given
(non-null
) input signal source is not a subtype of the type
specified for this signal source.public SignalSource<? super A> getInput()
public void setInput(SignalSource<A> input)
ClassCastException
- if the type of values produced by the given
(non-null
) input signal source is not a subtype of the type
specified for this signal source.getValueClass()
public A get()
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().get()
.
public Class<? super A> getValueClass()
For signals of primitive value type, the result will be the corresponding pseudoclass.
This implementation returns Object.class
. Subclasses
may override this method to provide more specific type
information.
getValueClass
in interface CompilableDataFlow
getValueClass
in interface SignalSource<A>
Class.isPrimitive()
public Consumer<CompilationContext> compileDataFlow()
SignalSource
This implementation generates code to invoke this.get()
.
compileDataFlow
in interface CompilableDataFlow
compileDataFlow
in interface SignalSource<A>