
package forager.client;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import forager.events.ForagerEventMap;
import forager.events.Job;
import forager.events.JoinEvent;

import galileo.event.EventHandler;
import galileo.event.EventReactor;
import galileo.net.ClientMessageRouter;
import galileo.net.NetworkDestination;

public class Forager {

    private NetworkDestination server;
    private ClientMessageRouter messageRouter;

    private ForagerEventMap eventMap = new ForagerEventMap();
    private EventReactor eventReactor = new EventReactor(this, eventMap);

    private ExecutorService threadPool;

    public Forager(NetworkDestination server) {
        this(server, 4);
    }

    public Forager(NetworkDestination server, int threads) {
        this.server = server;
        this.threadPool = Executors.newFixedThreadPool(threads);
    }

    public void start()
    throws Exception {
        messageRouter = new ClientMessageRouter();
        messageRouter.addListener(eventReactor);

        /* Join the network */
        JoinEvent join = new JoinEvent();
        messageRouter.sendMessage(server, eventReactor.wrapEvent(join));

        /* Start the monitor thread */
        Thread monitor = new Thread(new StatusMonitor(this));
        monitor.start();

        while (true) {
            eventReactor.processNextEvent();
        }
    }

    protected synchronized void submitTaskRequest(int numTasks)
    throws IOException {
        TaskRequest tr = new TaskRequest(numTasks);
        messageRouter.sendMessage(server, eventReactor.wrapEvent(tr));
    }

    @EventHandler
    public void processTaskSpec(TaskSpec taskSpec, EventContext context) {
        System.out.println("Starting job: " + taskSpec);
        Task task = new Task(taskSpec.command);
        threadPool.submit(task);
    }

    public static void main(String[] args)
    throws Exception {
        if (args.length < 2) {
            System.out.println("Usage: forager.client.Forager <host> <port>");
            System.exit(1);
        }

        String host = args[0];
        int port = Integer.parseInt(args[1]);
        NetworkDestination overlord = new NetworkDestination(host, port);

        Forager forager = new Forager(overlord);
        forager.start();
    }
}

@@ -35,39 +35,22 @@
 ava.
-util.concurrent.ExecutorService
+io.IOException
 ;%0Aim
@@ -85,16 +85,64 @@
 ecutors;
+%0Aimport java.util.concurrent.ThreadPoolExecutor;
 %0A%0Aimport
@@ -178,35 +178,8 @@
 ap;%0A
-import forager.events.Job;%0A
 impo
@@ -203,24 +203,126 @@
 .JoinEvent;%0A
+import forager.events.TaskRequest;%0Aimport forager.events.TaskSpec;%0A%0Aimport galileo.event.EventContext;
 %0Aimport gali
@@ -718,22 +718,34 @@
   pr
-ivate 
+otected ThreadPool
 Executor
 Serv
@@ -744,15 +744,8 @@
 utor
-Service
  thr
@@ -948,18 +948,51 @@
 readPool
- =
+%0A            = (ThreadPoolExecutor)
  Executo

Use a ThreadPoolExecutor instead of ExecSvc