- java.lang.Object
-
- org.praxislive.code.CodeDelegate
-
- Direct Known Subclasses:
CodeContainerDelegate
,CodeRootDelegate
,DefaultCodeDelegate
public abstract class CodeDelegate extends Object
CodeDelegate is the base class for all user rewritable code.
-
-
Constructor Summary
Constructors Constructor Description CodeDelegate()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Async<Call>
ask(ControlAddress destination, Object... args)
Call a Control.Async<Call>
ask(ControlAddress destination, List<Value> args)
Call a Control.<T,R>
Async<R>async(T input, Async.Task<T,R> task)
Run a task asynchronously and outside of the component context.<T> Optional<T>
find(Class<T> type)
Search for an instance of the given type.Lookup
getLookup()
Return a Lookup for finding instances of features.boolean
isLoggable(LogLevel level)
Check whether the messages at the given log level are being sent.void
log(LogLevel level, Class<? extends Exception> type, String msg)
Send a log message with associated Exception type.void
log(LogLevel level, Exception ex)
Send a log message with associated Exception type.void
log(LogLevel level, Exception ex, String msg)
Send a log message with associated Exception.void
log(LogLevel level, String msg)
Send a log message.long
millis()
The current time in milliseconds since the root was started.ComponentAddress
self()
Get this component's address.ControlAddress
self(String control)
Get the address of a control on this component.void
tell(ControlAddress destination, double value)
Send a message to a Control.void
tell(ControlAddress destination, String value)
Send a message to a Control.void
tell(ControlAddress destination, Value value)
Send a message to a Control.void
tellIn(double seconds, ControlAddress destination, double value)
Send a message to a Control in the given number of seconds or fractions of second from now.void
tellIn(double seconds, ControlAddress destination, String value)
Send a message to a Control in the given number of seconds or fractions of second from now.void
tellIn(double seconds, ControlAddress destination, Value value)
Send a message to a Control in the given number of seconds or fractions of second from now.long
time()
The current clocktime in nanoseconds.void
transmit(String componentID, String portID, double value)
Send a value to a port on another component.void
transmit(String componentID, String portID, String value)
Send a value to a port on another component.void
transmit(String componentID, String portID, Value value)
Send a value to a port on another component.
-
-
-
Method Detail
-
log
public final void log(LogLevel level, String msg)
Send a log message.- Parameters:
level
-msg
-
-
log
public final void log(LogLevel level, Exception ex)
Send a log message with associated Exception type.- Parameters:
level
-ex
-
-
log
public final void log(LogLevel level, Exception ex, String msg)
Send a log message with associated Exception.- Parameters:
level
-ex
-msg
-
-
log
public final void log(LogLevel level, Class<? extends Exception> type, String msg)
Send a log message with associated Exception type.- Parameters:
level
-type
-msg
-
-
isLoggable
public final boolean isLoggable(LogLevel level)
Check whether the messages at the given log level are being sent.- Parameters:
level
-- Returns:
-
transmit
public final void transmit(String componentID, String portID, String value)
Send a value to a port on another component. The other component must have the same parent.- Parameters:
componentID
- ID of the other componentportID
- ID of the port on the other componentvalue
-
-
transmit
public final void transmit(String componentID, String portID, Value value)
Send a value to a port on another component. The other component must have the same parent.- Parameters:
componentID
- ID of the other componentportID
- ID of the port on the other componentvalue
-
-
transmit
public final void transmit(String componentID, String portID, double value)
Send a value to a port on another component. The other component must have the same parent.- Parameters:
componentID
- ID of the other componentportID
- ID of the port on the other componentvalue
-
-
tell
public final void tell(ControlAddress destination, String value)
Send a message to a Control.- Parameters:
destination
- address of controlvalue
- message value
-
tell
public final void tell(ControlAddress destination, double value)
Send a message to a Control.- Parameters:
destination
- address of controlvalue
- message value
-
tell
public final void tell(ControlAddress destination, Value value)
Send a message to a Control.- Parameters:
destination
- address of controlvalue
- message value
-
tellIn
public final void tellIn(double seconds, ControlAddress destination, String value)
Send a message to a Control in the given number of seconds or fractions of second from now.- Parameters:
seconds
- from nowdestination
- address of controlvalue
- message value
-
tellIn
public final void tellIn(double seconds, ControlAddress destination, double value)
Send a message to a Control in the given number of seconds or fractions of second from now.- Parameters:
seconds
- from nowdestination
- address of controlvalue
- message value
-
tellIn
public final void tellIn(double seconds, ControlAddress destination, Value value)
Send a message to a Control in the given number of seconds or fractions of second from now.- Parameters:
seconds
- from nowdestination
- address of controlvalue
- message value
-
ask
public final Async<Call> ask(ControlAddress destination, List<Value> args)
Call a Control. The returnedAsync
result will be completed by the responseCall
if successful, or the resulting error. UseCall.args
to extract the result.- Parameters:
destination
- address of controlargs
- call arguments- Returns:
- async response
-
ask
public final Async<Call> ask(ControlAddress destination, Object... args)
Call a Control. The returnedAsync
result will be completed by the responseCall
if successful, or the resulting error. UseCall.args
to extract the result.- Parameters:
destination
- address of controlargs
- call arguments- Returns:
- async response
-
async
public final <T,R> Async<R> async(T input, Async.Task<T,R> task)
Run a task asynchronously and outside of the component context. All data required to complete the task should be passed in as input data. The task should not access any other data from the component during execution. If multiple inputs are required, considerList.of(java.lang.Object...)
.The returned
Async
will be completed by the task result, or the resulting error.- Type Parameters:
T
- type of inputR
- type of result- Parameters:
input
- input datatask
- async task- Returns:
- async result
-
self
public final ComponentAddress self()
Get this component's address.- Returns:
- address of self
-
self
public final ControlAddress self(String control)
Get the address of a control on this component.- Parameters:
control
- id of control- Returns:
- address of control
-
getLookup
public Lookup getLookup()
Return a Lookup for finding instances of features.- Returns:
- Lookup context
-
find
public <T> Optional<T> find(Class<T> type)
Search for an instance of the given type.- Type Parameters:
T
-- Parameters:
type
- class to search for- Returns:
- Optional wrapping the result if found, or empty if not
-
time
public final long time()
The current clocktime in nanoseconds. May only be used relatively to itself, and may be negative.- Returns:
-
millis
public final long millis()
The current time in milliseconds since the root was started.- Returns:
-
-