@SuppressWarnings("rawtypes")
@Override
public void operate(FlowProcess process, BufferCall<NullContext> buffCall) {
Iterator<TupleEntry> values = buffCall.getArgumentsIterator();
TupleEntry group = buffCall.getGroup();
_values = values;
_iteratorDone = false;
// <key> is the output of the IGroupingKeyGenerator used. This should
// be <IP address>-<crawl delay in ms>
String key = group.getString(0);
if (GroupingKey.isSpecialKey(key)) {
throw new RuntimeException("Invalid grouping key: " + key);
}
long crawlDelay = GroupingKey.getCrawlDelayFromKey(key);
if (crawlDelay == BaseFetchJobPolicy.UNSET_CRAWL_DELAY) {
crawlDelay = _policy.getDefaultCrawlDelay();
}
_policy.startFetchSet(key, crawlDelay);
TupleEntryCollector collector = buffCall.getOutputCollector();
PartitioningKey newKey = new PartitioningKey(key, _numReduceTasks);
while (safeHasNext()) {
ScoredUrlDatum scoredDatum = new ScoredUrlDatum(new TupleEntry(values.next()));
FetchSetInfo setInfo = _policy.nextFetchSet(scoredDatum);
if (setInfo != null) {
FetchSetDatum result = makeFetchSetDatum(setInfo, newKey, safeHasNext());
collector.add(BixoPlatform.clone(result.getTuple(), process));
}