protected class TaskSpec {
  public String appId;
  public Boolean shortTask;
  public TUserGroupInfo user;
  public String requestId;
  public THostPort originalNodeMonitorAddress;
    
  public InetSocketAddress schedulerAddress;
  public InetSocketAddress appBackendAddress;

  /**
   * ID of the task that previously ran in the slot this task is using. Used
   * to track how long it takes to fill an empty slot on a slave. Empty if this task was launched
   * immediately, because there were empty slots available on the slave.  Filled in when
   * the task is launched.
   */
  public String previousRequestId;
  public String previousTaskId;

  /** Filled in after the getTask() RPC completes. */
  public TTaskLaunchSpec taskSpec;

  public TaskSpec(TEnqueueTaskReservationsRequest request, InetSocketAddress appBackendAddress) {
    appId = request.getAppId();
    user = request.getUser();
    shortTask = request.shortTask;
    requestId = request.getRequestId();
    originalNodeMonitorAddress = request.originalNodeMonitorAddress;
    schedulerAddress = new InetSocketAddress(request.getSchedulerAddress().getHost(),
                                             request.getSchedulerAddress().getPort());
    this.appBackendAddress = appBackendAddress;
    previousRequestId = "";
    previousTaskId = "";
  }
} public class SchedulerThrift implements SchedulerService.Iface, GetTaskService.Iface {
  // Defaults if not specified by configuration
  public final static int DEFAULT_SCHEDULER_THRIFT_PORT = 20503;
  private final static int DEFAULT_SCHEDULER_THRIFT_THREADS = 8;
  public final static int DEFAULT_GET_TASK_PORT = 20507;

  private Scheduler scheduler = new Scheduler();

  /**
   * Initialize this thrift service.
   *
   * This spawns a multi-threaded thrift server and listens for Eagle
   * scheduler requests.
   */
  public void initialize(Configuration conf) throws IOException {
    SchedulerService.Processor<SchedulerService.Iface> processor =
        new SchedulerService.Processor<SchedulerService.Iface>(this);
    int port = conf.getInt(EagleConf.SCHEDULER_THRIFT_PORT,
        DEFAULT_SCHEDULER_THRIFT_PORT);
    int threads = conf.getInt(EagleConf.SCHEDULER_THRIFT_THREADS,
        DEFAULT_SCHEDULER_THRIFT_THREADS);
    String hostname = Network.getHostName(conf);
    InetSocketAddress addr = new InetSocketAddress(hostname, port);
    scheduler.initialize(conf, addr);
    TServers.launchThreadedThriftServer(port, threads, processor);
    int getTaskPort = conf.getInt(EagleConf.GET_TASK_PORT,
        DEFAULT_GET_TASK_PORT);
    GetTaskService.Processor<GetTaskService.Iface> getTaskprocessor =
        new GetTaskService.Processor<GetTaskService.Iface>(this);
    TServers.launchSingleThreadThriftServer(getTaskPort, getTaskprocessor);
  }

  @Override
  public boolean registerFrontend(String app, String socketAddress) {
    return scheduler.registerFrontend(app, socketAddress);
  }

  @Override
  public void submitJob(TSchedulingRequest req)
      throws TException {
    scheduler.submitJob(req);
  }

  @Override
  public void sendFrontendMessage(String app, TFullTaskId taskId,
      int status, ByteBuffer message) throws TException {
    scheduler.sendFrontendMessage(app, taskId, status, message);
  }

  @Override
  public List<TTaskLaunchSpec> getTask(String requestId, THostPort nodeMonitorAddress, THostPort oldNodeMonitorAddress)
      throws TException {
    return scheduler.getTask(requestId, nodeMonitorAddress, oldNodeMonitorAddress);
  }
} public class Logging {
  public final static String AUDIT_LOGGER_NAME = "audit";
  public final static String AUDIT_LOG_FILENAME_FORMAT = "eagle_audit.%d.%d.log";
  public final static String AUDIT_LOG_FORMAT = "%c\t%m%n";

  private static Joiner paramJoiner = Joiner.on(",").useForNull("null");
  private static Joiner auditParamJoiner = Joiner.on("\t");
  private static Joiner auditEventParamJoiner = Joiner.on(":");

  /**
   * Sets up audit logging to log to a file named based on the current time (in
   * ms).
   *
   * The logger is configured to effectively ignore the log level.
   *
   * @throws IOException
   *           if the audit log file could not be opened for writing.
   */
  public static void configureAuditLogging() throws IOException {
    PatternLayout layout = new PatternLayout(AUDIT_LOG_FORMAT);
    // This assumes that no other daemon will be started within 1 millisecond.
    String filename = String.format(AUDIT_LOG_FILENAME_FORMAT,
        System.currentTimeMillis(), new Random().nextInt(Integer.MAX_VALUE));
    FileAppender fileAppender = new FileAppender(layout, filename);
    Logger auditLogger = Logger.getLogger(Logging.AUDIT_LOGGER_NAME);
    auditLogger.addAppender(fileAppender);
    auditLogger.setLevel(Level.ALL);
    /*
     * We don't want audit messages to be appended to the main appender, which
     * is intended for potentially user-facing messages.
     */
    auditLogger.setAdditivity(false);
  }

  /** Returns the total count of garbage collections. */
  public static long getGCCount() {
    long totalGarbageCollections = 0;

    for (GarbageCollectorMXBean gc : ManagementFactory
        .getGarbageCollectorMXBeans()) {
      long count = gc.getCollectionCount();
      if (count >= 0) {
        totalGarbageCollections += count;
      }
    }
    return totalGarbageCollections;
  }

  /** Returns the total time that has been spent on garbage collection. */
  public static long getGCTime() {
    long garbageCollectionTime = 0;

    for (GarbageCollectorMXBean gc : ManagementFactory
        .getGarbageCollectorMXBeans()) {
      long time = gc.getCollectionTime();
      if (time >= 0) {
        garbageCollectionTime += time;
      }
    }
    return garbageCollectionTime;
  }

  /**
   * Returns a log string for the given event, starting with the epoch time.
   */
  public static String auditEventString(Object... params) {
    DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss,SSS");
    Date date = new Date();

    return auditParamJoiner.join(System.currentTimeMillis(),dateFormat.format(date), 
        auditEventParamJoiner.join(params));
  }

  /**
   * Returns a logger to be used for audit logging messages for the given class.
   */
  @SuppressWarnings("rawtypes")
  public static Logger getAuditLogger(Class clazz) {
    return Logger.getLogger(String.format("%s.%s", AUDIT_LOGGER_NAME,
        clazz.getName()));
  }

  /**
   * Return a function name (determined via reflection) and all its parameters
   * (passed) in a consistent stringformat. Very helpful in logging function
   * calls throughout our program.
   */
  public static String functionCall(Object... params) {
    String name = Thread.currentThread().getStackTrace()[2].getMethodName();
    return name + ": [" + paramJoiner.join(params) + "]";
  }
} public class Network {
  
  public static THostPort socketAddressToThrift(InetSocketAddress address) {
    return new THostPort(address.getAddress().getHostAddress(), address.getPort());
  }

  /** Return the hostname of this machine, based on configured value, or system
   * Interrogation. */
  public static String getHostName(Configuration conf) {
    String defaultHostname = null;
    try {
      defaultHostname = InetAddress.getLocalHost().getHostName();
    } catch (UnknownHostException e) {
      defaultHostname = "localhost";
    }
    return conf.getString(EagleConf.HOSTNAME, defaultHostname); 
  }
  
  /**
   * Return the IP address of this machine, as determined from the hostname
   * specified in configuration or from querying the machine.
   */
  public static String getIPAddress(Configuration conf) {
    String hostname = getHostName(conf);
    try {
      return InetAddress.getByName(hostname).getHostAddress();
    } catch (UnknownHostException e) {
      return "IP UNKNOWN";
    }
  }
} public class Resources {
  public static int getSystemMemoryMb(Configuration conf) {
    int systemMemory = -1;
    try {
      Process p = Runtime.getRuntime().exec("cat /proc/meminfo");  
      BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
      String line = in.readLine();
      while (line != null) {
        if (line.contains("MemTotal")) { 
          String[] parts = line.split("\\s+");
          if (parts.length > 1) {
            int memory = Integer.parseInt(parts[1]) / 1000;
            systemMemory = memory;
          }
        }
        line = in.readLine();
      }
    } catch (IOException e) {}
    if (conf.containsKey(EagleConf.SYSTEM_MEMORY)) {
      return conf.getInt(EagleConf.SYSTEM_MEMORY);
    } else {
      if (systemMemory != -1) {
        return systemMemory;
      } else {
        return EagleConf.DEFAULT_SYSTEM_MEMORY;
      }
    }
  }
  
  public static int getSystemCPUCount(Configuration conf) {
    // No system interrogation yet
    return conf.getInt(EagleConf.SYSTEM_CPUS, EagleConf.DEFAULT_SYSTEM_CPUS);
  }
} public class TClients {
  private final static Logger LOG = Logger.getLogger(TClients.class);

  public static NodeMonitorService.Client createBlockingNmClient(String host, int port)
      throws IOException {
    return createBlockingNmClient(host, port, 0);
  }

  public static NodeMonitorService.Client createBlockingNmClient(String host, int port,
      int timeout)
      throws IOException {
    TTransport tr = new TFramedTransport(new TSocket(host, port, timeout));
    try {
      tr.open();
    } catch (TTransportException e) {
      LOG.warn("Error creating node monitor client to " + host + ":" + port);
      throw new IOException(e);
    }
    TProtocol proto = new TBinaryProtocol(tr);
    NodeMonitorService.Client client = new NodeMonitorService.Client(proto);
    return client;
  }

  public static SchedulerService.Client createBlockingSchedulerClient(
      InetSocketAddress socket) throws IOException {
    return createBlockingSchedulerClient(socket.getAddress().getHostAddress(), socket.getPort());
  }

  public static SchedulerService.Client createBlockingSchedulerClient(
      String host, int port) throws IOException {
    return createBlockingSchedulerClient(host, port, 0);
  }

  public static SchedulerService.Client createBlockingSchedulerClient(
      String host, int port, int timeout) throws IOException {
    TTransport tr = new TFramedTransport(new TSocket(host, port, timeout));
    try {
      tr.open();
    } catch (TTransportException e) {
      LOG.warn("Error creating scheduler client to " + host + ":" + port);
      throw new IOException(e);
    }
    TProtocol proto = new TBinaryProtocol(tr);
    SchedulerService.Client client = new SchedulerService.Client(proto);
    return client;
  }

  public static GetTaskService.Client createBlockingGetTaskClient(
      InetSocketAddress socket) throws IOException {
    return createBlockingGetTaskClient(socket.getAddress().getHostAddress(), socket.getPort());
  }

  public static GetTaskService.Client createBlockingGetTaskClient(
      String host, int port) throws IOException {
    return createBlockingGetTaskClient(host, port, 0);
  }

  public static GetTaskService.Client createBlockingGetTaskClient(
      String host, int port, int timeout) throws IOException {
    TTransport tr = new TFramedTransport(new TSocket(host, port, timeout));
    try {
      tr.open();
    } catch (TTransportException e) {
      LOG.warn("Error creating scheduler client to " + host + ":" + port);
      throw new IOException(e);
    }
    TProtocol proto = new TBinaryProtocol(tr);
    GetTaskService.Client client = new GetTaskService.Client(proto);
    return client;
  }

  public static BackendService.Client createBlockingBackendClient(
      InetSocketAddress socket) throws IOException {
    return createBlockingBackendClient(socket.getAddress().getHostAddress(), socket.getPort());
  }

  public static BackendService.Client createBlockingBackendClient(
      String host, int port) throws IOException {
    TTransport tr = new TFramedTransport(new TSocket(host, port));
    try {
      tr.open();
    } catch (TTransportException e) {
      LOG.warn("Error creating backend client to " + host + ":" + port);
      throw new IOException(e);
    }
    TProtocol proto = new TBinaryProtocol(tr);
    BackendService.Client client = new BackendService.Client(proto);
    return client;
  }

  public static StateStoreService.Client createBlockingStateStoreClient(
      String host, int port) throws IOException {
    TTransport tr = new TFramedTransport(new TSocket(host, port));
    try {
      tr.open();
    } catch (TTransportException e) {
      LOG.warn("Error creating state store client to " + host + ":" + port);
      throw new IOException(e);
    }
    TProtocol proto = new TBinaryProtocol(tr);
    StateStoreService.Client client = new StateStoreService.Client(proto);
    return client;
  }

  public static FrontendService.Client createBlockingFrontendClient(
      InetSocketAddress socket) throws IOException {
    return createBlockingFrontendClient(socket.getAddress().getHostAddress(), socket.getPort());
  }

  public static FrontendService.Client createBlockingFrontendClient(
      String host, int port) throws IOException {
    TTransport tr = new TFramedTransport(new TSocket(host, port));
    try {
      tr.open();
    } catch (TTransportException e) {
      LOG.warn("Error creating state store client to " + host + ":" + port);
      throw new IOException(e);
    }
    TProtocol proto = new TBinaryProtocol(tr);
    FrontendService.Client client = new FrontendService.Client(proto);
    return client;
  }
} @SuppressWarnings({"cast", "rawtypes", "serial", "unchecked"})
@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2016-03-03")
public class BackendService {

  public interface Iface {

    public void launchTask(ByteBuffer message, ch.epfl.eagle.thrift.TFullTaskId taskId, ch.epfl.eagle.thrift.TUserGroupInfo user) throws org.apache.thrift.TException;

  }

  public interface AsyncIface {

    public void launchTask(ByteBuffer message, ch.epfl.eagle.thrift.TFullTaskId taskId, ch.epfl.eagle.thrift.TUserGroupInfo user, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException;

  }

  public static class Client extends org.apache.thrift.TServiceClient implements Iface {
    public static class Factory implements org.apache.thrift.TServiceClientFactory<Client> {
      public Factory() {}
      public Client getClient(org.apache.thrift.protocol.TProtocol prot) {
        return new Client(prot);
      }
      public Client getClient(org.apache.thrift.protocol.TProtocol iprot, org.apache.thrift.protocol.TProtocol oprot) {
        return new Client(iprot, oprot);
      }
    }

    public Client(org.apache.thrift.protocol.TProtocol prot)
    {
      super(prot, prot);
    }

    public Client(org.apache.thrift.protocol.TProtocol iprot, org.apache.thrift.protocol.TProtocol oprot) {
      super(iprot, oprot);
    }

    public void launchTask(ByteBuffer message, ch.epfl.eagle.thrift.TFullTaskId taskId, ch.epfl.eagle.thrift.TUserGroupInfo user) throws org.apache.thrift.TException
    {
      send_launchTask(message, taskId, user);
      recv_launchTask();
    }

    public void send_launchTask(ByteBuffer message, ch.epfl.eagle.thrift.TFullTaskId taskId, ch.epfl.eagle.thrift.TUserGroupInfo user) throws org.apache.thrift.TException
    {
      launchTask_args args = new launchTask_args();
      args.setMessage(message);
      args.setTaskId(taskId);
      args.setUser(user);
      sendBase("launchTask", args);
    }

    public void recv_launchTask() throws org.apache.thrift.TException
    {
      launchTask_result result = new launchTask_result();
      receiveBase(result, "launchTask");
      return;
    }

  }
  public static class AsyncClient extends org.apache.thrift.async.TAsyncClient implements AsyncIface {
    public static class Factory implements org.apache.thrift.async.TAsyncClientFactory<AsyncClient> {
      private org.apache.thrift.async.TAsyncClientManager clientManager;
      private org.apache.thrift.protocol.TProtocolFactory protocolFactory;
      public Factory(org.apache.thrift.async.TAsyncClientManager clientManager, org.apache.thrift.protocol.TProtocolFactory protocolFactory) {
        this.clientManager = clientManager;
        this.protocolFactory = protocolFactory;
      }
      public AsyncClient getAsyncClient(org.apache.thrift.transport.TNonblockingTransport transport) {
        return new AsyncClient(protocolFactory, clientManager, transport);
      }
    }

    public AsyncClient(org.apache.thrift.protocol.TProtocolFactory protocolFactory, org.apache.thrift.async.TAsyncClientManager clientManager, org.apache.thrift.transport.TNonblockingTransport transport) {
      super(protocolFactory, clientManager, transport);
    }

