Changes between Version 23 and Version 24 of Java API
- Timestamp:
- 12/04/12 12:58:47 (12 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Java API
v23 v24 236 236 === Filters === 237 237 238 A conduit filter is like a mapper, but i s only applied to a single conduit. The implementation is also more light-weight, and theoretically it is allowed to modify the timestamps of messages, or drop them all-together. To implement a filter, extend {{{muscle.core.conduit.filter.AbstractFilter}}}. This uses generics to indicate what values it should convert between. It is allowed to define a constructor, this should then either be empty or take a single {{{double}}} argument. The only function that should be overridden is apply() and this should call put() as many times as it wants to send a message. A simple multiplication-filter would look as follows238 A conduit filter is like a mapper, but it is only applied to a single conduit. The implementation is also more light-weight, and theoretically it is allowed to modify the timestamps of messages, or drop them all-together. To implement a filter, extend {{{muscle.core.conduit.filter.AbstractFilter}}}. This uses generics to indicate what values it should convert between. It is allowed to define a constructor which may take zero arguments or a single {{{double}}}. The only function that should be overridden is apply() and this should call put() as many times as it wants to send a message. A simple multiplication-filter would look as follows 239 239 {{{ 240 240 public class MultiplicationFilter extends muscle.core.conduit.filter.AbstractFilter<double[], double[]> { … … 247 247 @Override 248 248 public void apply(Observation<double[]> obs) { 249 double[] data = obs.getData(); 249 // Do not modify the original data of the submodel, so make a private copy and use the resulting data 250 double[] data = obs.privateCopy(SerializableDatatype.DOUBLE_ARR).getData(); 250 251 251 252 // perform multiplication … … 254 255 } 255 256 256 // Create a new observa ble to send257 // Create a new observation to send, with the same timestamps as the original 257 258 Observation<double[]> multObs = obs.copyWithData(data); 258 259 put(multObs); … … 261 262 }}} 262 263 263 In the {{{muscle.core.conduit.filter}}} are some examples of filters which are ready to use. 264 264 In the {{{muscle.core.conduit.filter}}} are some examples of filters which are ready to use, they are explained in the [[Configuration|Configuration section]]. 265 265 === Terminals === 266 266