(SelectorEntry key, Iterable<WebPage> values,
Context context)
| 49 | private Utf8 batchId; |
| 50 | |
| 51 | @Override |
| 52 | protected void reduce(SelectorEntry key, Iterable<WebPage> values, |
| 53 | Context context) throws IOException, InterruptedException { |
| 54 | for (WebPage page : values) { |
| 55 | if (count >= limit) { |
| 56 | return; |
| 57 | } |
| 58 | if (maxCount > 0) { |
| 59 | String hostordomain; |
| 60 | if (byDomain) { |
| 61 | hostordomain = URLUtil.getDomainName(key.url); |
| 62 | } else { |
| 63 | hostordomain = URLUtil.getHost(key.url); |
| 64 | } |
| 65 | |
| 66 | Integer hostCount = hostCountMap.get(hostordomain); |
| 67 | if (hostCount == null) { |
| 68 | hostCountMap.put(hostordomain, 0); |
| 69 | hostCount = 0; |
| 70 | } |
| 71 | if (hostCount >= maxCount) { |
| 72 | return; |
| 73 | } |
| 74 | hostCountMap.put(hostordomain, hostCount + 1); |
| 75 | } |
| 76 | |
| 77 | Mark.GENERATE_MARK.putMark(page, batchId); |
| 78 | page.setBatchId(batchId); |
| 79 | try { |
| 80 | context.write(TableUtil.reverseUrl(key.url), page); |
| 81 | } catch (MalformedURLException e) { |
| 82 | context.getCounter("Generator", "MALFORMED_URL").increment(1); |
| 83 | continue; |
| 84 | } |
| 85 | context.getCounter("Generator", "GENERATE_MARK").increment(1); |
| 86 | count++; |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | @Override |
| 91 | protected void setup(Context context) throws IOException, |
nothing calls this directly
no test coverage detected