    public void launchTask(ByteBuffer message, ch.epfl.eagle.thrift.TFullTaskId taskId, ch.epfl.eagle.thrift.TUserGroupInfo user, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException {
      checkReady();
      launchTask_call method_call = new launchTask_call(message, taskId, user, resultHandler, this, ___protocolFactory, ___transport);
      this.___currentMethod = method_call;
      ___manager.call(method_call);
    }

    public static class launchTask_call extends org.apache.thrift.async.TAsyncMethodCall {
      private ByteBuffer message;
      private ch.epfl.eagle.thrift.TFullTaskId taskId;
      private ch.epfl.eagle.thrift.TUserGroupInfo user;
      public launchTask_call(ByteBuffer message, ch.epfl.eagle.thrift.TFullTaskId taskId, ch.epfl.eagle.thrift.TUserGroupInfo user, org.apache.thrift.async.AsyncMethodCallback resultHandler, org.apache.thrift.async.TAsyncClient client, org.apache.thrift.protocol.TProtocolFactory protocolFactory, org.apache.thrift.transport.TNonblockingTransport transport) throws org.apache.thrift.TException {
        super(client, protocolFactory, transport, resultHandler, false);
        this.message = message;
        this.taskId = taskId;
        this.user = user;
      }

      public void write_args(org.apache.thrift.protocol.TProtocol prot) throws org.apache.thrift.TException {
        prot.writeMessageBegin(new org.apache.thrift.protocol.TMessage("launchTask", org.apache.thrift.protocol.TMessageType.CALL, 0));
        launchTask_args args = new launchTask_args();
        args.setMessage(message);
        args.setTaskId(taskId);
        args.setUser(user);
        args.write(prot);
        prot.writeMessageEnd();
      }

      public void getResult() throws org.apache.thrift.TException {
        if (getState() != org.apache.thrift.async.TAsyncMethodCall.State.RESPONSE_READ) {
          throw new IllegalStateException("Method call not finished!");
        }
        org.apache.thrift.transport.TMemoryInputTransport memoryTransport = new org.apache.thrift.transport.TMemoryInputTransport(getFrameBuffer().array());
        org.apache.thrift.protocol.TProtocol prot = client.getProtocolFactory().getProtocol(memoryTransport);
        (new Client(prot)).recv_launchTask();
      }
    }

  }

  public static class Processor<I extends Iface> extends org.apache.thrift.TBaseProcessor<I> implements org.apache.thrift.TProcessor {
    private static final Logger LOGGER = LoggerFactory.getLogger(Processor.class.getName());
    public Processor(I iface) {
      super(iface, getProcessMap(new HashMap<String, org.apache.thrift.ProcessFunction<I, ? extends org.apache.thrift.TBase>>()));
    }

    protected Processor(I iface, Map<String,  org.apache.thrift.ProcessFunction<I, ? extends  org.apache.thrift.TBase>> processMap) {
      super(iface, getProcessMap(processMap));
    }

    private static <I extends Iface> Map<String,  org.apache.thrift.ProcessFunction<I, ? extends  org.apache.thrift.TBase>> getProcessMap(Map<String,  org.apache.thrift.ProcessFunction<I, ? extends  org.apache.thrift.TBase>> processMap) {
      processMap.put("launchTask", new launchTask());
      return processMap;
    }

    public static class launchTask<I extends Iface> extends org.apache.thrift.ProcessFunction<I, launchTask_args> {
      public launchTask() {
        super("launchTask");
      }

      public launchTask_args getEmptyArgsInstance() {
        return new launchTask_args();
      }

      protected boolean isOneway() {
        return false;
      }

      public launchTask_result getResult(I iface, launchTask_args args) throws org.apache.thrift.TException {
        launchTask_result result = new launchTask_result();
        iface.launchTask(args.message, args.taskId, args.user);
        return result;
      }
    }

  }

  public static class AsyncProcessor<I extends AsyncIface> extends org.apache.thrift.TBaseAsyncProcessor<I> {
    private static final Logger LOGGER = LoggerFactory.getLogger(AsyncProcessor.class.getName());
    public AsyncProcessor(I iface) {
      super(iface, getProcessMap(new HashMap<String, org.apache.thrift.AsyncProcessFunction<I, ? extends org.apache.thrift.TBase, ?>>()));
    }

    protected AsyncProcessor(I iface, Map<String,  org.apache.thrift.AsyncProcessFunction<I, ? extends  org.apache.thrift.TBase, ?>> processMap) {
      super(iface, getProcessMap(processMap));
    }

    private static <I extends AsyncIface> Map<String,  org.apache.thrift.AsyncProcessFunction<I, ? extends  org.apache.thrift.TBase,?>> getProcessMap(Map<String,  org.apache.thrift.AsyncProcessFunction<I, ? extends  org.apache.thrift.TBase, ?>> processMap) {
      processMap.put("launchTask", new launchTask());
      return processMap;
    }

    public static class launchTask<I extends AsyncIface> extends org.apache.thrift.AsyncProcessFunction<I, launchTask_args, Void> {
      public launchTask() {
        super("launchTask");
      }

      public launchTask_args getEmptyArgsInstance() {
        return new launchTask_args();
      }

      public AsyncMethodCallback<Void> getResultHandler(final AsyncFrameBuffer fb, final int seqid) {
        final org.apache.thrift.AsyncProcessFunction fcall = this;
        return new AsyncMethodCallback<Void>() { 
          public void onComplete(Void o) {
            launchTask_result result = new launchTask_result();
            try {
              fcall.sendResponse(fb,result, org.apache.thrift.protocol.TMessageType.REPLY,seqid);
              return;
            } catch (Exception e) {
              LOGGER.error("Exception writing to internal frame buffer", e);
            }
            fb.close();
          }
          public void onError(Exception e) {
            byte msgType = org.apache.thrift.protocol.TMessageType.REPLY;
            org.apache.thrift.TBase msg;
            launchTask_result result = new launchTask_result();
            {
              msgType = org.apache.thrift.protocol.TMessageType.EXCEPTION;
              msg = (org.apache.thrift.TBase)new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.INTERNAL_ERROR, e.getMessage());
            }
            try {
              fcall.sendResponse(fb,msg,msgType,seqid);
              return;
            } catch (Exception ex) {
              LOGGER.error("Exception writing to internal frame buffer", ex);
            }
            fb.close();
          }
        };
      }

      protected boolean isOneway() {
        return false;
      }

      public void start(I iface, launchTask_args args, org.apache.thrift.async.AsyncMethodCallback<Void> resultHandler) throws TException {
        iface.launchTask(args.message, args.taskId, args.user,resultHandler);
      }
    }

  }

  public static class launchTask_args implements org.apache.thrift.TBase<launchTask_args, launchTask_args._Fields>, java.io.Serializable, Cloneable, Comparable<launchTask_args>   {
    private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("launchTask_args");

    private static final org.apache.thrift.protocol.TField MESSAGE_FIELD_DESC = new org.apache.thrift.protocol.TField("message", org.apache.thrift.protocol.TType.STRING, (short)1);
    private static final org.apache.thrift.protocol.TField TASK_ID_FIELD_DESC = new org.apache.thrift.protocol.TField("taskId", org.apache.thrift.protocol.TType.STRUCT, (short)2);
    private static final org.apache.thrift.protocol.TField USER_FIELD_DESC = new org.apache.thrift.protocol.TField("user", org.apache.thrift.protocol.TType.STRUCT, (short)3);

    private static final Map<Class<? extends IScheme>, SchemeFactory> schemes = new HashMap<Class<? extends IScheme>, SchemeFactory>();
    static {
      schemes.put(StandardScheme.class, new launchTask_argsStandardSchemeFactory());
      schemes.put(TupleScheme.class, new launchTask_argsTupleSchemeFactory());
    }

    public ByteBuffer message; // required
    public ch.epfl.eagle.thrift.TFullTaskId taskId; // required
    public ch.epfl.eagle.thrift.TUserGroupInfo user; // required

    /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */
    public enum _Fields implements org.apache.thrift.TFieldIdEnum {
      MESSAGE((short)1, "message"),
      TASK_ID((short)2, "taskId"),
      USER((short)3, "user");

      private static final Map<String, _Fields> byName = new HashMap<String, _Fields>();

      static {
        for (_Fields field : EnumSet.allOf(_Fields.class)) {
          byName.put(field.getFieldName(), field);
        }
      }

      /**
       * Find the _Fields constant that matches fieldId, or null if its not found.
       */
      public static _Fields findByThriftId(int fieldId) {
        switch(fieldId) {
          case 1: // MESSAGE
            return MESSAGE;
          case 2: // TASK_ID
            return TASK_ID;
          case 3: // USER
            return USER;
          default:
            return null;
        }
      }

      /**
       * Find the _Fields constant that matches fieldId, throwing an exception
       * if it is not found.
       */
      public static _Fields findByThriftIdOrThrow(int fieldId) {
        _Fields fields = findByThriftId(fieldId);
        if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!");
        return fields;
      }

      /**
       * Find the _Fields constant that matches name, or null if its not found.
       */
      public static _Fields findByName(String name) {
        return byName.get(name);
      }

      private final short _thriftId;
      private final String _fieldName;

      _Fields(short thriftId, String fieldName) {
        _thriftId = thriftId;
        _fieldName = fieldName;
      }

      public short getThriftFieldId() {
        return _thriftId;
      }

      public String getFieldName() {
        return _fieldName;
      }
    }

