code: protected SimpleSlot getFreeSlotForTask(ExecutionVertex vertex,
  											Iterable<TaskManagerLocation> requestedLocations,
  											boolean localOnly) {
  		// we need potentially to loop multiple times, because there may be false positives
  		// in the set-with-available-instances
  		while (true) {
  			Pair<Instance, Locality> instanceLocalityPair = findInstance(requestedLocations, localOnly);
  
  			if (instanceLocalityPair == null){
  				return null;
  			}
  
  			Instance instanceToUse = instanceLocalityPair.getLeft();
  			Locality locality = instanceLocalityPair.getRight();
  
  			try {
  				SimpleSlot slot = instanceToUse.allocateSimpleSlot();
  				
  				// if the instance has further available slots, re-add it to the set of available resources.
  				if (instanceToUse.hasResourcesAvailable()) {
  					this.instancesWithAvailableResources.put(instanceToUse.getTaskManagerID(), instanceToUse);
  				}
  				
  				if (slot != null) {
  					slot.setLocality(locality);
  					return slot;
  				}
  			}
  			catch (InstanceDiedException e) {
  				// the instance died it has not yet been propagated to this scheduler
  				// remove the instance from the set of available instances
  				removeInstance(instanceToUse);
  			}
  			
  			// if we failed to get a slot, fall through the loop
  		}
  	}
docs: Gets a suitable instance to schedule the vertex execution to.
  <p>
  NOTE: This method does is not thread-safe, it needs to be synchronized by the caller.
  
  @param vertex The task to run.
  @return The instance to run the vertex on, it {@code null}, if no instance is available.