MCPcopy Create free account
hub / github.com/apache/nutch / resolveUrls

Method resolveUrls

src/java/org/apache/nutch/tools/ResolveUrls.java:100–133  ·  view source on GitHub ↗

Creates a thread pool for resolving urls. Reads in the url file on the local filesystem. For each url it attempts to resolve it keeping a total account of the number resolved, errored, and the amount of time.

()

Source from the content-addressed store, hash-verified

98 * account of the number resolved, errored, and the amount of time.
99 */
100 public void resolveUrls() {
101
102 try {
103
104 // create a thread pool with a fixed number of threads
105 pool = Executors.newFixedThreadPool(numThreads);
106
107 // read in the urls file and loop through each line, one url per line
108 BufferedReader buffRead = new BufferedReader(new InputStreamReader(new FileInputStream(urlsFile), StandardCharsets.UTF_8));
109 String urlStr = null;
110 while ((urlStr = buffRead.readLine()) != null) {
111
112 // spin up a resolver thread per url
113 LOG.info("Starting: " + urlStr);
114 pool.execute(new ResolverThread(urlStr));
115 }
116
117 // close the file and wait for up to 60 seconds before shutting down
118 // the thread pool to give urls time to finish resolving
119 buffRead.close();
120 pool.awaitTermination(60, TimeUnit.SECONDS);
121 } catch (Exception e) {
122
123 // on error shutdown the thread pool immediately
124 pool.shutdownNow();
125 LOG.info(StringUtils.stringifyException(e));
126 }
127
128 // shutdown the thread pool and log totals
129 pool.shutdown();
130 LOG.info("Total: " + numTotal.get() + ", Resovled: " + numResolved.get()
131 + ", Errored: " + numErrored.get() + ", Average Time: "
132 + totalTime.get() / numTotal.get());
133 }
134
135 /**
136 * Create a new ResolveUrls with a file from the local file system.

Callers 1

mainMethod · 0.95

Calls 3

readLineMethod · 0.80
closeMethod · 0.65
getMethod · 0.65

Tested by

no test coverage detected