    // isset id assignments
    public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap;
    static {
      Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class);
      tmpMap.put(_Fields.MESSAGE, new org.apache.thrift.meta_data.FieldMetaData("message", org.apache.thrift.TFieldRequirementType.DEFAULT, 
          new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING          , true)));
      tmpMap.put(_Fields.TASK_ID, new org.apache.thrift.meta_data.FieldMetaData("taskId", org.apache.thrift.TFieldRequirementType.DEFAULT, 
          new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, ch.epfl.eagle.thrift.TFullTaskId.class)));
      tmpMap.put(_Fields.USER, new org.apache.thrift.meta_data.FieldMetaData("user", org.apache.thrift.TFieldRequirementType.DEFAULT, 
          new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, ch.epfl.eagle.thrift.TUserGroupInfo.class)));
      metaDataMap = Collections.unmodifiableMap(tmpMap);
      org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(launchTask_args.class, metaDataMap);
    }

    public launchTask_args() {
    }

    public launchTask_args(
      ByteBuffer message,
      ch.epfl.eagle.thrift.TFullTaskId taskId,
      ch.epfl.eagle.thrift.TUserGroupInfo user)
    {
      this();
      this.message = org.apache.thrift.TBaseHelper.copyBinary(message);
      this.taskId = taskId;
      this.user = user;
    }

    /**
     * Performs a deep copy on <i>other</i>.
     */
    public launchTask_args(launchTask_args other) {
      if (other.isSetMessage()) {
        this.message = org.apache.thrift.TBaseHelper.copyBinary(other.message);
      }
      if (other.isSetTaskId()) {
        this.taskId = new ch.epfl.eagle.thrift.TFullTaskId(other.taskId);
      }
      if (other.isSetUser()) {
        this.user = new ch.epfl.eagle.thrift.TUserGroupInfo(other.user);
      }
    }

    public launchTask_args deepCopy() {
      return new launchTask_args(this);
    }

    @Override
    public void clear() {
      this.message = null;
      this.taskId = null;
      this.user = null;
    }

    public byte[] getMessage() {
      setMessage(org.apache.thrift.TBaseHelper.rightSize(message));
      return message == null ? null : message.array();
    }

    public ByteBuffer bufferForMessage() {
      return org.apache.thrift.TBaseHelper.copyBinary(message);
    }

    public launchTask_args setMessage(byte[] message) {
      this.message = message == null ? (ByteBuffer)null : ByteBuffer.wrap(Arrays.copyOf(message, message.length));
      return this;
    }

    public launchTask_args setMessage(ByteBuffer message) {
      this.message = org.apache.thrift.TBaseHelper.copyBinary(message);
      return this;
    }

    public void unsetMessage() {
      this.message = null;
    }

    /** Returns true if field message is set (has been assigned a value) and false otherwise */
    public boolean isSetMessage() {
      return this.message != null;
    }

    public void setMessageIsSet(boolean value) {
      if (!value) {
        this.message = null;
      }
    }

    public ch.epfl.eagle.thrift.TFullTaskId getTaskId() {
      return this.taskId;
    }

    public launchTask_args setTaskId(ch.epfl.eagle.thrift.TFullTaskId taskId) {
      this.taskId = taskId;
      return this;
    }

    public void unsetTaskId() {
      this.taskId = null;
    }

    /** Returns true if field taskId is set (has been assigned a value) and false otherwise */
    public boolean isSetTaskId() {
      return this.taskId != null;
    }

    public void setTaskIdIsSet(boolean value) {
      if (!value) {
        this.taskId = null;
      }
    }

    public ch.epfl.eagle.thrift.TUserGroupInfo getUser() {
      return this.user;
    }

    public launchTask_args setUser(ch.epfl.eagle.thrift.TUserGroupInfo user) {
      this.user = user;
      return this;
    }

    public void unsetUser() {
      this.user = null;
    }

    /** Returns true if field user is set (has been assigned a value) and false otherwise */
    public boolean isSetUser() {
      return this.user != null;
    }

    public void setUserIsSet(boolean value) {
      if (!value) {
        this.user = null;
      }
    }

    public void setFieldValue(_Fields field, Object value) {
      switch (field) {
      case MESSAGE:
        if (value == null) {
          unsetMessage();
        } else {
          setMessage((ByteBuffer)value);
        }
        break;

      case TASK_ID:
        if (value == null) {
          unsetTaskId();
        } else {
          setTaskId((ch.epfl.eagle.thrift.TFullTaskId)value);
        }
        break;

      case USER:
        if (value == null) {
          unsetUser();
        } else {
          setUser((ch.epfl.eagle.thrift.TUserGroupInfo)value);
        }
        break;

      }
    }

    public Object getFieldValue(_Fields field) {
      switch (field) {
      case MESSAGE:
        return getMessage();

      case TASK_ID:
        return getTaskId();

      case USER:
        return getUser();

      }
      throw new IllegalStateException();
    }

    /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */
    public boolean isSet(_Fields field) {
      if (field == null) {
        throw new IllegalArgumentException();
      }

      switch (field) {
      case MESSAGE:
        return isSetMessage();
      case TASK_ID:
        return isSetTaskId();
      case USER:
        return isSetUser();
      }
      throw new IllegalStateException();
    }

    @Override
    public boolean equals(Object that) {
      if (that == null)
        return false;
      if (that instanceof launchTask_args)
        return this.equals((launchTask_args)that);
      return false;
    }

    public boolean equals(launchTask_args that) {
      if (that == null)
        return false;

      boolean this_present_message = true && this.isSetMessage();
      boolean that_present_message = true && that.isSetMessage();
      if (this_present_message || that_present_message) {
        if (!(this_present_message && that_present_message))
          return false;
        if (!this.message.equals(that.message))
          return false;
      }

      boolean this_present_taskId = true && this.isSetTaskId();
      boolean that_present_taskId = true && that.isSetTaskId();
      if (this_present_taskId || that_present_taskId) {
        if (!(this_present_taskId && that_present_taskId))
          return false;
        if (!this.taskId.equals(that.taskId))
          return false;
      }

      boolean this_present_user = true && this.isSetUser();
      boolean that_present_user = true && that.isSetUser();
      if (this_present_user || that_present_user) {
        if (!(this_present_user && that_present_user))
          return false;
        if (!this.user.equals(that.user))
          return false;
      }

      return true;
    }

    @Override
    public int hashCode() {
      List<Object> list = new ArrayList<Object>();

      boolean present_message = true && (isSetMessage());
      list.add(present_message);
      if (present_message)
        list.add(message);

      boolean present_taskId = true && (isSetTaskId());
      list.add(present_taskId);
      if (present_taskId)
        list.add(taskId);

      boolean present_user = true && (isSetUser());
      list.add(present_user);
      if (present_user)
        list.add(user);

      return list.hashCode();
    }

    @Override
    public int compareTo(launchTask_args other) {
      if (!getClass().equals(other.getClass())) {
        return getClass().getName().compareTo(other.getClass().getName());
      }

      int lastComparison = 0;

      lastComparison = Boolean.valueOf(isSetMessage()).compareTo(other.isSetMessage());
      if (lastComparison != 0) {
        return lastComparison;
      }
      if (isSetMessage()) {
        lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.message, other.message);
        if (lastComparison != 0) {
          return lastComparison;
        }
      }
      lastComparison = Boolean.valueOf(isSetTaskId()).compareTo(other.isSetTaskId());
      if (lastComparison != 0) {
        return lastComparison;
      }
      if (isSetTaskId()) {
        lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.taskId, other.taskId);
        if (lastComparison != 0) {
          return lastComparison;
        }
      }
      lastComparison = Boolean.valueOf(isSetUser()).compareTo(other.isSetUser());
      if (lastComparison != 0) {
        return lastComparison;
      }
      if (isSetUser()) {
        lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.user, other.user);
        if (lastComparison != 0) {
          return lastComparison;
        }
      }
      return 0;
    }

    public _Fields fieldForId(int fieldId) {
      return _Fields.findByThriftId(fieldId);
    }

    public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException {
      schemes.get(iprot.getScheme()).getScheme().read(iprot, this);
    }

    public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException {
      schemes.get(oprot.getScheme()).getScheme().write(oprot, this);
    }

    @Override
    public String toString() {
      StringBuilder sb = new StringBuilder("launchTask_args(");
      boolean first = true;

      sb.append("message:");
      if (this.message == null) {
        sb.append("null");
      } else {
        org.apache.thrift.TBaseHelper.toString(this.message, sb);
      }
      first = false;
      if (!first) sb.append(", ");
      sb.append("taskId:");
      if (this.taskId == null) {
        sb.append("null");
      } else {
        sb.append(this.taskId);
      }
      first = false;
      if (!first) sb.append(", ");
      sb.append("user:");
      if (this.user == null) {
        sb.append("null");
      } else {
        sb.append(this.user);
      }
      first = false;
      sb.append(")");
      return sb.toString();
    }

    public void validate() throws org.apache.thrift.TException {
      // check for required fields
      // check for sub-struct validity
      if (taskId != null) {
        taskId.validate();
      }
      if (user != null) {
        user.validate();
      }
    }

    private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException {
      try {
        write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out)));
      } catch (org.apache.thrift.TException te) {
        throw new java.io.IOException(te);
      }
    }

    private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException {
      try {
        read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in)));
      } catch (org.apache.thrift.TException te) {
        throw new java.io.IOException(te);
      }
    }

    private static class launchTask_argsStandardSchemeFactory implements SchemeFactory {
      public launchTask_argsStandardScheme getScheme() {
        return new launchTask_argsStandardScheme();
      }
    }

    private static class launchTask_argsStandardScheme extends StandardScheme<launchTask_args> {

      public void read(org.apache.thrift.protocol.TProtocol iprot, launchTask_args struct) throws org.apache.thrift.TException {
        org.apache.thrift.protocol.TField schemeField;
        iprot.readStructBegin();
        while (true)
        {
          schemeField = iprot.readFieldBegin();
          if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { 
            break;
          }
          switch (schemeField.id) {
            case 1: // MESSAGE
              if (schemeField.type == org.apache.thrift.protocol.TType.STRING) {
                struct.message = iprot.readBinary();
                struct.setMessageIsSet(true);
              } else { 
                org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
              }
              break;
            case 2: // TASK_ID
              if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) {
                struct.taskId = new ch.epfl.eagle.thrift.TFullTaskId();
                struct.taskId.read(iprot);
                struct.setTaskIdIsSet(true);
              } else { 
                org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
              }
              break;
            case 3: // USER
              if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) {
                struct.user = new ch.epfl.eagle.thrift.TUserGroupInfo();
                struct.user.read(iprot);
                struct.setUserIsSet(true);
              } else { 
                org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
              }
              break;
            default:
              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
          }
          iprot.readFieldEnd();
        }
        iprot.readStructEnd();

        // check for required fields of primitive type, which can't be checked in the validate method
        struct.validate();
      }

      public void write(org.apache.thrift.protocol.TProtocol oprot, launchTask_args struct) throws org.apache.thrift.TException {
        struct.validate();

        oprot.writeStructBegin(STRUCT_DESC);
        if (struct.message != null) {
          oprot.writeFieldBegin(MESSAGE_FIELD_DESC);
          oprot.writeBinary(struct.message);
          oprot.writeFieldEnd();
        }
        if (struct.taskId != null) {
          oprot.writeFieldBegin(TASK_ID_FIELD_DESC);
          struct.taskId.write(oprot);
          oprot.writeFieldEnd();
        }
        if (struct.user != null) {
          oprot.writeFieldBegin(USER_FIELD_DESC);
          struct.user.write(oprot);
          oprot.writeFieldEnd();
        }
        oprot.writeFieldStop();
        oprot.writeStructEnd();
      }

    }

    private static class launchTask_argsTupleSchemeFactory implements SchemeFactory {
      public launchTask_argsTupleScheme getScheme() {
        return new launchTask_argsTupleScheme();
      }
    }

    private static class launchTask_argsTupleScheme extends TupleScheme<launchTask_args> {

      @Override
      public void write(org.apache.thrift.protocol.TProtocol prot, launchTask_args struct) throws org.apache.thrift.TException {
        TTupleProtocol oprot = (TTupleProtocol) prot;
        BitSet optionals = new BitSet();
        if (struct.isSetMessage()) {
          optionals.set(0);
        }
        if (struct.isSetTaskId()) {
          optionals.set(1);
        }
        if (struct.isSetUser()) {
          optionals.set(2);
        }
        oprot.writeBitSet(optionals, 3);
        if (struct.isSetMessage()) {
          oprot.writeBinary(struct.message);
        }
        if (struct.isSetTaskId()) {
          struct.taskId.write(oprot);
        }
        if (struct.isSetUser()) {
          struct.user.write(oprot);
        }
      }

      @Override
      public void read(org.apache.thrift.protocol.TProtocol prot, launchTask_args struct) throws org.apache.thrift.TException {
        TTupleProtocol iprot = (TTupleProtocol) prot;
        BitSet incoming = iprot.readBitSet(3);
        if (incoming.get(0)) {
          struct.message = iprot.readBinary();
          struct.setMessageIsSet(true);
        }
        if (incoming.get(1)) {
          struct.taskId = new ch.epfl.eagle.thrift.TFullTaskId();
          struct.taskId.read(iprot);
          struct.setTaskIdIsSet(true);
        }
        if (incoming.get(2)) {
          struct.user = new ch.epfl.eagle.thrift.TUserGroupInfo();
          struct.user.read(iprot);
          struct.setUserIsSet(true);
        }
      }
    }

  }

  public static class launchTask_result implements org.apache.thrift.TBase<launchTask_result, launchTask_result._Fields>, java.io.Serializable, Cloneable, Comparable<launchTask_result>   {
    private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("launchTask_result");


    private static final Map<Class<? extends IScheme>, SchemeFactory> schemes = new HashMap<Class<? extends IScheme>, SchemeFactory>();
    static {
      schemes.put(StandardScheme.class, new launchTask_resultStandardSchemeFactory());
      schemes.put(TupleScheme.class, new launchTask_resultTupleSchemeFactory());
    }


    /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */
    public enum _Fields implements org.apache.thrift.TFieldIdEnum {
;

      private static final Map<String, _Fields> byName = new HashMap<String, _Fields>();

      static {
        for (_Fields field : EnumSet.allOf(_Fields.class)) {
          byName.put(field.getFieldName(), field);
        }
      }

      /**
       * Find the _Fields constant that matches fieldId, or null if its not found.
       */
      public static _Fields findByThriftId(int fieldId) {
        switch(fieldId) {
          default:
            return null;
        }
      }

      /**
       * Find the _Fields constant that matches fieldId, throwing an exception
       * if it is not found.
       */
      public static _Fields findByThriftIdOrThrow(int fieldId) {
        _Fields fields = findByThriftId(fieldId);
        if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!");
        return fields;
      }

      /**
       * Find the _Fields constant that matches name, or null if its not found.
       */
      public static _Fields findByName(String name) {
        return byName.get(name);
      }

      private final short _thriftId;
      private final String _fieldName;

      _Fields(short thriftId, String fieldName) {
        _thriftId = thriftId;
        _fieldName = fieldName;
      }

      public short getThriftFieldId() {
        return _thriftId;
      }

      public String getFieldName() {
        return _fieldName;
      }
    }
    public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap;
    static {
      Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class);
      metaDataMap = Collections.unmodifiableMap(tmpMap);
      org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(launchTask_result.class, metaDataMap);
    }

    public launchTask_result() {
    }

    /**
     * Performs a deep copy on <i>other</i>.
     */
    public launchTask_result(launchTask_result other) {
    }

    public launchTask_result deepCopy() {
      return new launchTask_result(this);
    }

    @Override
    public void clear() {
    }

    public void setFieldValue(_Fields field, Object value) {
      switch (field) {
      }
    }

    public Object getFieldValue(_Fields field) {
      switch (field) {
      }
      throw new IllegalStateException();
    }

    /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */
    public boolean isSet(_Fields field) {
      if (field == null) {
        throw new IllegalArgumentException();
      }

      switch (field) {
      }
      throw new IllegalStateException();
    }

    @Override
    public boolean equals(Object that) {
      if (that == null)
        return false;
      if (that instanceof launchTask_result)
        return this.equals((launchTask_result)that);
      return false;
    }

    public boolean equals(launchTask_result that) {
      if (that == null)
        return false;

      return true;
    }

    @Override
    public int hashCode() {
      List<Object> list = new ArrayList<Object>();

      return list.hashCode();
    }

    @Override
    public int compareTo(launchTask_result other) {
      if (!getClass().equals(other.getClass())) {
        return getClass().getName().compareTo(other.getClass().getName());
      }

      int lastComparison = 0;

      return 0;
    }

    public _Fields fieldForId(int fieldId) {
      return _Fields.findByThriftId(fieldId);
    }

    public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException {
      schemes.get(iprot.getScheme()).getScheme().read(iprot, this);
    }

    public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException {
      schemes.get(oprot.getScheme()).getScheme().write(oprot, this);
      }

    @Override
    public String toString() {
      StringBuilder sb = new StringBuilder("launchTask_result(");
      boolean first = true;

      sb.append(")");
      return sb.toString();
    }

    public void validate() throws org.apache.thrift.TException {
      // check for required fields
      // check for sub-struct validity
    }

    private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException {
      try {
        write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out)));
      } catch (org.apache.thrift.TException te) {
        throw new java.io.IOException(te);
      }
    }

    private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException {
      try {
        read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in)));
      } catch (org.apache.thrift.TException te) {
        throw new java.io.IOException(te);
      }
    }

    private static class launchTask_resultStandardSchemeFactory implements SchemeFactory {
      public launchTask_resultStandardScheme getScheme() {
        return new launchTask_resultStandardScheme();
      }
    }

    private static class launchTask_resultStandardScheme extends StandardScheme<launchTask_result> {

      public void read(org.apache.thrift.protocol.TProtocol iprot, launchTask_result struct) throws org.apache.thrift.TException {
        org.apache.thrift.protocol.TField schemeField;
        iprot.readStructBegin();
        while (true)
        {
          schemeField = iprot.readFieldBegin();
          if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { 
            break;
          }
          switch (schemeField.id) {
            default:
              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
          }
          iprot.readFieldEnd();
        }
        iprot.readStructEnd();

        // check for required fields of primitive type, which can't be checked in the validate method
        struct.validate();
      }

      public void write(org.apache.thrift.protocol.TProtocol oprot, launchTask_result struct) throws org.apache.thrift.TException {
        struct.validate();

        oprot.writeStructBegin(STRUCT_DESC);
        oprot.writeFieldStop();
        oprot.writeStructEnd();
      }

    }

    private static class launchTask_resultTupleSchemeFactory implements SchemeFactory {
      public launchTask_resultTupleScheme getScheme() {
        return new launchTask_resultTupleScheme();
      }
    }

    private static class launchTask_resultTupleScheme extends TupleScheme<launchTask_result> {

      @Override
      public void write(org.apache.thrift.protocol.TProtocol prot, launchTask_result struct) throws org.apache.thrift.TException {
        TTupleProtocol oprot = (TTupleProtocol) prot;
      }

      @Override
      public void read(org.apache.thrift.protocol.TProtocol prot, launchTask_result struct) throws org.apache.thrift.TException {
        TTupleProtocol iprot = (TTupleProtocol) prot;
      }
    }

  }

} @SuppressWarnings({"cast", "rawtypes", "serial", "unchecked"})
@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2016-03-03")
public class GetTaskService {

  public interface Iface {

    public List<ch.epfl.eagle.thrift.TTaskLaunchSpec> getTask(String requestId, ch.epfl.eagle.thrift.THostPort nodeMonitorAddress, ch.epfl.eagle.thrift.THostPort oldNodeMonitorAddress) throws org.apache.thrift.TException;

  }

  public interface AsyncIface {

    public void getTask(String requestId, ch.epfl.eagle.thrift.THostPort nodeMonitorAddress, ch.epfl.eagle.thrift.THostPort oldNodeMonitorAddress, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException;

  }

  public static class Client extends org.apache.thrift.TServiceClient implements Iface {
    public static class Factory implements org.apache.thrift.TServiceClientFactory<Client> {
      public Factory() {}
      public Client getClient(org.apache.thrift.protocol.TProtocol prot) {
        return new Client(prot);
      }
      public Client getClient(org.apache.thrift.protocol.TProtocol iprot, org.apache.thrift.protocol.TProtocol oprot) {
        return new Client(iprot, oprot);
      }
    }

    public Client(org.apache.thrift.protocol.TProtocol prot)
    {
      super(prot, prot);
    }

    public Client(org.apache.thrift.protocol.TProtocol iprot, org.apache.thrift.protocol.TProtocol oprot) {
      super(iprot, oprot);
    }

    public List<ch.epfl.eagle.thrift.TTaskLaunchSpec> getTask(String requestId, ch.epfl.eagle.thrift.THostPort nodeMonitorAddress, ch.epfl.eagle.thrift.THostPort oldNodeMonitorAddress) throws org.apache.thrift.TException
    {
      send_getTask(requestId, nodeMonitorAddress, oldNodeMonitorAddress);
      return recv_getTask();
    }

    public void send_getTask(String requestId, ch.epfl.eagle.thrift.THostPort nodeMonitorAddress, ch.epfl.eagle.thrift.THostPort oldNodeMonitorAddress) throws org.apache.thrift.TException
    {
      getTask_args args = new getTask_args();
      args.setRequestId(requestId);
      args.setNodeMonitorAddress(nodeMonitorAddress);
      args.setOldNodeMonitorAddress(oldNodeMonitorAddress);
      sendBase("getTask", args);
    }

    public List<ch.epfl.eagle.thrift.TTaskLaunchSpec> recv_getTask() throws org.apache.thrift.TException
    {
      getTask_result result = new getTask_result();
      receiveBase(result, "getTask");
      if (result.isSetSuccess()) {
        return result.success;
      }
      throw new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.MISSING_RESULT, "getTask failed: unknown result");
    }

  }
  public static class AsyncClient extends org.apache.thrift.async.TAsyncClient implements AsyncIface {
    public static class Factory implements org.apache.thrift.async.TAsyncClientFactory<AsyncClient> {
      private org.apache.thrift.async.TAsyncClientManager clientManager;
      private org.apache.thrift.protocol.TProtocolFactory protocolFactory;
      public Factory(org.apache.thrift.async.TAsyncClientManager clientManager, org.apache.thrift.protocol.TProtocolFactory protocolFactory) {
        this.clientManager = clientManager;
        this.protocolFactory = protocolFactory;
      }
      public AsyncClient getAsyncClient(org.apache.thrift.transport.TNonblockingTransport transport) {
        return new AsyncClient(protocolFactory, clientManager, transport);
      }
    }

    public AsyncClient(org.apache.thrift.protocol.TProtocolFactory protocolFactory, org.apache.thrift.async.TAsyncClientManager clientManager, org.apache.thrift.transport.TNonblockingTransport transport) {
      super(protocolFactory, clientManager, transport);
    }

    public void getTask(String requestId, ch.epfl.eagle.thrift.THostPort nodeMonitorAddress, ch.epfl.eagle.thrift.THostPort oldNodeMonitorAddress, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException {
      checkReady();
      getTask_call method_call = new getTask_call(requestId, nodeMonitorAddress, oldNodeMonitorAddress, resultHandler, this, ___protocolFactory, ___transport);
      this.___currentMethod = method_call;
      ___manager.call(method_call);
    }

    public static class getTask_call extends org.apache.thrift.async.TAsyncMethodCall {
      private String requestId;
      private ch.epfl.eagle.thrift.THostPort nodeMonitorAddress;
      private ch.epfl.eagle.thrift.THostPort oldNodeMonitorAddress;
      public getTask_call(String requestId, ch.epfl.eagle.thrift.THostPort nodeMonitorAddress, ch.epfl.eagle.thrift.THostPort oldNodeMonitorAddress, org.apache.thrift.async.AsyncMethodCallback resultHandler, org.apache.thrift.async.TAsyncClient client, org.apache.thrift.protocol.TProtocolFactory protocolFactory, org.apache.thrift.transport.TNonblockingTransport transport) throws org.apache.thrift.TException {
        super(client, protocolFactory, transport, resultHandler, false);
        this.requestId = requestId;
        this.nodeMonitorAddress = nodeMonitorAddress;
        this.oldNodeMonitorAddress = oldNodeMonitorAddress;
      }

      public void write_args(org.apache.thrift.protocol.TProtocol prot) throws org.apache.thrift.TException {
        prot.writeMessageBegin(new org.apache.thrift.protocol.TMessage("getTask", org.apache.thrift.protocol.TMessageType.CALL, 0));
        getTask_args args = new getTask_args();
        args.setRequestId(requestId);
        args.setNodeMonitorAddress(nodeMonitorAddress);
        args.setOldNodeMonitorAddress(oldNodeMonitorAddress);
        args.write(prot);
        prot.writeMessageEnd();
      }

      public List<ch.epfl.eagle.thrift.TTaskLaunchSpec> getResult() throws org.apache.thrift.TException {
        if (getState() != org.apache.thrift.async.TAsyncMethodCall.State.RESPONSE_READ) {
          throw new IllegalStateException("Method call not finished!");
        }
        org.apache.thrift.transport.TMemoryInputTransport memoryTransport = new org.apache.thrift.transport.TMemoryInputTransport(getFrameBuffer().array());
        org.apache.thrift.protocol.TProtocol prot = client.getProtocolFactory().getProtocol(memoryTransport);
        return (new Client(prot)).recv_getTask();
      }
    }

  }

