// Path: ParallelRequests/app/src/main/java/itis/homework/parallelrequests/app/AppDelegate.java
// public class AppDelegate extends Application {
// 
//     private RequestsService mRequestsService;
// 
//     @Override
//     public void onCreate() {
//         super.onCreate();
//         mRequestsService = new RequestProcessor(new RequestControllerImpl());
//     }
// 
//     @NonNull
//     public static AppDelegate get(Context context) {
//         return ((AppDelegate) context.getApplicationContext());
//     }
// 
//     @NonNull
//     public RequestsService getRequestsService() {
//         return mRequestsService;
//     }
// }
// 
// Path: ParallelRequests/app/src/main/java/itis/homework/parallelrequests/network/RequestsService.java
// public interface RequestsService {
// 
//     Observable<Boolean> config();
// 
//     Observable<Boolean> auth();
// 
//     Observable<Boolean> friends();
// 
//     Observable<Boolean> posts();
// 
//     Observable<Boolean> groups();
// 
//     Observable<Boolean> messages();
// 
//     Observable<Boolean> photos();
// 
//     void reset();
// 
// }
// 
// Path: ParallelRequests/app/src/main/java/itis/homework/parallelrequests/network/ThreadUtils.java
// public class ThreadUtils {
// 
//     private static final long RETRY_DELAY = 100;
//     private static final int MINIMUM_POOL_SIZE = 4;
//     private static final int CORE_POOL_SIZE = Runtime.getRuntime().availableProcessors();
//     private static final int MAXIMUM_POOL_SIZE = CORE_POOL_SIZE > 2 ? CORE_POOL_SIZE * 2 : MINIMUM_POOL_SIZE;
//     private static final int KEEP_ALIVE_TIME = 10;
// 
//     private static final Handler HANDLER = new Handler(Looper.getMainLooper());
// 
//     private static final RejectedExecutionHandler REJECTED_EXECUTION_HANDLER = new RejectedExecutionHandler() {
//         @Override
//         public void rejectedExecution(final Runnable runnable, ThreadPoolExecutor executor) {
//             HANDLER.postDelayed(() -> THREAD_POOL_EXECUTOR.execute(runnable), RETRY_DELAY);
//         }
//     };
// 
//     private static final ThreadPoolExecutor THREAD_POOL_EXECUTOR = new ThreadPoolExecutor(CORE_POOL_SIZE * 2,
//             MAXIMUM_POOL_SIZE,
//             KEEP_ALIVE_TIME,
//             TimeUnit.SECONDS,
//             new LinkedBlockingQueue<>(MAXIMUM_POOL_SIZE),
//             REJECTED_EXECUTION_HANDLER);
// 
//     @NonNull
//     public static Thread runInBackground(@NonNull final Runnable runnable) {
//         Thread thread = new Thread(runnable);
//         THREAD_POOL_EXECUTOR.execute(thread);
//         return thread;
//     }
// }


import android.app.IntentService;
import android.content.Context;
import android.content.Intent;
import itis.homework.parallelrequests.app.AppDelegate;
import itis.homework.parallelrequests.network.RequestsService;
import itis.homework.parallelrequests.network.ThreadUtils;
package itis.homework.parallelrequests;



/**
 * @author Artur Vasilov
 */
public class SampleService extends IntentService {

    private boolean mIsConfigLoaded = false;
    private boolean mIsAuthLoaded = false;

    public static void start(Context context) {
        Intent intent = new Intent(context, SampleService.class);
        context.startService(intent);
    }

    private RequestsService mRequestsService;

    public SampleService() {
        super(SampleService.class.getName());
    }

    @Override
    public void onCreate() {
        super.onCreate();
// Path: ParallelRequests/app/src/main/java/itis/homework/parallelrequests/app/AppDelegate.java
// public class AppDelegate extends Application {
// 
//     private RequestsService mRequestsService;
// 
//     @Override
//     public void onCreate() {
//         super.onCreate();
//         mRequestsService = new RequestProcessor(new RequestControllerImpl());
//     }
// 
//     @NonNull
//     public static AppDelegate get(Context context) {
//         return ((AppDelegate) context.getApplicationContext());
//     }
// 
//     @NonNull
//     public RequestsService getRequestsService() {
//         return mRequestsService;
//     }
// }
// 
// Path: ParallelRequests/app/src/main/java/itis/homework/parallelrequests/network/RequestsService.java
// public interface RequestsService {
// 
//     Observable<Boolean> config();
// 
//     Observable<Boolean> auth();
// 
//     Observable<Boolean> friends();
// 
//     Observable<Boolean> posts();
// 
//     Observable<Boolean> groups();
// 
//     Observable<Boolean> messages();
// 
//     Observable<Boolean> photos();
// 
//     void reset();
// 
// }
// 
// Path: ParallelRequests/app/src/main/java/itis/homework/parallelrequests/network/ThreadUtils.java
// public class ThreadUtils {
// 
//     private static final long RETRY_DELAY = 100;
//     private static final int MINIMUM_POOL_SIZE = 4;
//     private static final int CORE_POOL_SIZE = Runtime.getRuntime().availableProcessors();
//     private static final int MAXIMUM_POOL_SIZE = CORE_POOL_SIZE > 2 ? CORE_POOL_SIZE * 2 : MINIMUM_POOL_SIZE;
//     private static final int KEEP_ALIVE_TIME = 10;
// 
//     private static final Handler HANDLER = new Handler(Looper.getMainLooper());
// 
//     private static final RejectedExecutionHandler REJECTED_EXECUTION_HANDLER = new RejectedExecutionHandler() {
//         @Override
//         public void rejectedExecution(final Runnable runnable, ThreadPoolExecutor executor) {
//             HANDLER.postDelayed(() -> THREAD_POOL_EXECUTOR.execute(runnable), RETRY_DELAY);
//         }
//     };
// 
//     private static final ThreadPoolExecutor THREAD_POOL_EXECUTOR = new ThreadPoolExecutor(CORE_POOL_SIZE * 2,
//             MAXIMUM_POOL_SIZE,
//             KEEP_ALIVE_TIME,
//             TimeUnit.SECONDS,
//             new LinkedBlockingQueue<>(MAXIMUM_POOL_SIZE),
//             REJECTED_EXECUTION_HANDLER);
// 
//     @NonNull
//     public static Thread runInBackground(@NonNull final Runnable runnable) {
//         Thread thread = new Thread(runnable);
//         THREAD_POOL_EXECUTOR.execute(thread);
//         return thread;
//     }
// }


// Path: ParallelRequests/app/src/main/java/itis/homework/parallelrequests/SampleService.java
import android.app.IntentService;
import android.content.Context;
import android.content.Intent;
import itis.homework.parallelrequests.app.AppDelegate;
import itis.homework.parallelrequests.network.RequestsService;
import itis.homework.parallelrequests.network.ThreadUtils;

package itis.homework.parallelrequests;



/**
 * @author Artur Vasilov
 */
public class SampleService extends IntentService {

    private boolean mIsConfigLoaded = false;
    private boolean mIsAuthLoaded = false;

    public static void start(Context context) {
        Intent intent = new Intent(context, SampleService.class);
        context.startService(intent);
    }

    private RequestsService mRequestsService;

    public SampleService() {
        super(SampleService.class.getName());
    }

    @Override
    public void onCreate() {
        super.onCreate();
        mRequestsService = AppDelegate.get(this).getRequestsService();