package networking.hw3;


import java.util.concurrent.*;

/**
 * This class returns the result number from the youtube analytics for each month
 */
public class Analytics {

    private static final ExecutorService threadpool = Executors.newFixedThreadPool(3);

    static Future future;

    public long analyze (int index) throws ExecutionException, InterruptedException {
        YoutubeTask task = new YoutubeTask(index);
        future = threadpool.submit(task);
        long viewCount;
        try {
            viewCount = (long) future.get();
        } catch (final InterruptedException ex) {
            System.out.println(ex);
            return -1;
        } catch (final ExecutionException ex) {
            System.out.println(ex);
            return -1;
        } catch(CancellationException ce){
            System.out.println(ce);
            return -1;
        }
        return viewCount;
    }


    private class YoutubeTask implements Callable {

        int index = 0;
        Query query = new Query();

        public YoutubeTask(int index) {
            this.index = index;
        }

        @Override
        public Object call() throws Exception {
            return query.countViews(index);
        }
    }
}
@@ -282,16 +282,358 @@
 uture;%0A%0A
+    /**%0A     * Gets a task from the youtube api, which is worked on over time.%0A     * The task may be interrupted by other clients or canceled. All%0A     * over which is handled.%0A     * @param index Index of the chunk that is it going to be analyzed%0A     * @return%0A     * @throws ExecutionException%0A     * @throws InterruptedException%0A     */%0A
     publ
@@ -702,32 +702,32 @@
 ptedException %7B%0A
-
         YoutubeT
@@ -1247,17 +1247,97 @@
 %0A    %7D%0A%0A
+    /**%0A     * A runnable class to launch the query and return a result.%0A     */
 %0A
-
     priv
@@ -1436,24 +1436,211 @@
 w Query();%0A%0A
+        /**%0A         * Calls a query on the youtube api analytics and gets back a view count.%0A         * @param index Position of the chunk in the set that is being worked on%0A         */%0A
         publ

add javadocs