  public static class Processor<I extends Iface> extends org.apache.thrift.TBaseProcessor<I> implements org.apache.thrift.TProcessor {
    private static final Logger LOGGER = LoggerFactory.getLogger(Processor.class.getName());
    public Processor(I iface) {
      super(iface, getProcessMap(new HashMap<String, org.apache.thrift.ProcessFunction<I, ? extends org.apache.thrift.TBase>>()));
    }

    protected Processor(I iface, Map<String,  org.apache.thrift.ProcessFunction<I, ? extends  org.apache.thrift.TBase>> processMap) {
      super(iface, getProcessMap(processMap));
    }

    private static <I extends Iface> Map<String,  org.apache.thrift.ProcessFunction<I, ? extends  org.apache.thrift.TBase>> getProcessMap(Map<String,  org.apache.thrift.ProcessFunction<I, ? extends  org.apache.thrift.TBase>> processMap) {
      processMap.put("getTask", new getTask());
      return processMap;
    }

    public static class getTask<I extends Iface> extends org.apache.thrift.ProcessFunction<I, getTask_args> {
      public getTask() {
        super("getTask");
      }

      public getTask_args getEmptyArgsInstance() {
        return new getTask_args();
      }

      protected boolean isOneway() {
        return false;
      }

      public getTask_result getResult(I iface, getTask_args args) throws org.apache.thrift.TException {
        getTask_result result = new getTask_result();
        result.success = iface.getTask(args.requestId, args.nodeMonitorAddress, args.oldNodeMonitorAddress);
        return result;
      }
    }

  }

  public static class AsyncProcessor<I extends AsyncIface> extends org.apache.thrift.TBaseAsyncProcessor<I> {
    private static final Logger LOGGER = LoggerFactory.getLogger(AsyncProcessor.class.getName());
    public AsyncProcessor(I iface) {
      super(iface, getProcessMap(new HashMap<String, org.apache.thrift.AsyncProcessFunction<I, ? extends org.apache.thrift.TBase, ?>>()));
    }

    protected AsyncProcessor(I iface, Map<String,  org.apache.thrift.AsyncProcessFunction<I, ? extends  org.apache.thrift.TBase, ?>> processMap) {
      super(iface, getProcessMap(processMap));
    }

    private static <I extends AsyncIface> Map<String,  org.apache.thrift.AsyncProcessFunction<I, ? extends  org.apache.thrift.TBase,?>> getProcessMap(Map<String,  org.apache.thrift.AsyncProcessFunction<I, ? extends  org.apache.thrift.TBase, ?>> processMap) {
      processMap.put("getTask", new getTask());
      return processMap;
    }

    public static class getTask<I extends AsyncIface> extends org.apache.thrift.AsyncProcessFunction<I, getTask_args, List<ch.epfl.eagle.thrift.TTaskLaunchSpec>> {
      public getTask() {
        super("getTask");
      }

      public getTask_args getEmptyArgsInstance() {
        return new getTask_args();
      }

      public AsyncMethodCallback<List<ch.epfl.eagle.thrift.TTaskLaunchSpec>> getResultHandler(final AsyncFrameBuffer fb, final int seqid) {
        final org.apache.thrift.AsyncProcessFunction fcall = this;
        return new AsyncMethodCallback<List<ch.epfl.eagle.thrift.TTaskLaunchSpec>>() { 
          public void onComplete(List<ch.epfl.eagle.thrift.TTaskLaunchSpec> o) {
            getTask_result result = new getTask_result();
            result.success = o;
            try {
              fcall.sendResponse(fb,result, org.apache.thrift.protocol.TMessageType.REPLY,seqid);
              return;
            } catch (Exception e) {
              LOGGER.error("Exception writing to internal frame buffer", e);
            }
            fb.close();
          }
          public void onError(Exception e) {
            byte msgType = org.apache.thrift.protocol.TMessageType.REPLY;
            org.apache.thrift.TBase msg;
            getTask_result result = new getTask_result();
            {
              msgType = org.apache.thrift.protocol.TMessageType.EXCEPTION;
              msg = (org.apache.thrift.TBase)new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.INTERNAL_ERROR, e.getMessage());
            }
            try {
              fcall.sendResponse(fb,msg,msgType,seqid);
              return;
            } catch (Exception ex) {
              LOGGER.error("Exception writing to internal frame buffer", ex);
            }
            fb.close();
          }
        };
      }

      protected boolean isOneway() {
        return false;
      }

      public void start(I iface, getTask_args args, org.apache.thrift.async.AsyncMethodCallback<List<ch.epfl.eagle.thrift.TTaskLaunchSpec>> resultHandler) throws TException {
        iface.getTask(args.requestId, args.nodeMonitorAddress, args.oldNodeMonitorAddress,resultHandler);
      }
    }

  }

  public static class getTask_args implements org.apache.thrift.TBase<getTask_args, getTask_args._Fields>, java.io.Serializable, Cloneable, Comparable<getTask_args>   {
    private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("getTask_args");

    private static final org.apache.thrift.protocol.TField REQUEST_ID_FIELD_DESC = new org.apache.thrift.protocol.TField("requestId", org.apache.thrift.protocol.TType.STRING, (short)1);
    private static final org.apache.thrift.protocol.TField NODE_MONITOR_ADDRESS_FIELD_DESC = new org.apache.thrift.protocol.TField("nodeMonitorAddress", org.apache.thrift.protocol.TType.STRUCT, (short)2);
    private static final org.apache.thrift.protocol.TField OLD_NODE_MONITOR_ADDRESS_FIELD_DESC = new org.apache.thrift.protocol.TField("oldNodeMonitorAddress", org.apache.thrift.protocol.TType.STRUCT, (short)3);

    private static final Map<Class<? extends IScheme>, SchemeFactory> schemes = new HashMap<Class<? extends IScheme>, SchemeFactory>();
    static {
      schemes.put(StandardScheme.class, new getTask_argsStandardSchemeFactory());
      schemes.put(TupleScheme.class, new getTask_argsTupleSchemeFactory());
    }

    public String requestId; // required
    public ch.epfl.eagle.thrift.THostPort nodeMonitorAddress; // required
    public ch.epfl.eagle.thrift.THostPort oldNodeMonitorAddress; // required

    /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */
    public enum _Fields implements org.apache.thrift.TFieldIdEnum {
      REQUEST_ID((short)1, "requestId"),
      NODE_MONITOR_ADDRESS((short)2, "nodeMonitorAddress"),
      OLD_NODE_MONITOR_ADDRESS((short)3, "oldNodeMonitorAddress");

      private static final Map<String, _Fields> byName = new HashMap<String, _Fields>();

      static {
        for (_Fields field : EnumSet.allOf(_Fields.class)) {
          byName.put(field.getFieldName(), field);
        }
      }

      /**
       * Find the _Fields constant that matches fieldId, or null if its not found.
       */
      public static _Fields findByThriftId(int fieldId) {
        switch(fieldId) {
          case 1: // REQUEST_ID
            return REQUEST_ID;
          case 2: // NODE_MONITOR_ADDRESS
            return NODE_MONITOR_ADDRESS;
          case 3: // OLD_NODE_MONITOR_ADDRESS
            return OLD_NODE_MONITOR_ADDRESS;
          default:
            return null;
        }
      }

      /**
       * Find the _Fields constant that matches fieldId, throwing an exception
       * if it is not found.
       */
      public static _Fields findByThriftIdOrThrow(int fieldId) {
        _Fields fields = findByThriftId(fieldId);
        if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!");
        return fields;
      }

      /**
       * Find the _Fields constant that matches name, or null if its not found.
       */
      public static _Fields findByName(String name) {
        return byName.get(name);
      }

      private final short _thriftId;
      private final String _fieldName;

      _Fields(short thriftId, String fieldName) {
        _thriftId = thriftId;
        _fieldName = fieldName;
      }

      public short getThriftFieldId() {
        return _thriftId;
      }

      public String getFieldName() {
        return _fieldName;
      }
    }

