- All Known Implementing Classes:
AbstractSingleCallFrame,InlineCommand.InlineStackFrame,ScriptStackFrame
Command.createStackFrame(org.praxislive.script.Namespace, java.util.List).
A StackFrame should always start off in StackFrame.State.Incomplete. The script
executor will call process(org.praxislive.script.Env). During
processing the StackFrame may evaluate a result, make one or more Calls, or
create a child StackFrame (eg. from evaluation of another command).
If a Call has been made, the state should remain incomplete. Any returning
call will be passed into postResponse(org.praxislive.core.Call).
If a child StackFrame has been returned, the result of its processing will be
passed into
postResponse(org.praxislive.script.StackFrame.State, java.util.List).
Once a response has been posted, the script executor will check if the
StackFrame is still marked incomplete. If it is still incomplete, the
executor will call process(org.praxislive.script.Env) again. If it
has any other state, the state and result will be posted up to the parent
StackFrame if there is one, or returned as the script result.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic enumPossible states of a StackFrame. -
Method Summary
Modifier and TypeMethodDescriptiondefault StackFrameandThen(Function<List<Value>, StackFrame> stage) Combine this StackFrame with another created from the result of this StackFrame.default StackFrameandThenMap(UnaryOperator<List<Value>> mapper) Map the result of this StackFrame with the provided mapping function before returning a result or usingandThen(java.util.function.Function).static StackFrameasync(TaskService.Task task) Create a StackFrame that executes the provided task asynchronously in the defaultTaskServiceand returns the result.static StackFramecall(ControlAddress to, List<Value> args) Create a StackFrame that makes a call to the provided control and returns the result.static StackFramecall(ControlAddress to, Value arg) Create a StackFrame that makes a call to the provided control and returns the result.getState()Get the current state of this StackFrame.voidpostResponse(Call call) Used by the script executor to post the result of a Call.voidpostResponse(StackFrame.State state, List<Value> args) Used by the script executor to post the result of a child StackFrame returned byprocess(org.praxislive.script.Env).Process the StackFrame.result()Access the result of this StackFrame.static StackFrameCreate a StackFrame that makes a call to the providedServiceand returns the result.static StackFrameserviceCall(Class<? extends Service> service, String control, Value arg) Create a StackFrame that makes a call to the providedServiceand returns the result.
-
Method Details
-
getState
StackFrame.State getState()Get the current state of this StackFrame.- Returns:
- current state
-
process
Process the StackFrame. After processing, the StackFrame should have made one or more Calls, returned a child StackFrame, or moved out of the Incomplete state.Process may be called multiple times if the state is still incomplete after this method returns and a response has been posted.
- Parameters:
env- processing environment- Returns:
- child StackFrame or null
-
postResponse
Used by the script executor to post the result of a Call. The StackFrame should validate the match ID of the response call against any pending calls before processing the call state or arguments.If the state is still incomplete after a response is posted,
process(org.praxislive.script.Env)will be called again.- Parameters:
call- response call- Throws:
IllegalStateException- if the state is not incomplete or a call response is not expected
-
postResponse
Used by the script executor to post the result of a child StackFrame returned byprocess(org.praxislive.script.Env).If the state is still incomplete after a response is posted,
process(org.praxislive.script.Env)will be called again.- Parameters:
state- the completion state of the child stack frameargs- the result of the child stack frame- Throws:
IllegalStateException- if the state is not incomplete or a child stack frame result is not expected
-
result
Access the result of this StackFrame.- Returns:
- result
- Throws:
IllegalStateException- if the state is incomplete
-
andThen
Combine this StackFrame with another created from the result of this StackFrame. The returned StackFrame will execute the frames in turn.The default implementation returns a private implementation of a compound stackframe. If this method is called on an existing compound stack frame, then the stage function will be added to that and
thiswill be returned.- Parameters:
stage- function to create next stack frame from result- Returns:
- compound stackframe
-
andThenMap
Map the result of this StackFrame with the provided mapping function before returning a result or usingandThen(java.util.function.Function).The default implementation calls
andThen(java.util.function.Function)with a function that creates a private implementation of a mapping StackFrame.- Parameters:
mapper- map value list- Returns:
- mapping stackframe
-
call
Create a StackFrame that makes a call to the provided control and returns the result.- Parameters:
to- control addressarg- single argument- Returns:
- stackframe
-
call
Create a StackFrame that makes a call to the provided control and returns the result.- Parameters:
to- control addressargs- arguments- Returns:
- stackframe
-
serviceCall
Create a StackFrame that makes a call to the providedServiceand returns the result. The first implementation of the service found in the Env lookup will be used.- Parameters:
service- type of servicecontrol- id of control on servicearg- single argument- Returns:
- stackframe
- Throws:
ServiceUnavailableException- if no implementation of the service is found
-
serviceCall
Create a StackFrame that makes a call to the providedServiceand returns the result. The first implementation of the service found in the Env lookup will be used.- Parameters:
service- type of servicecontrol- id of control on serviceargs- arguments- Returns:
- stackframe
- Throws:
ServiceUnavailableException- if no implementation of the service is found
-
async
Create a StackFrame that executes the provided task asynchronously in the defaultTaskServiceand returns the result.- Parameters:
task- task to execute- Returns:
- stackframe
-