public interface Function
A component is executed with a ExecutionParameters
which provides
the component with a Message
, configuration and a snapshot.
The given Message
represents component's input. Besides other things
it contains a payload to be consumed by a component.
A configuration is an instance JsonObject
containing
required information, such as API key or username/password combination, that
components needs to collect from user to function properly.
A snapshot is an instance of JsonObject
that represents
component's state. For example, a Twitter timeline component might store the id
of the last retrieved tweet for the next execution in order to ask Twitter for
tweets whose ids are greater than the one in the snapshot.
EventEmitter
.
The following example demonstrates a simple component which echos the incoming message.
public class EchoComponent implements Function {
@Override
public void execute(ExecutionParameters parameters) {
final JsonObject snapshot = Json.createObjectBuilder()
.add("echo", parameters.getSnapshot())
.build();
parameters.getEventEmitter()
.emitSnapshot(snapshot)
.emitData(echoMessage(parameters));
}
private Message echoMessage(ExecutionParameters parameters) {
final Message msg = parameters.getMessage();
final JsonObject body = Json.createObjectBuilder()
.add("echo", msg.getBody())
.add("config", parameters.getConfiguration())
.build();
return new Message.Builder()
.body(body)
.attachments(msg.getAttachments())
.build();
}
}
ExecutionParameters
,
Message
,
EventEmitter
Modifier and Type | Method and Description |
---|---|
void |
execute(ExecutionParameters parameters)
Executes this component with the given
ExecutionParameters . |
default void |
init(InitParameters parameters)
Used to initialize a component before message processing.
|
default void |
shutdown(ShutdownParameters parameters)
Used to shutdown a component gracefully before its process is killed.
|
default javax.json.JsonObject |
startup(StartupParameters parameters)
Used to initialize the component on flow start.
|
void execute(ExecutionParameters parameters)
ExecutionParameters
.parameters
- parameters to execute component withdefault javax.json.JsonObject startup(StartupParameters parameters)
shutdown(ShutdownParameters)
method where the subscription can be canceled on flow stop.parameters
- parameters to startup the module withdefault void init(InitParameters parameters)
parameters
- to init the module withdefault void shutdown(ShutdownParameters parameters)
startup(StartupParameters)
.
For example, this method may be used to cancel a webhook subscription on flow stop.parameters
- parameters to shutdown the module with