    // isset id assignments
    public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap;
    static {
      Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class);
      tmpMap.put(_Fields.REQUEST_ID, new org.apache.thrift.meta_data.FieldMetaData("requestId", org.apache.thrift.TFieldRequirementType.DEFAULT, 
          new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING)));
      tmpMap.put(_Fields.NODE_MONITOR_ADDRESS, new org.apache.thrift.meta_data.FieldMetaData("nodeMonitorAddress", org.apache.thrift.TFieldRequirementType.DEFAULT, 
          new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, ch.epfl.eagle.thrift.THostPort.class)));
      tmpMap.put(_Fields.OLD_NODE_MONITOR_ADDRESS, new org.apache.thrift.meta_data.FieldMetaData("oldNodeMonitorAddress", org.apache.thrift.TFieldRequirementType.DEFAULT, 
          new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, ch.epfl.eagle.thrift.THostPort.class)));
      metaDataMap = Collections.unmodifiableMap(tmpMap);
      org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(getTask_args.class, metaDataMap);
    }

    public getTask_args() {
    }

    public getTask_args(
      String requestId,
      ch.epfl.eagle.thrift.THostPort nodeMonitorAddress,
      ch.epfl.eagle.thrift.THostPort oldNodeMonitorAddress)
    {
      this();
      this.requestId = requestId;
      this.nodeMonitorAddress = nodeMonitorAddress;
      this.oldNodeMonitorAddress = oldNodeMonitorAddress;
    }

    /**
     * Performs a deep copy on <i>other</i>.
     */
    public getTask_args(getTask_args other) {
      if (other.isSetRequestId()) {
        this.requestId = other.requestId;
      }
      if (other.isSetNodeMonitorAddress()) {
        this.nodeMonitorAddress = new ch.epfl.eagle.thrift.THostPort(other.nodeMonitorAddress);
      }
      if (other.isSetOldNodeMonitorAddress()) {
        this.oldNodeMonitorAddress = new ch.epfl.eagle.thrift.THostPort(other.oldNodeMonitorAddress);
      }
    }

    public getTask_args deepCopy() {
      return new getTask_args(this);
    }

    @Override
    public void clear() {
      this.requestId = null;
      this.nodeMonitorAddress = null;
      this.oldNodeMonitorAddress = null;
    }

    public String getRequestId() {
      return this.requestId;
    }

    public getTask_args setRequestId(String requestId) {
      this.requestId = requestId;
      return this;
    }

    public void unsetRequestId() {
      this.requestId = null;
    }

    /** Returns true if field requestId is set (has been assigned a value) and false otherwise */
    public boolean isSetRequestId() {
      return this.requestId != null;
    }

    public void setRequestIdIsSet(boolean value) {
      if (!value) {
        this.requestId = null;
      }
    }

    public ch.epfl.eagle.thrift.THostPort getNodeMonitorAddress() {
      return this.nodeMonitorAddress;
    }

    public getTask_args setNodeMonitorAddress(ch.epfl.eagle.thrift.THostPort nodeMonitorAddress) {
      this.nodeMonitorAddress = nodeMonitorAddress;
      return this;
    }

    public void unsetNodeMonitorAddress() {
      this.nodeMonitorAddress = null;
    }

    /** Returns true if field nodeMonitorAddress is set (has been assigned a value) and false otherwise */
    public boolean isSetNodeMonitorAddress() {
      return this.nodeMonitorAddress != null;
    }

    public void setNodeMonitorAddressIsSet(boolean value) {
      if (!value) {
        this.nodeMonitorAddress = null;
      }
    }

    public ch.epfl.eagle.thrift.THostPort getOldNodeMonitorAddress() {
      return this.oldNodeMonitorAddress;
    }

    public getTask_args setOldNodeMonitorAddress(ch.epfl.eagle.thrift.THostPort oldNodeMonitorAddress) {
      this.oldNodeMonitorAddress = oldNodeMonitorAddress;
      return this;
    }

    public void unsetOldNodeMonitorAddress() {
      this.oldNodeMonitorAddress = null;
    }

    /** Returns true if field oldNodeMonitorAddress is set (has been assigned a value) and false otherwise */
    public boolean isSetOldNodeMonitorAddress() {
      return this.oldNodeMonitorAddress != null;
    }

    public void setOldNodeMonitorAddressIsSet(boolean value) {
      if (!value) {
        this.oldNodeMonitorAddress = null;
      }
    }

    public void setFieldValue(_Fields field, Object value) {
      switch (field) {
      case REQUEST_ID:
        if (value == null) {
          unsetRequestId();
        } else {
          setRequestId((String)value);
        }
        break;

      case NODE_MONITOR_ADDRESS:
        if (value == null) {
          unsetNodeMonitorAddress();
        } else {
          setNodeMonitorAddress((ch.epfl.eagle.thrift.THostPort)value);
        }
        break;

      case OLD_NODE_MONITOR_ADDRESS:
        if (value == null) {
          unsetOldNodeMonitorAddress();
        } else {
          setOldNodeMonitorAddress((ch.epfl.eagle.thrift.THostPort)value);
        }
        break;

      }
    }

    public Object getFieldValue(_Fields field) {
      switch (field) {
      case REQUEST_ID:
        return getRequestId();

      case NODE_MONITOR_ADDRESS:
        return getNodeMonitorAddress();

      case OLD_NODE_MONITOR_ADDRESS:
        return getOldNodeMonitorAddress();

      }
      throw new IllegalStateException();
    }

    /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */
    public boolean isSet(_Fields field) {
      if (field == null) {
        throw new IllegalArgumentException();
      }

      switch (field) {
      case REQUEST_ID:
        return isSetRequestId();
      case NODE_MONITOR_ADDRESS:
        return isSetNodeMonitorAddress();
      case OLD_NODE_MONITOR_ADDRESS:
        return isSetOldNodeMonitorAddress();
      }
      throw new IllegalStateException();
    }

    @Override
    public boolean equals(Object that) {
      if (that == null)
        return false;
      if (that instanceof getTask_args)
        return this.equals((getTask_args)that);
      return false;
    }

    public boolean equals(getTask_args that) {
      if (that == null)
        return false;

      boolean this_present_requestId = true && this.isSetRequestId();
      boolean that_present_requestId = true && that.isSetRequestId();
      if (this_present_requestId || that_present_requestId) {
        if (!(this_present_requestId && that_present_requestId))
          return false;
        if (!this.requestId.equals(that.requestId))
          return false;
      }

      boolean this_present_nodeMonitorAddress = true && this.isSetNodeMonitorAddress();
      boolean that_present_nodeMonitorAddress = true && that.isSetNodeMonitorAddress();
      if (this_present_nodeMonitorAddress || that_present_nodeMonitorAddress) {
        if (!(this_present_nodeMonitorAddress && that_present_nodeMonitorAddress))
          return false;
        if (!this.nodeMonitorAddress.equals(that.nodeMonitorAddress))
          return false;
      }

      boolean this_present_oldNodeMonitorAddress = true && this.isSetOldNodeMonitorAddress();
      boolean that_present_oldNodeMonitorAddress = true && that.isSetOldNodeMonitorAddress();
      if (this_present_oldNodeMonitorAddress || that_present_oldNodeMonitorAddress) {
        if (!(this_present_oldNodeMonitorAddress && that_present_oldNodeMonitorAddress))
          return false;
        if (!this.oldNodeMonitorAddress.equals(that.oldNodeMonitorAddress))
          return false;
      }

      return true;
    }

    @Override
    public int hashCode() {
      List<Object> list = new ArrayList<Object>();

      boolean present_requestId = true && (isSetRequestId());
      list.add(present_requestId);
      if (present_requestId)
        list.add(requestId);

      boolean present_nodeMonitorAddress = true && (isSetNodeMonitorAddress());
      list.add(present_nodeMonitorAddress);
      if (present_nodeMonitorAddress)
        list.add(nodeMonitorAddress);

      boolean present_oldNodeMonitorAddress = true && (isSetOldNodeMonitorAddress());
      list.add(present_oldNodeMonitorAddress);
      if (present_oldNodeMonitorAddress)
        list.add(oldNodeMonitorAddress);

      return list.hashCode();
    }

    @Override
    public int compareTo(getTask_args other) {
      if (!getClass().equals(other.getClass())) {
        return getClass().getName().compareTo(other.getClass().getName());
      }

      int lastComparison = 0;

      lastComparison = Boolean.valueOf(isSetRequestId()).compareTo(other.isSetRequestId());
      if (lastComparison != 0) {
        return lastComparison;
      }
      if (isSetRequestId()) {
        lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.requestId, other.requestId);
        if (lastComparison != 0) {
          return lastComparison;
        }
      }
      lastComparison = Boolean.valueOf(isSetNodeMonitorAddress()).compareTo(other.isSetNodeMonitorAddress());
      if (lastComparison != 0) {
        return lastComparison;
      }
      if (isSetNodeMonitorAddress()) {
        lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.nodeMonitorAddress, other.nodeMonitorAddress);
        if (lastComparison != 0) {
          return lastComparison;
        }
      }
      lastComparison = Boolean.valueOf(isSetOldNodeMonitorAddress()).compareTo(other.isSetOldNodeMonitorAddress());
      if (lastComparison != 0) {
        return lastComparison;
      }
      if (isSetOldNodeMonitorAddress()) {
        lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.oldNodeMonitorAddress, other.oldNodeMonitorAddress);
        if (lastComparison != 0) {
          return lastComparison;
        }
      }
      return 0;
    }

    public _Fields fieldForId(int fieldId) {
      return _Fields.findByThriftId(fieldId);
    }

    public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException {
      schemes.get(iprot.getScheme()).getScheme().read(iprot, this);
    }

    public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException {
      schemes.get(oprot.getScheme()).getScheme().write(oprot, this);
    }

    @Override
    public String toString() {
      StringBuilder sb = new StringBuilder("getTask_args(");
      boolean first = true;

      sb.append("requestId:");
      if (this.requestId == null) {
        sb.append("null");
      } else {
        sb.append(this.requestId);
      }
      first = false;
      if (!first) sb.append(", ");
      sb.append("nodeMonitorAddress:");
      if (this.nodeMonitorAddress == null) {
        sb.append("null");
      } else {
        sb.append(this.nodeMonitorAddress);
      }
      first = false;
      if (!first) sb.append(", ");
      sb.append("oldNodeMonitorAddress:");
      if (this.oldNodeMonitorAddress == null) {
        sb.append("null");
      } else {
        sb.append(this.oldNodeMonitorAddress);
      }
      first = false;
      sb.append(")");
      return sb.toString();
    }

    public void validate() throws org.apache.thrift.TException {
      // check for required fields
      // check for sub-struct validity
      if (nodeMonitorAddress != null) {
        nodeMonitorAddress.validate();
      }
      if (oldNodeMonitorAddress != null) {
        oldNodeMonitorAddress.validate();
      }
    }

    private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException {
      try {
        write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out)));
      } catch (org.apache.thrift.TException te) {
        throw new java.io.IOException(te);
      }
    }

    private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException {
      try {
        read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in)));
      } catch (org.apache.thrift.TException te) {
        throw new java.io.IOException(te);
      }
    }

    private static class getTask_argsStandardSchemeFactory implements SchemeFactory {
      public getTask_argsStandardScheme getScheme() {
        return new getTask_argsStandardScheme();
      }
    }

    private static class getTask_argsStandardScheme extends StandardScheme<getTask_args> {

      public void read(org.apache.thrift.protocol.TProtocol iprot, getTask_args struct) throws org.apache.thrift.TException {
        org.apache.thrift.protocol.TField schemeField;
        iprot.readStructBegin();
        while (true)
        {
          schemeField = iprot.readFieldBegin();
          if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { 
            break;
          }
          switch (schemeField.id) {
            case 1: // REQUEST_ID
              if (schemeField.type == org.apache.thrift.protocol.TType.STRING) {
                struct.requestId = iprot.readString();
                struct.setRequestIdIsSet(true);
              } else { 
                org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
              }
              break;
            case 2: // NODE_MONITOR_ADDRESS
              if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) {
                struct.nodeMonitorAddress = new ch.epfl.eagle.thrift.THostPort();
                struct.nodeMonitorAddress.read(iprot);
                struct.setNodeMonitorAddressIsSet(true);
              } else { 
                org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
              }
              break;
            case 3: // OLD_NODE_MONITOR_ADDRESS
              if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) {
                struct.oldNodeMonitorAddress = new ch.epfl.eagle.thrift.THostPort();
                struct.oldNodeMonitorAddress.read(iprot);
                struct.setOldNodeMonitorAddressIsSet(true);
              } else { 
                org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
              }
              break;
            default:
              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
          }
          iprot.readFieldEnd();
        }
        iprot.readStructEnd();

        // check for required fields of primitive type, which can't be checked in the validate method
        struct.validate();
      }

      public void write(org.apache.thrift.protocol.TProtocol oprot, getTask_args struct) throws org.apache.thrift.TException {
        struct.validate();

        oprot.writeStructBegin(STRUCT_DESC);
        if (struct.requestId != null) {
          oprot.writeFieldBegin(REQUEST_ID_FIELD_DESC);
          oprot.writeString(struct.requestId);
          oprot.writeFieldEnd();
        }
        if (struct.nodeMonitorAddress != null) {
          oprot.writeFieldBegin(NODE_MONITOR_ADDRESS_FIELD_DESC);
          struct.nodeMonitorAddress.write(oprot);
          oprot.writeFieldEnd();
        }
        if (struct.oldNodeMonitorAddress != null) {
          oprot.writeFieldBegin(OLD_NODE_MONITOR_ADDRESS_FIELD_DESC);
          struct.oldNodeMonitorAddress.write(oprot);
          oprot.writeFieldEnd();
        }
        oprot.writeFieldStop();
        oprot.writeStructEnd();
      }

    }

    private static class getTask_argsTupleSchemeFactory implements SchemeFactory {
      public getTask_argsTupleScheme getScheme() {
        return new getTask_argsTupleScheme();
      }
    }

    private static class getTask_argsTupleScheme extends TupleScheme<getTask_args> {

      @Override
      public void write(org.apache.thrift.protocol.TProtocol prot, getTask_args struct) throws org.apache.thrift.TException {
        TTupleProtocol oprot = (TTupleProtocol) prot;
        BitSet optionals = new BitSet();
        if (struct.isSetRequestId()) {
          optionals.set(0);
        }
        if (struct.isSetNodeMonitorAddress()) {
          optionals.set(1);
        }
        if (struct.isSetOldNodeMonitorAddress()) {
          optionals.set(2);
        }
        oprot.writeBitSet(optionals, 3);
        if (struct.isSetRequestId()) {
          oprot.writeString(struct.requestId);
        }
        if (struct.isSetNodeMonitorAddress()) {
          struct.nodeMonitorAddress.write(oprot);
        }
        if (struct.isSetOldNodeMonitorAddress()) {
          struct.oldNodeMonitorAddress.write(oprot);
        }
      }

      @Override
      public void read(org.apache.thrift.protocol.TProtocol prot, getTask_args struct) throws org.apache.thrift.TException {
        TTupleProtocol iprot = (TTupleProtocol) prot;
        BitSet incoming = iprot.readBitSet(3);
        if (incoming.get(0)) {
          struct.requestId = iprot.readString();
          struct.setRequestIdIsSet(true);
        }
        if (incoming.get(1)) {
          struct.nodeMonitorAddress = new ch.epfl.eagle.thrift.THostPort();
          struct.nodeMonitorAddress.read(iprot);
          struct.setNodeMonitorAddressIsSet(true);
        }
        if (incoming.get(2)) {
          struct.oldNodeMonitorAddress = new ch.epfl.eagle.thrift.THostPort();
          struct.oldNodeMonitorAddress.read(iprot);
          struct.setOldNodeMonitorAddressIsSet(true);
        }
      }
    }

  }

  public static class getTask_result implements org.apache.thrift.TBase<getTask_result, getTask_result._Fields>, java.io.Serializable, Cloneable, Comparable<getTask_result>   {
    private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("getTask_result");

    private static final org.apache.thrift.protocol.TField SUCCESS_FIELD_DESC = new org.apache.thrift.protocol.TField("success", org.apache.thrift.protocol.TType.LIST, (short)0);

    private static final Map<Class<? extends IScheme>, SchemeFactory> schemes = new HashMap<Class<? extends IScheme>, SchemeFactory>();
    static {
      schemes.put(StandardScheme.class, new getTask_resultStandardSchemeFactory());
      schemes.put(TupleScheme.class, new getTask_resultTupleSchemeFactory());
    }

    public List<ch.epfl.eagle.thrift.TTaskLaunchSpec> success; // required

    /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */
    public enum _Fields implements org.apache.thrift.TFieldIdEnum {
      SUCCESS((short)0, "success");

      private static final Map<String, _Fields> byName = new HashMap<String, _Fields>();

      static {
        for (_Fields field : EnumSet.allOf(_Fields.class)) {
          byName.put(field.getFieldName(), field);
        }
      }

      /**
       * Find the _Fields constant that matches fieldId, or null if its not found.
       */
      public static _Fields findByThriftId(int fieldId) {
        switch(fieldId) {
          case 0: // SUCCESS
            return SUCCESS;
          default:
            return null;
        }
      }

      /**
       * Find the _Fields constant that matches fieldId, throwing an exception
       * if it is not found.
       */
      public static _Fields findByThriftIdOrThrow(int fieldId) {
        _Fields fields = findByThriftId(fieldId);
        if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!");
        return fields;
      }

      /**
       * Find the _Fields constant that matches name, or null if its not found.
       */
      public static _Fields findByName(String name) {
        return byName.get(name);
      }

      private final short _thriftId;
      private final String _fieldName;

      _Fields(short thriftId, String fieldName) {
        _thriftId = thriftId;
        _fieldName = fieldName;
      }

      public short getThriftFieldId() {
        return _thriftId;
      }

      public String getFieldName() {
        return _fieldName;
      }
    }

    // isset id assignments
    public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap;
    static {
      Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class);
      tmpMap.put(_Fields.SUCCESS, new org.apache.thrift.meta_data.FieldMetaData("success", org.apache.thrift.TFieldRequirementType.DEFAULT, 
          new org.apache.thrift.meta_data.ListMetaData(org.apache.thrift.protocol.TType.LIST, 
              new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, ch.epfl.eagle.thrift.TTaskLaunchSpec.class))));
      metaDataMap = Collections.unmodifiableMap(tmpMap);
      org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(getTask_result.class, metaDataMap);
    }

    public getTask_result() {
    }

    public getTask_result(
      List<ch.epfl.eagle.thrift.TTaskLaunchSpec> success)
    {
      this();
      this.success = success;
    }

    /**
     * Performs a deep copy on <i>other</i>.
     */
    public getTask_result(getTask_result other) {
      if (other.isSetSuccess()) {
        List<ch.epfl.eagle.thrift.TTaskLaunchSpec> __this__success = new ArrayList<ch.epfl.eagle.thrift.TTaskLaunchSpec>(other.success.size());
        for (ch.epfl.eagle.thrift.TTaskLaunchSpec other_element : other.success) {
          __this__success.add(new ch.epfl.eagle.thrift.TTaskLaunchSpec(other_element));
        }
        this.success = __this__success;
      }
    }

    public getTask_result deepCopy() {
      return new getTask_result(this);
    }

    @Override
    public void clear() {
      this.success = null;
    }

    public int getSuccessSize() {
      return (this.success == null) ? 0 : this.success.size();
    }

    public java.util.Iterator<ch.epfl.eagle.thrift.TTaskLaunchSpec> getSuccessIterator() {
      return (this.success == null) ? null : this.success.iterator();
    }

    public void addToSuccess(ch.epfl.eagle.thrift.TTaskLaunchSpec elem) {
      if (this.success == null) {
        this.success = new ArrayList<ch.epfl.eagle.thrift.TTaskLaunchSpec>();
      }
      this.success.add(elem);
    }

    public List<ch.epfl.eagle.thrift.TTaskLaunchSpec> getSuccess() {
      return this.success;
    }

    public getTask_result setSuccess(List<ch.epfl.eagle.thrift.TTaskLaunchSpec> success) {
      this.success = success;
      return this;
    }

    public void unsetSuccess() {
      this.success = null;
    }

    /** Returns true if field success is set (has been assigned a value) and false otherwise */
    public boolean isSetSuccess() {
      return this.success != null;
    }

    public void setSuccessIsSet(boolean value) {
      if (!value) {
        this.success = null;
      }
    }

    public void setFieldValue(_Fields field, Object value) {
      switch (field) {
      case SUCCESS:
        if (value == null) {
          unsetSuccess();
        } else {
          setSuccess((List<ch.epfl.eagle.thrift.TTaskLaunchSpec>)value);
        }
        break;

      }
    }

    public Object getFieldValue(_Fields field) {
      switch (field) {
      case SUCCESS:
        return getSuccess();

      }
      throw new IllegalStateException();
    }

    /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */
    public boolean isSet(_Fields field) {
      if (field == null) {
        throw new IllegalArgumentException();
      }

      switch (field) {
      case SUCCESS:
        return isSetSuccess();
      }
      throw new IllegalStateException();
    }

    @Override
    public boolean equals(Object that) {
      if (that == null)
        return false;
      if (that instanceof getTask_result)
        return this.equals((getTask_result)that);
      return false;
    }

    public boolean equals(getTask_result that) {
      if (that == null)
        return false;

      boolean this_present_success = true && this.isSetSuccess();
      boolean that_present_success = true && that.isSetSuccess();
      if (this_present_success || that_present_success) {
        if (!(this_present_success && that_present_success))
          return false;
        if (!this.success.equals(that.success))
          return false;
      }

      return true;
    }

    @Override
    public int hashCode() {
      List<Object> list = new ArrayList<Object>();

      boolean present_success = true && (isSetSuccess());
      list.add(present_success);
      if (present_success)
        list.add(success);

      return list.hashCode();
    }

    @Override
    public int compareTo(getTask_result other) {
      if (!getClass().equals(other.getClass())) {
        return getClass().getName().compareTo(other.getClass().getName());
      }

      int lastComparison = 0;

      lastComparison = Boolean.valueOf(isSetSuccess()).compareTo(other.isSetSuccess());
      if (lastComparison != 0) {
        return lastComparison;
      }
      if (isSetSuccess()) {
        lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.success, other.success);
        if (lastComparison != 0) {
          return lastComparison;
        }
      }
      return 0;
    }

    public _Fields fieldForId(int fieldId) {
      return _Fields.findByThriftId(fieldId);
    }

    public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException {
      schemes.get(iprot.getScheme()).getScheme().read(iprot, this);
    }

    public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException {
      schemes.get(oprot.getScheme()).getScheme().write(oprot, this);
      }

    @Override
    public String toString() {
      StringBuilder sb = new StringBuilder("getTask_result(");
      boolean first = true;

      sb.append("success:");
      if (this.success == null) {
        sb.append("null");
      } else {
        sb.append(this.success);
      }
      first = false;
      sb.append(")");
      return sb.toString();
    }

    public void validate() throws org.apache.thrift.TException {
      // check for required fields
      // check for sub-struct validity
    }

    private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException {
      try {
        write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out)));
      } catch (org.apache.thrift.TException te) {
        throw new java.io.IOException(te);
      }
    }

    private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException {
      try {
        read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in)));
      } catch (org.apache.thrift.TException te) {
        throw new java.io.IOException(te);
      }
    }

    private static class getTask_resultStandardSchemeFactory implements SchemeFactory {
      public getTask_resultStandardScheme getScheme() {
        return new getTask_resultStandardScheme();
      }
    }

    private static class getTask_resultStandardScheme extends StandardScheme<getTask_result> {

      public void read(org.apache.thrift.protocol.TProtocol iprot, getTask_result struct) throws org.apache.thrift.TException {
        org.apache.thrift.protocol.TField schemeField;
        iprot.readStructBegin();
        while (true)
        {
          schemeField = iprot.readFieldBegin();
          if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { 
            break;
          }
          switch (schemeField.id) {
            case 0: // SUCCESS
              if (schemeField.type == org.apache.thrift.protocol.TType.LIST) {
                {
                  org.apache.thrift.protocol.TList _list0 = iprot.readListBegin();
                  struct.success = new ArrayList<ch.epfl.eagle.thrift.TTaskLaunchSpec>(_list0.size);
                  ch.epfl.eagle.thrift.TTaskLaunchSpec _elem1;
                  for (int _i2 = 0; _i2 < _list0.size; ++_i2)
                  {
                    _elem1 = new ch.epfl.eagle.thrift.TTaskLaunchSpec();
                    _elem1.read(iprot);
                    struct.success.add(_elem1);
                  }
                  iprot.readListEnd();
                }
                struct.setSuccessIsSet(true);
              } else { 
                org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
              }
              break;
            default:
              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
          }
          iprot.readFieldEnd();
        }
        iprot.readStructEnd();

        // check for required fields of primitive type, which can't be checked in the validate method
        struct.validate();
      }

      public void write(org.apache.thrift.protocol.TProtocol oprot, getTask_result struct) throws org.apache.thrift.TException {
        struct.validate();

        oprot.writeStructBegin(STRUCT_DESC);
        if (struct.success != null) {
          oprot.writeFieldBegin(SUCCESS_FIELD_DESC);
          {
            oprot.writeListBegin(new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.STRUCT, struct.success.size()));
            for (ch.epfl.eagle.thrift.TTaskLaunchSpec _iter3 : struct.success)
            {
              _iter3.write(oprot);
            }
            oprot.writeListEnd();
          }
          oprot.writeFieldEnd();
        }
        oprot.writeFieldStop();
        oprot.writeStructEnd();
      }

    }

    private static class getTask_resultTupleSchemeFactory implements SchemeFactory {
      public getTask_resultTupleScheme getScheme() {
        return new getTask_resultTupleScheme();
      }
    }

    private static class getTask_resultTupleScheme extends TupleScheme<getTask_result> {

      @Override
      public void write(org.apache.thrift.protocol.TProtocol prot, getTask_result struct) throws org.apache.thrift.TException {
        TTupleProtocol oprot = (TTupleProtocol) prot;
        BitSet optionals = new BitSet();
        if (struct.isSetSuccess()) {
          optionals.set(0);
        }
        oprot.writeBitSet(optionals, 1);
        if (struct.isSetSuccess()) {
          {
            oprot.writeI32(struct.success.size());
            for (ch.epfl.eagle.thrift.TTaskLaunchSpec _iter4 : struct.success)
            {
              _iter4.write(oprot);
            }
          }
        }
      }

      @Override
      public void read(org.apache.thrift.protocol.TProtocol prot, getTask_result struct) throws org.apache.thrift.TException {
        TTupleProtocol iprot = (TTupleProtocol) prot;
        BitSet incoming = iprot.readBitSet(1);
        if (incoming.get(0)) {
          {
            org.apache.thrift.protocol.TList _list5 = new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.STRUCT, iprot.readI32());
            struct.success = new ArrayList<ch.epfl.eagle.thrift.TTaskLaunchSpec>(_list5.size);
            ch.epfl.eagle.thrift.TTaskLaunchSpec _elem6;
            for (int _i7 = 0; _i7 < _list5.size; ++_i7)
            {
              _elem6 = new ch.epfl.eagle.thrift.TTaskLaunchSpec();
              _elem6.read(iprot);
              struct.success.add(_elem6);
            }
          }
          struct.setSuccessIsSet(true);
        }
      }
    }

  }

} @SuppressWarnings({"cast", "rawtypes", "serial", "unchecked"})
@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2016-03-03")
public class TFullTaskId implements org.apache.thrift.TBase<TFullTaskId, TFullTaskId._Fields>, java.io.Serializable, Cloneable, Comparable<TFullTaskId> {
  private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("TFullTaskId");

