// Path: library/src/main/java/fr/prcaen/externalresources/exception/ExternalResourceException.java
// public class ExternalResourceException extends RuntimeException {
// 
//   public ExternalResourceException(String detailMessage) {
//     super(detailMessage);
//   }
// 
//   public ExternalResourceException(String message, Throwable cause) {
//     super(message, cause);
//   }
// 
//   public ExternalResourceException(Throwable cause) {
//     super(cause);
//   }
// }
// 
// Path: library/src/main/java/fr/prcaen/externalresources/model/Resources.java
// @SuppressWarnings("unused") public final class Resources {
//   protected final ConcurrentHashMap<String, Resource> members;
// 
//   public Resources() {
//     this.members = new ConcurrentHashMap<>();
//   }
// 
//   public Resources(@NonNull ConcurrentHashMap<String, Resource> members) {
//     this.members = members;
//   }
// 
//   public static Resources from(Reader reader, Converter converter) throws IOException {
//     return converter.fromReader(reader);
//   }
// 
//   public static Resources from(String string, Converter converter) throws IOException {
//     return from(new StringReader(string), converter);
//   }
// 
//   public static Resources fromJson(Reader reader) throws IOException {
//     return from(reader, new JsonConverter());
//   }
// 
//   public static Resources fromJson(String string) throws IOException {
//     return from(string, new JsonConverter());
//   }
// 
//   public static Resources fromJson(InputStream reader) throws IOException {
//     return fromJson(new InputStreamReader(reader));
//   }
// 
//   public static Resources fromXml(Reader reader) throws IOException {
//     return from(reader, new XmlConverter());
//   }
// 
//   public static Resources fromXml(String string) throws IOException {
//     return from(string, new XmlConverter());
//   }
// 
//   public static Resources fromXml(InputStream reader) throws IOException {
//     return fromXml(new InputStreamReader(reader));
//   }
// 
//   public Resource add(String key, Resource value) {
//     return members.put(key, value);
//   }
// 
//   @NonNull protected Set<Entry<String, Resource>> entrySet() {
//     return members.entrySet();
//   }
// 
//   public boolean has(String key) {
//     return members.containsKey(key);
//   }
// 
//   public Resource get(String key) {
//     return members.get(key);
//   }
// 
//   public Resources merge(Resources resources) {
//     members.putAll(resources.members);
// 
//     return this;
//   }
// }
// 
// Path: library/src/main/java/fr/prcaen/externalresources/ResourcesRunnable.java
// public static final int RETRY_COUNT = 2;


import android.content.Context;
import android.net.NetworkInfo;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
import android.os.Message;
import android.os.Process;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import fr.prcaen.externalresources.exception.ExternalResourceException;
import fr.prcaen.externalresources.model.Resources;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import static fr.prcaen.externalresources.ResourcesRunnable.RETRY_COUNT;
    this.handler = new DispatcherHandler(dispatcherThread.getLooper(), this);
    this.networkBroadcastReceiver = new NetworkBroadcastReceiver(context, this);
    this.networkBroadcastReceiver.register();

    this.networkInfo = Utils.getActiveNetworkInfo(context);
    this.airPlaneMode = Utils.isAirplaneModeOn(context);
    this.resourcesRunnable = new ResourcesRunnable(downloader, this, cachePolicy);
  }

  public void stop() {
    service.shutdown();
    dispatcherThread.quit();
    networkBroadcastReceiver.unregister();
  }

  public void dispatchLaunch() {
    Logger.v(ExternalResources.TAG, "dispatch launch");
    handler.sendMessage(handler.obtainMessage(REQUEST_LAUNCH));
  }

  public void dispatchRetry() {
    Logger.v(ExternalResources.TAG, "dispatch retry");
    handler.sendMessageDelayed(handler.obtainMessage(REQUEST_RETRY), RETRY_DELAY);
  }

  public void dispatchFailed(ExternalResourceException e) {
    Logger.v(ExternalResources.TAG, "dispatch failed");
    mainHandler.sendMessage(mainHandler.obtainMessage(REQUEST_FAILED, e));
  }

