()
| 352 | } |
| 353 | |
| 354 | public void run() { |
| 355 | URLConnection connection = null; |
| 356 | Task task = null; |
| 357 | boolean isError; |
| 358 | InputStream stream; |
| 359 | Notifier notifier; |
| 360 | URL url; |
| 361 | |
| 362 | running = true; |
| 363 | |
| 364 | Thread.currentThread().setName("RemoteReader[" + host + "]"); |
| 365 | |
| 366 | Logger.debug("RemoteReader[" + host +"] started"); |
| 367 | |
| 368 | while(running) { |
| 369 | |
| 370 | try { |
| 371 | synchronized (tasks) { |
| 372 | while(running && (task = tasks.poll()) == null) { |
| 373 | tasks.wait(); |
| 374 | } |
| 375 | } |
| 376 | } catch (InterruptedException e) { |
| 377 | Logger.warning("RemoteReader[" + host +"] interrupted"); |
| 378 | break; |
| 379 | } |
| 380 | |
| 381 | if(task == null) break; |
| 382 | |
| 383 | isError = false; |
| 384 | notifier = null; |
| 385 | stream = null; |
| 386 | |
| 387 | try { |
| 388 | url = new URL(task.getUrl()); |
| 389 | } catch (MalformedURLException e) { |
| 390 | notifiers.execute(new Notifier(task, ("Bad URL: " + task.getUrl()).getBytes(), true)); |
| 391 | continue; |
| 392 | } |
| 393 | |
| 394 | if(!url.getHost().equals(host)) { |
| 395 | Logger.error(String.format("RemoteReader[%s]: URL '%s' does not belong to me", host, task.getUrl())); |
| 396 | notifiers.execute(new Notifier(task, "Host mismatch".getBytes(), true)); |
| 397 | continue; |
| 398 | } |
| 399 | |
| 400 | Logger.info("fetching '" + url.toString() + "'"); |
| 401 | |
| 402 | try { |
| 403 | connection = url.openConnection(); |
| 404 | stream = connection.getInputStream(); |
| 405 | } catch (IOException e) { |
| 406 | if (connection != null && connection instanceof HttpURLConnection) { |
| 407 | stream = ((HttpURLConnection) connection).getErrorStream(); |
| 408 | isError = true; |
| 409 | } else { |
| 410 | notifier = new Notifier(task, e.getMessage().getBytes(), true); |
| 411 | } |
nothing calls this directly
no test coverage detected