package org.lodder.subtools.multisubdownloader.workers;

import java.util.ArrayList;
import java.util.List;
import org.lodder.subtools.multisubdownloader.subtitleproviders.SubtitleProvider;
import org.lodder.subtools.sublibrary.logging.Logger;
import org.lodder.subtools.sublibrary.model.Release;
import org.lodder.subtools.sublibrary.model.Subtitle;

public class SearchWorker extends Thread {

  protected final SubtitleProvider provider;
  private final SearchManager scheduler;
  private boolean busy = false;
  private boolean isInterrupted = false;
  private Release release;
  private List<Subtitle> subtitles;

  public SearchWorker(SubtitleProvider provider, SearchManager scheduler) {
    this.provider = provider;
    this.scheduler = scheduler;
  }

  @Override
  public void run() {
    String language = this.scheduler.getLanguage();
    this.busy = false;
    while (!this.isInterrupted()) {
      this.busy = true;
      Release release = this.scheduler.getNextRelease(provider);
      if (release == null) {
        this.busy = false;
        break;
      }
      this.release = release;
      Logger.instance.debug("[Search] " + this.provider.getName() + " searching " + release.toString());

      List<Subtitle> subtitles = this.provider.search(release, language);
      if (subtitles == null) {
        subtitles = new ArrayList<>();
      }

      /* clone to prevent other threads from ever messing with it */
      this.subtitles = new ArrayList<>(subtitles);

      this.busy = false;
      Logger.instance.debug(
        "[Search] " + this.provider.getName() + " found " + subtitles.size() + " subtitles for "
          + release.toString());

      if (!this.isInterrupted()) {
        this.scheduler.onCompleted(this);
      }
    }
  }

  @Override
  public boolean isInterrupted() {
    /* bugfix? interupt-state isn't being held */
    return super.isInterrupted() || this.isInterrupted;
  }

  @Override
  public void interrupt() {
    this.isInterrupted = true;
    super.interrupt();
  }

  public boolean isBusy() {
    return busy;
  }

  public Release getRelease() {
    return release;
  }

  public List<Subtitle> getSubtitles() {
    return subtitles;
  }

  public SubtitleProvider getProvider() {
    return provider;
  }
}

@@ -97,24 +97,25 @@
 .util.List;%0A
+%0A
 import org.l
@@ -188,62 +188,8 @@
 er;%0A
-import org.lodder.subtools.sublibrary.logging.Logger;%0A
 impo
@@ -290,16 +290,73 @@
 ubtitle;
+%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;
 %0A%0Apublic
@@ -614,16 +614,100 @@
 btitles;
+%0A  private static final Logger LOGGER = LoggerFactory.getLogger(SearchWorker.class);
 %0A%0A  publ
@@ -1189,38 +1189,29 @@
 ase;%0A      L
-ogger.instance
+OGGER
 .debug(%22%5BSea
@@ -1207,35 +1207,50 @@
 debug(%22%5BSearch%5D 
-%22 +
+%7B%7D searching %7B%7D %22,
  this.provider.g
@@ -1261,26 +1261,9 @@
 me()
- + %22 searching %22 +
+,
  rel
@@ -1591,51 +1591,61 @@
    L
-ogger.instance.debug(%0A        %22%5BSearch%5D %22 +
+OGGER.debug(%22%5BSearch%5D %7B%7D found %7B%7D subtitles for %7B%7D %22,
  thi
@@ -1668,22 +1668,19 @@
 me()
- + %22 found %22 +
+,%0A         
  sub
@@ -1696,40 +1696,9 @@
 ze()
- + %22 subtitles for %22%0A          +
+,
  rel

Convert SearchWorker from old logger to new LOGGER slf4j