package co.tzhang.akka;

import akka.actor.ActorRef;
import akka.actor.ActorSystem;
import akka.actor.Props;
import akka.dispatch.Futures;
import akka.pattern.Patterns;
import akka.util.Timeout;
import co.tzhang.akka.actors.MasterActor;
import scala.concurrent.duration.FiniteDuration;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

/**
 * Created by haofan on 5/15/2016.
 */
public class FuturesSequence {
    private final Map<String, Future<Object>> taskList = new HashMap<>();
    public void addStartTask(ActorSystem system) {
        //final ExecutionContextExecutorService ec = ExecutionContexts.fromExecutorService(Executors.newSingleThreadExecutor());
        Timeout timeout = new Timeout(FiniteDuration.create(2, TimeUnit.SECONDS));
        ActorRef master = system.actorOf(Props.create(MasterActor.class), "master");
        Future<Object> futureRes = Patterns.ask(master,"The quick brown fox tried to jump over the lazy dog and fell on the dog",timeout);
        taskList.put("The quick brown fox tried to jump over the lazy dog and fell on the dog", futureRes);
        Future<Object> futureRes = Patterns.ask(master,"quick brown fox tried to jump over the lazy dog and fell on the dog",timeout);
        taskList.put("quick brown fox tried to jump over the lazy dog and fell on the dog", futureRes);
        Future<Object> futureRes = Patterns.ask(master,"The brown fox tried to jump over the lazy dog and fell on the dog",timeout);
        taskList.put("The brown fox tried to jump over the lazy dog and fell on the dog", futureRes);

    }
    public void completeTasks(ActorSystem system){
        if(!taskList.isEmpty()){
            final Future<Iterable<Object>> futureResponse = Futures.sequence(taskList.values(),system.dispatcher());
        }

    }
    public static void main(String[] args) throws Exception {
        ActorSystem system = ActorSystem.create("FuturesSequence");
        FuturesSequence futuresSequence = new FuturesSequence();
        futuresSequence.addStartTask(system);
        futuresSequence.completeTasks(system);
    }
}

@@ -45,244 +45,14 @@
 ctor
-Ref;%0Aimport akka.actor.ActorSystem;%0Aimport akka.actor.Props;%0Aimport akka.dispatch.Futures;%0Aimport akka.pattern.Patterns;%0Aimport akka.util.Timeout;%0Aimport co.tzhang.akka.actors.MasterActor;%0Aimport scala.concurrent.duration.FiniteDuration
+System
 ;%0A%0Ai
@@ -137,46 +137,8 @@
 ure;
-%0Aimport java.util.concurrent.TimeUnit;
 %0A%0A/*
@@ -463,24 +463,24 @@
 tor());%0A
-
         
 Timeout 
@@ -471,16 +471,18 @@
         
+/*
 Timeout 
@@ -1354,16 +1354,18 @@
 reRes);%0A
+*/
 %0A    %7D%0A 
@@ -1459,16 +1459,18 @@
         
+//
 final Fu

add description