Database Reference
In-Depth Information
about the channels assigned to this source as well as any other properties
that might have been set in the configuration:
public void configure(Context context) {
Interacting with the context object is quite simple. There are a number
of “getters” defined on the context class that can be used to extract
configuration parameters. These properties have already been specialized
to the appropriate selector. For example, if the class needed to access the
“optional” property, like the replicating selector, then the following code
would get the string associated with the property:
String optionalList = context.getString("optional");
However, RandomSelector only needs the list of channels associated with
this source. This method, getAllChannels , is actually part of the
AbstractChannelSelector class, so it is called directly. Because the
RandomSelector sends each event to one channel, list elements are
constructed for later use:
for (Channel c : getAllChannels()) {
List<Channel> x = new ArrayList<Channel>();
x.add(c);
outputs.add(x);
}
The other two methods that must be implemented by a custom channel
selector are getRequiredChannels and getOptionalChannels . Each
method gets a single argument in the form of an Event , whose metadata
can be checked. The RandomSelector does not check metadata; it simply
returns a random array containing a single channel as constructed in the
configuration method:
public List<Channel> getRequiredChannels(Event event) {
return outputs.get(rng.nextInt(outputs.size()));
}
public List<Channel> getOptionalChannels(Event event) {
return empty;
}
Search WWH ::




Custom Search