@Override
	protected void runInternal() {
		MindAppmasterServiceClient client = (MindAppmasterServiceClient) getIntegrationServiceClient();
		Random random = new Random();
		Long job = null;
		boolean die = false;

		// run loop, we exit if appmaster asks or randomly
		// in approximately once every 10 runs
		do {
			JobRequest request = new JobRequest();
			if(job == null) {
				request.setState(JobRequest.State.WHATTODO);
			} else {
				// we send job failed message approximately once in 4 runs
				request.setState(random.nextInt(4) == 0 ? JobRequest.State.JOBFAILED : JobRequest.State.JOBDONE);
				request.job = job;
			}
			JobResponse response = (JobResponse) client.doMindRequest(request);
			if (response == null) {
				die = true;
				break;
			}
			log.info("Response state=" + response.getState());

			if (response.getState().equals(JobResponse.State.RUNJOB)) {
				job = response.getJob();
				log.info("Running job=" + job);
				sleep(5);
			} else if (response.getState().equals(JobResponse.State.DIE)) {
				// appmaster asked us to go away
				die = true;
			} else if (response.getState().equals(JobResponse.State.STANDBY)) {
				// we're on standy, sleep a bit more
				sleep(5);
			}

			// set job which may be null and
			// sleep during the run loop
			job = response.getJob();
			sleep(1);
		} while (!die && random.nextInt(10) > 0);
		log.info("Bye, I'm done baby...");
	}
Customised container with following logic:

1. Loops itself and does requests to appmaster
2. Request is basic what-to-do/job
3. Randomly just die to simulate problems
4. Send back job complete notifications
5. Randomly just fail jobs

@author Janne Valkealahti
yarn/yarn/custom-amservice/src/main/java/org/springframework/yarn/examples/CustomContainer.java