  private static final org.apache.thrift.protocol.TField TASK_ID_FIELD_DESC = new org.apache.thrift.protocol.TField("taskId", org.apache.thrift.protocol.TType.STRING, (short)1);
  private static final org.apache.thrift.protocol.TField REQUEST_ID_FIELD_DESC = new org.apache.thrift.protocol.TField("requestId", org.apache.thrift.protocol.TType.STRING, (short)2);
  private static final org.apache.thrift.protocol.TField APP_ID_FIELD_DESC = new org.apache.thrift.protocol.TField("appId", org.apache.thrift.protocol.TType.STRING, (short)3);
  private static final org.apache.thrift.protocol.TField SCHEDULER_ADDRESS_FIELD_DESC = new org.apache.thrift.protocol.TField("schedulerAddress", org.apache.thrift.protocol.TType.STRUCT, (short)4);

  private static final Map<Class<? extends IScheme>, SchemeFactory> schemes = new HashMap<Class<? extends IScheme>, SchemeFactory>();
  static {
    schemes.put(StandardScheme.class, new TFullTaskIdStandardSchemeFactory());
    schemes.put(TupleScheme.class, new TFullTaskIdTupleSchemeFactory());
  }

  public String taskId; // required
  public String requestId; // required
  public String appId; // required
  public THostPort schedulerAddress; // required

  /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */
  public enum _Fields implements org.apache.thrift.TFieldIdEnum {
    TASK_ID((short)1, "taskId"),
    REQUEST_ID((short)2, "requestId"),
    APP_ID((short)3, "appId"),
    SCHEDULER_ADDRESS((short)4, "schedulerAddress");

    private static final Map<String, _Fields> byName = new HashMap<String, _Fields>();

    static {
      for (_Fields field : EnumSet.allOf(_Fields.class)) {
        byName.put(field.getFieldName(), field);
      }
    }

    /**
     * Find the _Fields constant that matches fieldId, or null if its not found.
     */
    public static _Fields findByThriftId(int fieldId) {
      switch(fieldId) {
        case 1: // TASK_ID
          return TASK_ID;
        case 2: // REQUEST_ID
          return REQUEST_ID;
        case 3: // APP_ID
          return APP_ID;
        case 4: // SCHEDULER_ADDRESS
          return SCHEDULER_ADDRESS;
        default:
          return null;
      }
    }

    /**
     * Find the _Fields constant that matches fieldId, throwing an exception
     * if it is not found.
     */
    public static _Fields findByThriftIdOrThrow(int fieldId) {
      _Fields fields = findByThriftId(fieldId);
      if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!");
      return fields;
    }

    /**
     * Find the _Fields constant that matches name, or null if its not found.
     */
    public static _Fields findByName(String name) {
      return byName.get(name);
    }

    private final short _thriftId;
    private final String _fieldName;

    _Fields(short thriftId, String fieldName) {
      _thriftId = thriftId;
      _fieldName = fieldName;
    }

    public short getThriftFieldId() {
      return _thriftId;
    }

    public String getFieldName() {
      return _fieldName;
    }
  }

  // isset id assignments
  public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap;
  static {
    Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class);
    tmpMap.put(_Fields.TASK_ID, new org.apache.thrift.meta_data.FieldMetaData("taskId", org.apache.thrift.TFieldRequirementType.DEFAULT, 
        new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING)));
    tmpMap.put(_Fields.REQUEST_ID, new org.apache.thrift.meta_data.FieldMetaData("requestId", org.apache.thrift.TFieldRequirementType.DEFAULT, 
        new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING)));
    tmpMap.put(_Fields.APP_ID, new org.apache.thrift.meta_data.FieldMetaData("appId", org.apache.thrift.TFieldRequirementType.DEFAULT, 
        new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING)));
    tmpMap.put(_Fields.SCHEDULER_ADDRESS, new org.apache.thrift.meta_data.FieldMetaData("schedulerAddress", org.apache.thrift.TFieldRequirementType.DEFAULT, 
        new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, THostPort.class)));
    metaDataMap = Collections.unmodifiableMap(tmpMap);
    org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(TFullTaskId.class, metaDataMap);
  }

  public TFullTaskId() {
  }

  public TFullTaskId(
    String taskId,
    String requestId,
    String appId,
    THostPort schedulerAddress)
  {
    this();
    this.taskId = taskId;
    this.requestId = requestId;
    this.appId = appId;
    this.schedulerAddress = schedulerAddress;
  }

  /**
   * Performs a deep copy on <i>other</i>.
   */
  public TFullTaskId(TFullTaskId other) {
    if (other.isSetTaskId()) {
      this.taskId = other.taskId;
    }
    if (other.isSetRequestId()) {
      this.requestId = other.requestId;
    }
    if (other.isSetAppId()) {
      this.appId = other.appId;
    }
    if (other.isSetSchedulerAddress()) {
      this.schedulerAddress = new THostPort(other.schedulerAddress);
    }
  }

  public TFullTaskId deepCopy() {
    return new TFullTaskId(this);
  }

  @Override
  public void clear() {
    this.taskId = null;
    this.requestId = null;
    this.appId = null;
    this.schedulerAddress = null;
  }

  public String getTaskId() {
    return this.taskId;
  }

  public TFullTaskId setTaskId(String taskId) {
    this.taskId = taskId;
    return this;
  }

  public void unsetTaskId() {
    this.taskId = null;
  }

  /** Returns true if field taskId is set (has been assigned a value) and false otherwise */
  public boolean isSetTaskId() {
    return this.taskId != null;
  }

  public void setTaskIdIsSet(boolean value) {
    if (!value) {
      this.taskId = null;
    }
  }

  public String getRequestId() {
    return this.requestId;
  }

  public TFullTaskId setRequestId(String requestId) {
    this.requestId = requestId;
    return this;
  }

  public void unsetRequestId() {
    this.requestId = null;
  }

  /** Returns true if field requestId is set (has been assigned a value) and false otherwise */
  public boolean isSetRequestId() {
    return this.requestId != null;
  }

  public void setRequestIdIsSet(boolean value) {
    if (!value) {
      this.requestId = null;
    }
  }

  public String getAppId() {
    return this.appId;
  }

  public TFullTaskId setAppId(String appId) {
    this.appId = appId;
    return this;
  }

  public void unsetAppId() {
    this.appId = null;
  }

  /** Returns true if field appId is set (has been assigned a value) and false otherwise */
  public boolean isSetAppId() {
    return this.appId != null;
  }

  public void setAppIdIsSet(boolean value) {
    if (!value) {
      this.appId = null;
    }
  }

  public THostPort getSchedulerAddress() {
    return this.schedulerAddress;
  }

  public TFullTaskId setSchedulerAddress(THostPort schedulerAddress) {
    this.schedulerAddress = schedulerAddress;
    return this;
  }

  public void unsetSchedulerAddress() {
    this.schedulerAddress = null;
  }

  /** Returns true if field schedulerAddress is set (has been assigned a value) and false otherwise */
  public boolean isSetSchedulerAddress() {
    return this.schedulerAddress != null;
  }

  public void setSchedulerAddressIsSet(boolean value) {
    if (!value) {
      this.schedulerAddress = null;
    }
  }

  public void setFieldValue(_Fields field, Object value) {
    switch (field) {
    case TASK_ID:
      if (value == null) {
        unsetTaskId();
      } else {
        setTaskId((String)value);
      }
      break;

    case REQUEST_ID:
      if (value == null) {
        unsetRequestId();
      } else {
        setRequestId((String)value);
      }
      break;

    case APP_ID:
      if (value == null) {
        unsetAppId();
      } else {
        setAppId((String)value);
      }
      break;

    case SCHEDULER_ADDRESS:
      if (value == null) {
        unsetSchedulerAddress();
      } else {
        setSchedulerAddress((THostPort)value);
      }
      break;

    }
  }

  public Object getFieldValue(_Fields field) {
    switch (field) {
    case TASK_ID:
      return getTaskId();

    case REQUEST_ID:
      return getRequestId();

    case APP_ID:
      return getAppId();

    case SCHEDULER_ADDRESS:
      return getSchedulerAddress();

    }
    throw new IllegalStateException();
  }

  /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */
  public boolean isSet(_Fields field) {
    if (field == null) {
      throw new IllegalArgumentException();
    }

    switch (field) {
    case TASK_ID:
      return isSetTaskId();
    case REQUEST_ID:
      return isSetRequestId();
    case APP_ID:
      return isSetAppId();
    case SCHEDULER_ADDRESS:
      return isSetSchedulerAddress();
    }
    throw new IllegalStateException();
  }

  @Override
  public boolean equals(Object that) {
    if (that == null)
      return false;
    if (that instanceof TFullTaskId)
      return this.equals((TFullTaskId)that);
    return false;
  }

  public boolean equals(TFullTaskId that) {
    if (that == null)
      return false;

    boolean this_present_taskId = true && this.isSetTaskId();
    boolean that_present_taskId = true && that.isSetTaskId();
    if (this_present_taskId || that_present_taskId) {
      if (!(this_present_taskId && that_present_taskId))
        return false;
      if (!this.taskId.equals(that.taskId))
        return false;
    }

    boolean this_present_requestId = true && this.isSetRequestId();
    boolean that_present_requestId = true && that.isSetRequestId();
    if (this_present_requestId || that_present_requestId) {
      if (!(this_present_requestId && that_present_requestId))
        return false;
      if (!this.requestId.equals(that.requestId))
        return false;
    }

    boolean this_present_appId = true && this.isSetAppId();
    boolean that_present_appId = true && that.isSetAppId();
    if (this_present_appId || that_present_appId) {
      if (!(this_present_appId && that_present_appId))
        return false;
      if (!this.appId.equals(that.appId))
        return false;
    }

    boolean this_present_schedulerAddress = true && this.isSetSchedulerAddress();
    boolean that_present_schedulerAddress = true && that.isSetSchedulerAddress();
    if (this_present_schedulerAddress || that_present_schedulerAddress) {
      if (!(this_present_schedulerAddress && that_present_schedulerAddress))
        return false;
      if (!this.schedulerAddress.equals(that.schedulerAddress))
        return false;
    }

    return true;
  }

  @Override
  public int hashCode() {
    List<Object> list = new ArrayList<Object>();

    boolean present_taskId = true && (isSetTaskId());
    list.add(present_taskId);
    if (present_taskId)
      list.add(taskId);

    boolean present_requestId = true && (isSetRequestId());
    list.add(present_requestId);
    if (present_requestId)
      list.add(requestId);

    boolean present_appId = true && (isSetAppId());
    list.add(present_appId);
    if (present_appId)
      list.add(appId);

    boolean present_schedulerAddress = true && (isSetSchedulerAddress());
    list.add(present_schedulerAddress);
    if (present_schedulerAddress)
      list.add(schedulerAddress);

    return list.hashCode();
  }

  @Override
  public int compareTo(TFullTaskId other) {
    if (!getClass().equals(other.getClass())) {
      return getClass().getName().compareTo(other.getClass().getName());
    }

    int lastComparison = 0;

    lastComparison = Boolean.valueOf(isSetTaskId()).compareTo(other.isSetTaskId());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetTaskId()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.taskId, other.taskId);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    lastComparison = Boolean.valueOf(isSetRequestId()).compareTo(other.isSetRequestId());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetRequestId()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.requestId, other.requestId);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    lastComparison = Boolean.valueOf(isSetAppId()).compareTo(other.isSetAppId());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetAppId()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.appId, other.appId);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    lastComparison = Boolean.valueOf(isSetSchedulerAddress()).compareTo(other.isSetSchedulerAddress());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetSchedulerAddress()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.schedulerAddress, other.schedulerAddress);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    return 0;
  }

  public _Fields fieldForId(int fieldId) {
    return _Fields.findByThriftId(fieldId);
  }

  public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException {
    schemes.get(iprot.getScheme()).getScheme().read(iprot, this);
  }

  public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException {
    schemes.get(oprot.getScheme()).getScheme().write(oprot, this);
  }

  @Override
  public String toString() {
    StringBuilder sb = new StringBuilder("TFullTaskId(");
    boolean first = true;

    sb.append("taskId:");
    if (this.taskId == null) {
      sb.append("null");
    } else {
      sb.append(this.taskId);
    }
    first = false;
    if (!first) sb.append(", ");
    sb.append("requestId:");
    if (this.requestId == null) {
      sb.append("null");
    } else {
      sb.append(this.requestId);
    }
    first = false;
    if (!first) sb.append(", ");
    sb.append("appId:");
    if (this.appId == null) {
      sb.append("null");
    } else {
      sb.append(this.appId);
    }
    first = false;
    if (!first) sb.append(", ");
    sb.append("schedulerAddress:");
    if (this.schedulerAddress == null) {
      sb.append("null");
    } else {
      sb.append(this.schedulerAddress);
    }
    first = false;
    sb.append(")");
    return sb.toString();
  }

  public void validate() throws org.apache.thrift.TException {
    // check for required fields
    // check for sub-struct validity
    if (schedulerAddress != null) {
      schedulerAddress.validate();
    }
  }

  private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException {
    try {
      write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out)));
    } catch (org.apache.thrift.TException te) {
      throw new java.io.IOException(te);
    }
  }

  private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException {
    try {
      read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in)));
    } catch (org.apache.thrift.TException te) {
      throw new java.io.IOException(te);
    }
  }

  private static class TFullTaskIdStandardSchemeFactory implements SchemeFactory {
    public TFullTaskIdStandardScheme getScheme() {
      return new TFullTaskIdStandardScheme();
    }
  }

  private static class TFullTaskIdStandardScheme extends StandardScheme<TFullTaskId> {

    public void read(org.apache.thrift.protocol.TProtocol iprot, TFullTaskId struct) throws org.apache.thrift.TException {
      org.apache.thrift.protocol.TField schemeField;
      iprot.readStructBegin();
      while (true)
      {
        schemeField = iprot.readFieldBegin();
        if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { 
          break;
        }
        switch (schemeField.id) {
          case 1: // TASK_ID
            if (schemeField.type == org.apache.thrift.protocol.TType.STRING) {
              struct.taskId = iprot.readString();
              struct.setTaskIdIsSet(true);
            } else { 
              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
            }
            break;
          case 2: // REQUEST_ID
            if (schemeField.type == org.apache.thrift.protocol.TType.STRING) {
              struct.requestId = iprot.readString();
              struct.setRequestIdIsSet(true);
            } else { 
              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
            }
            break;
          case 3: // APP_ID
            if (schemeField.type == org.apache.thrift.protocol.TType.STRING) {
              struct.appId = iprot.readString();
              struct.setAppIdIsSet(true);
            } else { 
              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
            }
            break;
          case 4: // SCHEDULER_ADDRESS
            if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) {
              struct.schedulerAddress = new THostPort();
              struct.schedulerAddress.read(iprot);
              struct.setSchedulerAddressIsSet(true);
            } else { 
              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
            }
            break;
          default:
            org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
        }
        iprot.readFieldEnd();
      }
      iprot.readStructEnd();

      // check for required fields of primitive type, which can't be checked in the validate method
      struct.validate();
    }

    public void write(org.apache.thrift.protocol.TProtocol oprot, TFullTaskId struct) throws org.apache.thrift.TException {
      struct.validate();

      oprot.writeStructBegin(STRUCT_DESC);
      if (struct.taskId != null) {
        oprot.writeFieldBegin(TASK_ID_FIELD_DESC);
        oprot.writeString(struct.taskId);
        oprot.writeFieldEnd();
      }
      if (struct.requestId != null) {
        oprot.writeFieldBegin(REQUEST_ID_FIELD_DESC);
        oprot.writeString(struct.requestId);
        oprot.writeFieldEnd();
      }
      if (struct.appId != null) {
        oprot.writeFieldBegin(APP_ID_FIELD_DESC);
        oprot.writeString(struct.appId);
        oprot.writeFieldEnd();
      }
      if (struct.schedulerAddress != null) {
        oprot.writeFieldBegin(SCHEDULER_ADDRESS_FIELD_DESC);
        struct.schedulerAddress.write(oprot);
        oprot.writeFieldEnd();
      }
      oprot.writeFieldStop();
      oprot.writeStructEnd();
    }

  }

  private static class TFullTaskIdTupleSchemeFactory implements SchemeFactory {
    public TFullTaskIdTupleScheme getScheme() {
      return new TFullTaskIdTupleScheme();
    }
  }

  private static class TFullTaskIdTupleScheme extends TupleScheme<TFullTaskId> {

    @Override
    public void write(org.apache.thrift.protocol.TProtocol prot, TFullTaskId struct) throws org.apache.thrift.TException {
      TTupleProtocol oprot = (TTupleProtocol) prot;
      BitSet optionals = new BitSet();
      if (struct.isSetTaskId()) {
        optionals.set(0);
      }
      if (struct.isSetRequestId()) {
        optionals.set(1);
      }
      if (struct.isSetAppId()) {
        optionals.set(2);
      }
      if (struct.isSetSchedulerAddress()) {
        optionals.set(3);
      }
      oprot.writeBitSet(optionals, 4);
      if (struct.isSetTaskId()) {
        oprot.writeString(struct.taskId);
      }
      if (struct.isSetRequestId()) {
        oprot.writeString(struct.requestId);
      }
      if (struct.isSetAppId()) {
        oprot.writeString(struct.appId);
      }
      if (struct.isSetSchedulerAddress()) {
        struct.schedulerAddress.write(oprot);
      }
    }

    @Override
    public void read(org.apache.thrift.protocol.TProtocol prot, TFullTaskId struct) throws org.apache.thrift.TException {
      TTupleProtocol iprot = (TTupleProtocol) prot;
      BitSet incoming = iprot.readBitSet(4);
      if (incoming.get(0)) {
        struct.taskId = iprot.readString();
        struct.setTaskIdIsSet(true);
      }
      if (incoming.get(1)) {
        struct.requestId = iprot.readString();
        struct.setRequestIdIsSet(true);
      }
      if (incoming.get(2)) {
        struct.appId = iprot.readString();
        struct.setAppIdIsSet(true);
      }
      if (incoming.get(3)) {
        struct.schedulerAddress = new THostPort();
        struct.schedulerAddress.read(iprot);
        struct.setSchedulerAddressIsSet(true);
      }
    }
  }

} @SuppressWarnings({"cast", "rawtypes", "serial", "unchecked"})
@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2016-03-03")
public class THostPort implements org.apache.thrift.TBase<THostPort, THostPort._Fields>, java.io.Serializable, Cloneable, Comparable<THostPort> {
  private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("THostPort");

