public abstract class Component
extends java.lang.Object
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 extends Component {
public EchoComponent(EventEmitter eventEmitter) {
super(eventEmitter);
}
@Override
public void execute(ExecutionParameters parameters) {
final JsonObject snapshot = new JsonObject();
snapshot.add("echo", parameters.getSnapshot());
getEventEmitter()
.emitSnapshot(snapshot)
.emitData(echoMessage(parameters));
}
private Message echoMessage(ExecutionParameters parameters) {
final Message msg = parameters.getMessage();
final JsonObject body = new JsonObject();
body.add("echo", msg.getBody());
body.add("config", parameters.getConfiguration());
return new Message.Builder()
.body(body)
.attachments(msg.getAttachments())
.build();
}
}
ExecutionParameters
,
Message
,
EventEmitter
Constructor and Description |
---|
Component(EventEmitter eventEmitter)
Creates a component instance with the given
EventEmitter . |
Modifier and Type | Method and Description |
---|---|
abstract void |
execute(ExecutionParameters parameters)
Executes this component with the given
ExecutionParameters . |
protected EventEmitter |
getEventEmitter()
Used to emit data to component's callee by sending events.
|
public Component(EventEmitter eventEmitter)
EventEmitter
.eventEmitter
- emitter to emit eventspublic abstract void execute(ExecutionParameters parameters)
ExecutionParameters
.parameters
- parameters to execute component withprotected EventEmitter getEventEmitter()