import java.io.*;
import java.net.*;

public class PipelineAgentServer extends ObjectServer {
   private int index = 0;
   private ObjectRequest request = null;
   private Task task = null;
   private ObjectResponse response = null;

   public void processRequest(ObjectInputStream in, ObjectOutputStream out) 
   throws Exception {
      index++;

System.out.println("INDEX: " + index);

      switch(index) {
      case 1:
      request = (ObjectRequest)in.readObject();
      task = request.getTask();
      break;

      case 2:
      task.run();
      break;

      case 3:
      response = task.getResponse();
      out.writeObject(response);
      out.flush();
      break;

      case 4:
      out.close();
      index = 0;
      break;
      }
   }
}