  private static final org.apache.thrift.protocol.TField HOST_FIELD_DESC = new org.apache.thrift.protocol.TField("host", org.apache.thrift.protocol.TType.STRING, (short)1);
  private static final org.apache.thrift.protocol.TField PORT_FIELD_DESC = new org.apache.thrift.protocol.TField("port", org.apache.thrift.protocol.TType.I32, (short)2);

  private static final Map<Class<? extends IScheme>, SchemeFactory> schemes = new HashMap<Class<? extends IScheme>, SchemeFactory>();
  static {
    schemes.put(StandardScheme.class, new THostPortStandardSchemeFactory());
    schemes.put(TupleScheme.class, new THostPortTupleSchemeFactory());
  }

  public String host; // required
  public int port; // required

  /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */
  public enum _Fields implements org.apache.thrift.TFieldIdEnum {
    HOST((short)1, "host"),
    PORT((short)2, "port");

    private static final Map<String, _Fields> byName = new HashMap<String, _Fields>();

    static {
      for (_Fields field : EnumSet.allOf(_Fields.class)) {
        byName.put(field.getFieldName(), field);
      }
    }

    /**
     * Find the _Fields constant that matches fieldId, or null if its not found.
     */
    public static _Fields findByThriftId(int fieldId) {
      switch(fieldId) {
        case 1: // HOST
          return HOST;
        case 2: // PORT
          return PORT;
        default:
          return null;
      }
    }

    /**
     * Find the _Fields constant that matches fieldId, throwing an exception
     * if it is not found.
     */
    public static _Fields findByThriftIdOrThrow(int fieldId) {
      _Fields fields = findByThriftId(fieldId);
      if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!");
      return fields;
    }

    /**
     * Find the _Fields constant that matches name, or null if its not found.
     */
    public static _Fields findByName(String name) {
      return byName.get(name);
    }

    private final short _thriftId;
    private final String _fieldName;

    _Fields(short thriftId, String fieldName) {
      _thriftId = thriftId;
      _fieldName = fieldName;
    }

    public short getThriftFieldId() {
      return _thriftId;
    }

    public String getFieldName() {
      return _fieldName;
    }
  }

  // isset id assignments
  private static final int __PORT_ISSET_ID = 0;
  private byte __isset_bitfield = 0;
  public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap;
  static {
    Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class);
    tmpMap.put(_Fields.HOST, new org.apache.thrift.meta_data.FieldMetaData("host", org.apache.thrift.TFieldRequirementType.DEFAULT, 
        new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING)));
    tmpMap.put(_Fields.PORT, new org.apache.thrift.meta_data.FieldMetaData("port", org.apache.thrift.TFieldRequirementType.DEFAULT, 
        new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I32)));
    metaDataMap = Collections.unmodifiableMap(tmpMap);
    org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(THostPort.class, metaDataMap);
  }

  public THostPort() {
  }

  public THostPort(
    String host,
    int port)
  {
    this();
    this.host = host;
    this.port = port;
    setPortIsSet(true);
  }

  /**
   * Performs a deep copy on <i>other</i>.
   */
  public THostPort(THostPort other) {
    __isset_bitfield = other.__isset_bitfield;
    if (other.isSetHost()) {
      this.host = other.host;
    }
    this.port = other.port;
  }

  public THostPort deepCopy() {
    return new THostPort(this);
  }

  @Override
  public void clear() {
    this.host = null;
    setPortIsSet(false);
    this.port = 0;
  }

  public String getHost() {
    return this.host;
  }

  public THostPort setHost(String host) {
    this.host = host;
    return this;
  }

  public void unsetHost() {
    this.host = null;
  }

  /** Returns true if field host is set (has been assigned a value) and false otherwise */
  public boolean isSetHost() {
    return this.host != null;
  }

  public void setHostIsSet(boolean value) {
    if (!value) {
      this.host = null;
    }
  }

  public int getPort() {
    return this.port;
  }

  public THostPort setPort(int port) {
    this.port = port;
    setPortIsSet(true);
    return this;
  }

  public void unsetPort() {
    __isset_bitfield = EncodingUtils.clearBit(__isset_bitfield, __PORT_ISSET_ID);
  }

  /** Returns true if field port is set (has been assigned a value) and false otherwise */
  public boolean isSetPort() {
    return EncodingUtils.testBit(__isset_bitfield, __PORT_ISSET_ID);
  }

  public void setPortIsSet(boolean value) {
    __isset_bitfield = EncodingUtils.setBit(__isset_bitfield, __PORT_ISSET_ID, value);
  }

  public void setFieldValue(_Fields field, Object value) {
    switch (field) {
    case HOST:
      if (value == null) {
        unsetHost();
      } else {
        setHost((String)value);
      }
      break;

    case PORT:
      if (value == null) {
        unsetPort();
      } else {
        setPort((Integer)value);
      }
      break;

    }
  }

  public Object getFieldValue(_Fields field) {
    switch (field) {
    case HOST:
      return getHost();

    case PORT:
      return getPort();

    }
    throw new IllegalStateException();
  }

  /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */
  public boolean isSet(_Fields field) {
    if (field == null) {
      throw new IllegalArgumentException();
    }

    switch (field) {
    case HOST:
      return isSetHost();
    case PORT:
      return isSetPort();
    }
    throw new IllegalStateException();
  }

  @Override
  public boolean equals(Object that) {
    if (that == null)
      return false;
    if (that instanceof THostPort)
      return this.equals((THostPort)that);
    return false;
  }

  public boolean equals(THostPort that) {
    if (that == null)
      return false;

    boolean this_present_host = true && this.isSetHost();
    boolean that_present_host = true && that.isSetHost();
    if (this_present_host || that_present_host) {
      if (!(this_present_host && that_present_host))
        return false;
      if (!this.host.equals(that.host))
        return false;
    }

    boolean this_present_port = true;
    boolean that_present_port = true;
    if (this_present_port || that_present_port) {
      if (!(this_present_port && that_present_port))
        return false;
      if (this.port != that.port)
        return false;
    }

    return true;
  }

  @Override
  public int hashCode() {
    List<Object> list = new ArrayList<Object>();

    boolean present_host = true && (isSetHost());
    list.add(present_host);
    if (present_host)
      list.add(host);

    boolean present_port = true;
    list.add(present_port);
    if (present_port)
      list.add(port);

    return list.hashCode();
  }

  @Override
  public int compareTo(THostPort other) {
    if (!getClass().equals(other.getClass())) {
      return getClass().getName().compareTo(other.getClass().getName());
    }

    int lastComparison = 0;

    lastComparison = Boolean.valueOf(isSetHost()).compareTo(other.isSetHost());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetHost()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.host, other.host);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    lastComparison = Boolean.valueOf(isSetPort()).compareTo(other.isSetPort());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetPort()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.port, other.port);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    return 0;
  }

  public _Fields fieldForId(int fieldId) {
    return _Fields.findByThriftId(fieldId);
  }

  public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException {
    schemes.get(iprot.getScheme()).getScheme().read(iprot, this);
  }

  public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException {
    schemes.get(oprot.getScheme()).getScheme().write(oprot, this);
  }

  @Override
  public String toString() {
    StringBuilder sb = new StringBuilder("THostPort(");
    boolean first = true;

    sb.append("host:");
    if (this.host == null) {
      sb.append("null");
    } else {
      sb.append(this.host);
    }
    first = false;
    if (!first) sb.append(", ");
    sb.append("port:");
    sb.append(this.port);
    first = false;
    sb.append(")");
    return sb.toString();
  }

  public void validate() throws org.apache.thrift.TException {
    // check for required fields
    // check for sub-struct validity
  }

  private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException {
    try {
      write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out)));
    } catch (org.apache.thrift.TException te) {
      throw new java.io.IOException(te);
    }
  }

  private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException {
    try {
      // it doesn't seem like you should have to do this, but java serialization is wacky, and doesn't call the default constructor.
      __isset_bitfield = 0;
      read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in)));
    } catch (org.apache.thrift.TException te) {
      throw new java.io.IOException(te);
    }
  }

  private static class THostPortStandardSchemeFactory implements SchemeFactory {
    public THostPortStandardScheme getScheme() {
      return new THostPortStandardScheme();
    }
  }

  private static class THostPortStandardScheme extends StandardScheme<THostPort> {

    public void read(org.apache.thrift.protocol.TProtocol iprot, THostPort struct) throws org.apache.thrift.TException {
      org.apache.thrift.protocol.TField schemeField;
      iprot.readStructBegin();
      while (true)
      {
        schemeField = iprot.readFieldBegin();
        if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { 
          break;
        }
        switch (schemeField.id) {
          case 1: // HOST
            if (schemeField.type == org.apache.thrift.protocol.TType.STRING) {
              struct.host = iprot.readString();
              struct.setHostIsSet(true);
            } else { 
              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
            }
            break;
          case 2: // PORT
            if (schemeField.type == org.apache.thrift.protocol.TType.I32) {
              struct.port = iprot.readI32();
              struct.setPortIsSet(true);
            } else { 
              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
            }
            break;
          default:
            org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
        }
        iprot.readFieldEnd();
      }
      iprot.readStructEnd();

      // check for required fields of primitive type, which can't be checked in the validate method
      struct.validate();
    }

    public void write(org.apache.thrift.protocol.TProtocol oprot, THostPort struct) throws org.apache.thrift.TException {
      struct.validate();

      oprot.writeStructBegin(STRUCT_DESC);
      if (struct.host != null) {
        oprot.writeFieldBegin(HOST_FIELD_DESC);
        oprot.writeString(struct.host);
        oprot.writeFieldEnd();
      }
      oprot.writeFieldBegin(PORT_FIELD_DESC);
      oprot.writeI32(struct.port);
      oprot.writeFieldEnd();
      oprot.writeFieldStop();
      oprot.writeStructEnd();
    }

  }

  private static class THostPortTupleSchemeFactory implements SchemeFactory {
    public THostPortTupleScheme getScheme() {
      return new THostPortTupleScheme();
    }
  }

  private static class THostPortTupleScheme extends TupleScheme<THostPort> {

    @Override
    public void write(org.apache.thrift.protocol.TProtocol prot, THostPort struct) throws org.apache.thrift.TException {
      TTupleProtocol oprot = (TTupleProtocol) prot;
      BitSet optionals = new BitSet();
      if (struct.isSetHost()) {
        optionals.set(0);
      }
      if (struct.isSetPort()) {
        optionals.set(1);
      }
      oprot.writeBitSet(optionals, 2);
      if (struct.isSetHost()) {
        oprot.writeString(struct.host);
      }
      if (struct.isSetPort()) {
        oprot.writeI32(struct.port);
      }
    }

    @Override
    public void read(org.apache.thrift.protocol.TProtocol prot, THostPort struct) throws org.apache.thrift.TException {
      TTupleProtocol iprot = (TTupleProtocol) prot;
      BitSet incoming = iprot.readBitSet(2);
      if (incoming.get(0)) {
        struct.host = iprot.readString();
        struct.setHostIsSet(true);
      }
      if (incoming.get(1)) {
        struct.port = iprot.readI32();
        struct.setPortIsSet(true);
      }
    }
  }

} @SuppressWarnings({"cast", "rawtypes", "serial", "unchecked"})
@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2016-03-03")
public class TTaskLaunchSpec implements org.apache.thrift.TBase<TTaskLaunchSpec, TTaskLaunchSpec._Fields>, java.io.Serializable, Cloneable, Comparable<TTaskLaunchSpec> {
  private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("TTaskLaunchSpec");

  private static final org.apache.thrift.protocol.TField TASK_ID_FIELD_DESC = new org.apache.thrift.protocol.TField("taskId", org.apache.thrift.protocol.TType.STRING, (short)1);
  private static final org.apache.thrift.protocol.TField MESSAGE_FIELD_DESC = new org.apache.thrift.protocol.TField("message", org.apache.thrift.protocol.TType.STRING, (short)2);

  private static final Map<Class<? extends IScheme>, SchemeFactory> schemes = new HashMap<Class<? extends IScheme>, SchemeFactory>();
  static {
    schemes.put(StandardScheme.class, new TTaskLaunchSpecStandardSchemeFactory());
    schemes.put(TupleScheme.class, new TTaskLaunchSpecTupleSchemeFactory());
  }

  public String taskId; // required
  public ByteBuffer message; // required

  /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */
  public enum _Fields implements org.apache.thrift.TFieldIdEnum {
    TASK_ID((short)1, "taskId"),
    MESSAGE((short)2, "message");

    private static final Map<String, _Fields> byName = new HashMap<String, _Fields>();

    static {
      for (_Fields field : EnumSet.allOf(_Fields.class)) {
        byName.put(field.getFieldName(), field);
      }
    }

    /**
     * Find the _Fields constant that matches fieldId, or null if its not found.
     */
    public static _Fields findByThriftId(int fieldId) {
      switch(fieldId) {
        case 1: // TASK_ID
          return TASK_ID;
        case 2: // MESSAGE
          return MESSAGE;
        default:
          return null;
      }
    }

    /**
     * Find the _Fields constant that matches fieldId, throwing an exception
     * if it is not found.
     */
    public static _Fields findByThriftIdOrThrow(int fieldId) {
      _Fields fields = findByThriftId(fieldId);
      if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!");
      return fields;
    }

    /**
     * Find the _Fields constant that matches name, or null if its not found.
     */
    public static _Fields findByName(String name) {
      return byName.get(name);
    }

    private final short _thriftId;
    private final String _fieldName;

    _Fields(short thriftId, String fieldName) {
      _thriftId = thriftId;
      _fieldName = fieldName;
    }

    public short getThriftFieldId() {
      return _thriftId;
    }

    public String getFieldName() {
      return _fieldName;
    }
  }