// Path: library/src/main/java/fr/prcaen/externalresources/exception/ExternalResourceException.java
// public class ExternalResourceException extends RuntimeException {
// 
//   public ExternalResourceException(String detailMessage) {
//     super(detailMessage);
//   }
// 
//   public ExternalResourceException(String message, Throwable cause) {
//     super(message, cause);
//   }
// 
//   public ExternalResourceException(Throwable cause) {
//     super(cause);
//   }
// }
// 
// Path: library/src/main/java/fr/prcaen/externalresources/model/Resources.java
// @SuppressWarnings("unused") public final class Resources {
//   protected final ConcurrentHashMap<String, Resource> members;
// 
//   public Resources() {
//     this.members = new ConcurrentHashMap<>();
//   }
// 
//   public Resources(@NonNull ConcurrentHashMap<String, Resource> members) {
//     this.members = members;
//   }
// 
//   public static Resources from(Reader reader, Converter converter) throws IOException {
//     return converter.fromReader(reader);
//   }
// 
//   public static Resources from(String string, Converter converter) throws IOException {
//     return from(new StringReader(string), converter);
//   }
// 
//   public static Resources fromJson(Reader reader) throws IOException {
//     return from(reader, new JsonConverter());
//   }
// 
//   public static Resources fromJson(String string) throws IOException {
//     return from(string, new JsonConverter());
//   }
// 
//   public static Resources fromJson(InputStream reader) throws IOException {
//     return fromJson(new InputStreamReader(reader));
//   }
// 
//   public static Resources fromXml(Reader reader) throws IOException {
//     return from(reader, new XmlConverter());
//   }
// 
//   public static Resources fromXml(String string) throws IOException {
//     return from(string, new XmlConverter());
//   }
// 
//   public static Resources fromXml(InputStream reader) throws IOException {
//     return fromXml(new InputStreamReader(reader));
//   }
// 
//   public Resource add(String key, Resource value) {
//     return members.put(key, value);
//   }
// 
//   @NonNull protected Set<Entry<String, Resource>> entrySet() {
//     return members.entrySet();
//   }
// 
//   public boolean has(String key) {
//     return members.containsKey(key);
//   }
// 
//   public Resource get(String key) {
//     return members.get(key);
//   }
// 
//   public Resources merge(Resources resources) {
//     members.putAll(resources.members);
// 
//     return this;
//   }
// }
// 
// Path: library/src/main/java/fr/prcaen/externalresources/ResourcesRunnable.java
// public static final int RETRY_COUNT = 2;


// Path: library/src/main/java/fr/prcaen/externalresources/Dispatcher.java
import android.content.Context;
import android.net.NetworkInfo;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
import android.os.Message;
import android.os.Process;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import fr.prcaen.externalresources.exception.ExternalResourceException;
import fr.prcaen.externalresources.model.Resources;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import static fr.prcaen.externalresources.ResourcesRunnable.RETRY_COUNT;

    this.handler = new DispatcherHandler(dispatcherThread.getLooper(), this);
    this.networkBroadcastReceiver = new NetworkBroadcastReceiver(context, this);
    this.networkBroadcastReceiver.register();

    this.networkInfo = Utils.getActiveNetworkInfo(context);
    this.airPlaneMode = Utils.isAirplaneModeOn(context);
    this.resourcesRunnable = new ResourcesRunnable(downloader, this, cachePolicy);
  }

  public void stop() {
    service.shutdown();
    dispatcherThread.quit();
    networkBroadcastReceiver.unregister();
  }

  public void dispatchLaunch() {
    Logger.v(ExternalResources.TAG, "dispatch launch");
    handler.sendMessage(handler.obtainMessage(REQUEST_LAUNCH));
  }

  public void dispatchRetry() {
    Logger.v(ExternalResources.TAG, "dispatch retry");
    handler.sendMessageDelayed(handler.obtainMessage(REQUEST_RETRY), RETRY_DELAY);
  }

  public void dispatchFailed(ExternalResourceException e) {
    Logger.v(ExternalResources.TAG, "dispatch failed");
    mainHandler.sendMessage(mainHandler.obtainMessage(REQUEST_FAILED, e));
  }

  public void dispatchDone(Resources resources) {