Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Another way—simple and straightforward—of creating Filters is via
Annotations. Here’s an annotated version of
NewTradeFilter:
@Component
public class AnnotatedNewTradeFilter {
@Filter
public boolean isTradeCancelled(Message<?> message) {
Trade t = (Trade)message.getPayload();
return (t.getStatus().equalsIgnoreCase("cancel"));
}
}
The framework uses the @Filter
annotation to annotate the isTradeCancelled method shown above. The
following snippet shows how the filter is configured:
<context:component-scan base-package="com.madhusudhan.jsi.flow.filter"/> <int:filter input-channel="in-channel" output-channel="stdout" ref="annotatedNewTradeFilter" > </int:filter>
The component-scan lets the
container scan for annotated beans in the filter package, in this case, the AnnotatedNewTradeFilter class. The annotated
method isTradeCancelled is invoked whenever an
expected message arrives in the in-channel.