  // isset id assignments
  public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap;
  static {
    Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class);
    tmpMap.put(_Fields.TASK_ID, new org.apache.thrift.meta_data.FieldMetaData("taskId", org.apache.thrift.TFieldRequirementType.DEFAULT, 
        new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING)));
    tmpMap.put(_Fields.MESSAGE, new org.apache.thrift.meta_data.FieldMetaData("message", org.apache.thrift.TFieldRequirementType.DEFAULT, 
        new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING        , true)));
    metaDataMap = Collections.unmodifiableMap(tmpMap);
    org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(TTaskLaunchSpec.class, metaDataMap);
  }

  public TTaskLaunchSpec() {
  }

  public TTaskLaunchSpec(
    String taskId,
    ByteBuffer message)
  {
    this();
    this.taskId = taskId;
    this.message = org.apache.thrift.TBaseHelper.copyBinary(message);
  }

  /**
   * Performs a deep copy on <i>other</i>.
   */
  public TTaskLaunchSpec(TTaskLaunchSpec other) {
    if (other.isSetTaskId()) {
      this.taskId = other.taskId;
    }
    if (other.isSetMessage()) {
      this.message = org.apache.thrift.TBaseHelper.copyBinary(other.message);
    }
  }

  public TTaskLaunchSpec deepCopy() {
    return new TTaskLaunchSpec(this);
  }

  @Override
  public void clear() {
    this.taskId = null;
    this.message = null;
  }

  public String getTaskId() {
    return this.taskId;
  }

  public TTaskLaunchSpec setTaskId(String taskId) {
    this.taskId = taskId;
    return this;
  }

  public void unsetTaskId() {
    this.taskId = null;
  }

  /** Returns true if field taskId is set (has been assigned a value) and false otherwise */
  public boolean isSetTaskId() {
    return this.taskId != null;
  }

  public void setTaskIdIsSet(boolean value) {
    if (!value) {
      this.taskId = null;
    }
  }

  public byte[] getMessage() {
    setMessage(org.apache.thrift.TBaseHelper.rightSize(message));
    return message == null ? null : message.array();
  }

  public ByteBuffer bufferForMessage() {
    return org.apache.thrift.TBaseHelper.copyBinary(message);
  }

  public TTaskLaunchSpec setMessage(byte[] message) {
    this.message = message == null ? (ByteBuffer)null : ByteBuffer.wrap(Arrays.copyOf(message, message.length));
    return this;
  }

  public TTaskLaunchSpec setMessage(ByteBuffer message) {
    this.message = org.apache.thrift.TBaseHelper.copyBinary(message);
    return this;
  }

  public void unsetMessage() {
    this.message = null;
  }

  /** Returns true if field message is set (has been assigned a value) and false otherwise */
  public boolean isSetMessage() {
    return this.message != null;
  }

  public void setMessageIsSet(boolean value) {
    if (!value) {
      this.message = null;
    }
  }

  public void setFieldValue(_Fields field, Object value) {
    switch (field) {
    case TASK_ID:
      if (value == null) {
        unsetTaskId();
      } else {
        setTaskId((String)value);
      }
      break;

    case MESSAGE:
      if (value == null) {
        unsetMessage();
      } else {
        setMessage((ByteBuffer)value);
      }
      break;

    }
  }

  public Object getFieldValue(_Fields field) {
    switch (field) {
    case TASK_ID:
      return getTaskId();

    case MESSAGE:
      return getMessage();

    }
    throw new IllegalStateException();
  }

  /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */
  public boolean isSet(_Fields field) {
    if (field == null) {
      throw new IllegalArgumentException();
    }

    switch (field) {
    case TASK_ID:
      return isSetTaskId();
    case MESSAGE:
      return isSetMessage();
    }
    throw new IllegalStateException();
  }

  @Override
  public boolean equals(Object that) {
    if (that == null)
      return false;
    if (that instanceof TTaskLaunchSpec)
      return this.equals((TTaskLaunchSpec)that);
    return false;
  }

  public boolean equals(TTaskLaunchSpec that) {
    if (that == null)
      return false;

    boolean this_present_taskId = true && this.isSetTaskId();
    boolean that_present_taskId = true && that.isSetTaskId();
    if (this_present_taskId || that_present_taskId) {
      if (!(this_present_taskId && that_present_taskId))
        return false;
      if (!this.taskId.equals(that.taskId))
        return false;
    }

    boolean this_present_message = true && this.isSetMessage();
    boolean that_present_message = true && that.isSetMessage();
    if (this_present_message || that_present_message) {
      if (!(this_present_message && that_present_message))
        return false;
      if (!this.message.equals(that.message))
        return false;
    }

    return true;
  }

  @Override
  public int hashCode() {
    List<Object> list = new ArrayList<Object>();

    boolean present_taskId = true && (isSetTaskId());
    list.add(present_taskId);
    if (present_taskId)
      list.add(taskId);

    boolean present_message = true && (isSetMessage());
    list.add(present_message);
    if (present_message)
      list.add(message);

    return list.hashCode();
  }

  @Override
  public int compareTo(TTaskLaunchSpec other) {
    if (!getClass().equals(other.getClass())) {
      return getClass().getName().compareTo(other.getClass().getName());
    }

    int lastComparison = 0;

    lastComparison = Boolean.valueOf(isSetTaskId()).compareTo(other.isSetTaskId());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetTaskId()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.taskId, other.taskId);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    lastComparison = Boolean.valueOf(isSetMessage()).compareTo(other.isSetMessage());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetMessage()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.message, other.message);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    return 0;
  }

  public _Fields fieldForId(int fieldId) {
    return _Fields.findByThriftId(fieldId);
  }

  public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException {
    schemes.get(iprot.getScheme()).getScheme().read(iprot, this);
  }

  public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException {
    schemes.get(oprot.getScheme()).getScheme().write(oprot, this);
  }

  @Override
  public String toString() {
    StringBuilder sb = new StringBuilder("TTaskLaunchSpec(");
    boolean first = true;

    sb.append("taskId:");
    if (this.taskId == null) {
      sb.append("null");
    } else {
      sb.append(this.taskId);
    }
    first = false;
    if (!first) sb.append(", ");
    sb.append("message:");
    if (this.message == null) {
      sb.append("null");
    } else {
      org.apache.thrift.TBaseHelper.toString(this.message, sb);
    }
    first = false;
    sb.append(")");
    return sb.toString();
  }

  public void validate() throws org.apache.thrift.TException {
    // check for required fields
    // check for sub-struct validity
  }

  private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException {
    try {
      write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out)));
    } catch (org.apache.thrift.TException te) {
      throw new java.io.IOException(te);
    }
  }

  private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException {
    try {
      read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in)));
    } catch (org.apache.thrift.TException te) {
      throw new java.io.IOException(te);
    }
  }

  private static class TTaskLaunchSpecStandardSchemeFactory implements SchemeFactory {
    public TTaskLaunchSpecStandardScheme getScheme() {
      return new TTaskLaunchSpecStandardScheme();
    }
  }

  private static class TTaskLaunchSpecStandardScheme extends StandardScheme<TTaskLaunchSpec> {

    public void read(org.apache.thrift.protocol.TProtocol iprot, TTaskLaunchSpec struct) throws org.apache.thrift.TException {
      org.apache.thrift.protocol.TField schemeField;
      iprot.readStructBegin();
      while (true)
      {
        schemeField = iprot.readFieldBegin();
        if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { 
          break;
        }
        switch (schemeField.id) {
          case 1: // TASK_ID
            if (schemeField.type == org.apache.thrift.protocol.TType.STRING) {
              struct.taskId = iprot.readString();
              struct.setTaskIdIsSet(true);
            } else { 
              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
            }
            break;
          case 2: // MESSAGE
            if (schemeField.type == org.apache.thrift.protocol.TType.STRING) {
              struct.message = iprot.readBinary();
              struct.setMessageIsSet(true);
            } else { 
              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
            }
            break;
          default:
            org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
        }
        iprot.readFieldEnd();
      }
      iprot.readStructEnd();

      // check for required fields of primitive type, which can't be checked in the validate method
      struct.validate();
    }

    public void write(org.apache.thrift.protocol.TProtocol oprot, TTaskLaunchSpec struct) throws org.apache.thrift.TException {
      struct.validate();

      oprot.writeStructBegin(STRUCT_DESC);
      if (struct.taskId != null) {
        oprot.writeFieldBegin(TASK_ID_FIELD_DESC);
        oprot.writeString(struct.taskId);
        oprot.writeFieldEnd();
      }
      if (struct.message != null) {
        oprot.writeFieldBegin(MESSAGE_FIELD_DESC);
        oprot.writeBinary(struct.message);
        oprot.writeFieldEnd();
      }
      oprot.writeFieldStop();
      oprot.writeStructEnd();
    }

  }

  private static class TTaskLaunchSpecTupleSchemeFactory implements SchemeFactory {
    public TTaskLaunchSpecTupleScheme getScheme() {
      return new TTaskLaunchSpecTupleScheme();
    }
  }

  private static class TTaskLaunchSpecTupleScheme extends TupleScheme<TTaskLaunchSpec> {

    @Override
    public void write(org.apache.thrift.protocol.TProtocol prot, TTaskLaunchSpec struct) throws org.apache.thrift.TException {
      TTupleProtocol oprot = (TTupleProtocol) prot;
      BitSet optionals = new BitSet();
      if (struct.isSetTaskId()) {
        optionals.set(0);
      }
      if (struct.isSetMessage()) {
        optionals.set(1);
      }
      oprot.writeBitSet(optionals, 2);
      if (struct.isSetTaskId()) {
        oprot.writeString(struct.taskId);
      }
      if (struct.isSetMessage()) {
        oprot.writeBinary(struct.message);
      }
    }

    @Override
    public void read(org.apache.thrift.protocol.TProtocol prot, TTaskLaunchSpec struct) throws org.apache.thrift.TException {
      TTupleProtocol iprot = (TTupleProtocol) prot;
      BitSet incoming = iprot.readBitSet(2);
      if (incoming.get(0)) {
        struct.taskId = iprot.readString();
        struct.setTaskIdIsSet(true);
      }
      if (incoming.get(1)) {
        struct.message = iprot.readBinary();
        struct.setMessageIsSet(true);
      }
    }
  }

}
import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.apache.commons.configuration.Configuration;
import org.apache.log4j.Logger;
import org.apache.thrift.TException;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import ch.epfl.eagle.daemon.nodemonitor.TaskScheduler.TaskSpec;
import ch.epfl.eagle.daemon.scheduler.SchedulerThrift;
import ch.epfl.eagle.daemon.util.Logging;
import ch.epfl.eagle.daemon.util.Network;
import ch.epfl.eagle.daemon.util.Resources;
import ch.epfl.eagle.daemon.util.TClients;
import ch.epfl.eagle.thrift.BackendService;
import ch.epfl.eagle.thrift.GetTaskService;
import ch.epfl.eagle.thrift.TFullTaskId;
import ch.epfl.eagle.thrift.THostPort;
import ch.epfl.eagle.thrift.TTaskLaunchSpec;
/*
 * EAGLE 
 *
 * Copyright 2016 Operating Systems Laboratory EPFL
 *
 * Modified from Sparrow - University of California, Berkeley 
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package ch.epfl.eagle.daemon.nodemonitor;





/**
 * TaskLauncher service consumes TaskReservations produced by {@link TaskScheduler.getNextTask}.
 * For each TaskReservation, the TaskLauncherService attempts to fetch the task specification from
 * the scheduler that sent the reservation using the {@code getTask} RPC; if it successfully
 * fetches a task, it launches the task on the appropriate backend.
 *
 * TaskLauncherService uses multiple threads to launch tasks. Each thread keeps a client for
 * each scheduler, and a client for each application backend, and the TaskLauncherService uses
 * a number of threads equal to the number of slots available for running tasks on the machine.
 */
public class TaskLauncherService {
  private final static Logger LOG = Logger.getLogger(TaskLauncherService.class);
  private final static Logger AUDIT_LOG = Logging.getAuditLogger(TaskLauncherService.class);

  /* The number of threads used by the service. */
  private int numThreads;

  private THostPort nodeMonitorInternalAddress;

  private TaskScheduler scheduler;

  /** A runnable that spins in a loop asking for tasks to launch and launching them. */
  private class TaskLaunchRunnable implements Runnable {

    /** Client to use to communicate with each scheduler (indexed by scheduler hostname). */
    private HashMap<String, GetTaskService.Client> schedulerClients = Maps.newHashMap();

    /** Client to use to communicate with each application backend (indexed by backend address). */
    private HashMap<InetSocketAddress, BackendService.Client> backendClients = Maps.newHashMap();

    @Override
    public void run() {
      while (true) {
        TaskSpec task = scheduler.getNextTask(); // blocks until task is ready

        List<TTaskLaunchSpec> taskLaunchSpecs = executeGetTaskRpc(task);
        AUDIT_LOG.info(Logging.auditEventString("node_monitor_get_task_complete", task.requestId,
            nodeMonitorInternalAddress.getHost()));

        if (taskLaunchSpecs.isEmpty()) {
          LOG.debug("Didn't receive a task for request " + task.requestId);
          scheduler.noTaskForReservation(task);
          continue;
        }
        if (taskLaunchSpecs.size() > 1) {
          LOG.warn("Received " + taskLaunchSpecs +
                   " task launch specifications; ignoring all but the first one.");
        }
        task.taskSpec = taskLaunchSpecs.get(0);
        LOG.info("Received task for request " + task.requestId + ", task " +
                  task.taskSpec.getTaskId());

        // Launch the task on the backend.
        AUDIT_LOG.info(Logging.auditEventString("node_monitor_task_launch",
        	System.currentTimeMillis(),
            task.requestId,
            nodeMonitorInternalAddress.getHost(),
            task.taskSpec.getTaskId(),
            task.previousRequestId,
            task.previousTaskId));
        executeLaunchTaskRpc(task);
        LOG.info("Launched task " + task.taskSpec.getTaskId() + " for request " + task.requestId +
            " on application backend at system time " + System.currentTimeMillis());
      }

    }

    /** Uses a getTask() RPC to get the task specification from the appropriate scheduler. */
    private List<TTaskLaunchSpec> executeGetTaskRpc(TaskSpec task) {
      String schedulerAddress = task.schedulerAddress.getAddress().getHostAddress();
      if (!schedulerClients.containsKey(schedulerAddress)) {
        try {
          schedulerClients.put(schedulerAddress,
              TClients.createBlockingGetTaskClient(
                  task.schedulerAddress.getAddress().getHostAddress(),
                  SchedulerThrift.DEFAULT_GET_TASK_PORT));
        } catch (IOException e) {
          LOG.error("Error creating thrift client: " + e.getMessage());
          List<TTaskLaunchSpec> emptyTaskLaunchSpecs = Lists.newArrayList();
          return emptyTaskLaunchSpecs;
        }
      }
      GetTaskService.Client getTaskClient = schedulerClients.get(schedulerAddress);

      long startTimeMillis = System.currentTimeMillis();
      long startGCCount = Logging.getGCCount();

      LOG.debug("Attempting to get task for request " + task.requestId);
      AUDIT_LOG.debug(Logging.auditEventString("node_monitor_get_task_launch", task.requestId,
          nodeMonitorInternalAddress.getHost()));
      List<TTaskLaunchSpec> taskLaunchSpecs;
      try {
        taskLaunchSpecs = getTaskClient.getTask(task.requestId, nodeMonitorInternalAddress, task.originalNodeMonitorAddress);
      } catch (TException e) {
        LOG.error("Error when launching getTask RPC:" + e.getMessage());
        List<TTaskLaunchSpec> emptyTaskLaunchSpecs = Lists.newArrayList();
        return emptyTaskLaunchSpecs;
      }

      long rpcTime = System.currentTimeMillis() - startTimeMillis;
      long numGarbageCollections = Logging.getGCCount() - startGCCount;
      LOG.debug("GetTask() RPC for request " + task.requestId + " completed in " +  rpcTime +
                "ms (" + numGarbageCollections + "GCs occured during RPC)");
      return taskLaunchSpecs;
    }

    /** Executes an RPC to launch a task on an application backend. */
    private void executeLaunchTaskRpc(TaskSpec task) {
      if (!backendClients.containsKey(task.appBackendAddress)) {
        try {
          backendClients.put(task.appBackendAddress,
              TClients.createBlockingBackendClient(task.appBackendAddress));
        } catch (IOException e) {
          LOG.error("Error creating thrift client: " + e.getMessage());
          return;
        }
      }
      BackendService.Client backendClient = backendClients.get(task.appBackendAddress);
      THostPort schedulerHostPort = Network.socketAddressToThrift(task.schedulerAddress);
      TFullTaskId taskId = new TFullTaskId(task.taskSpec.getTaskId(), task.requestId,
          task.appId, schedulerHostPort);
      try {
        backendClient.launchTask(task.taskSpec.bufferForMessage(), taskId, task.user);
      } catch (TException e) {
        LOG.error("Unable to launch task on backend " + task.appBackendAddress + ":" + e);
      }
    }
  }

  public void initialize(Configuration conf, TaskScheduler scheduler,
      int nodeMonitorPort) {
    numThreads = scheduler.getMaxActiveTasks();
    if (numThreads <= 0) {
      // If the scheduler does not enforce a maximum number of tasks, just use a number of
      // threads equal to the number of cores.
      numThreads = Resources.getSystemCPUCount(conf);