This project has retired. For details please refer to its Attic page.
Source code
001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *   http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied.  See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019package org.apache.reef.examples.hello;
020
021import org.apache.reef.driver.evaluator.AllocatedEvaluator;
022import org.apache.reef.driver.evaluator.EvaluatorRequest;
023import org.apache.reef.driver.evaluator.EvaluatorRequestor;
024import org.apache.reef.driver.task.TaskConfiguration;
025import org.apache.reef.tang.Configuration;
026import org.apache.reef.tang.annotations.Unit;
027import org.apache.reef.wake.EventHandler;
028import org.apache.reef.wake.time.event.StartTime;
029
030import javax.inject.Inject;
031import java.util.logging.Level;
032import java.util.logging.Logger;
033
034/**
035 * The Driver code for the Hello REEF Application.
036 */
037@Unit
038public final class HelloDriver {
039
040  private static final Logger LOG = Logger.getLogger(HelloDriver.class.getName());
041
042  private final EvaluatorRequestor requestor;
043
044  /**
045   * Job driver constructor - instantiated via TANG.
046   *
047   * @param requestor evaluator requestor object used to create new evaluator containers.
048   */
049  @Inject
050  private HelloDriver(final EvaluatorRequestor requestor) {
051    this.requestor = requestor;
052    LOG.log(Level.FINE, "Instantiated 'HelloDriver'");
053  }
054
055  /**
056   * Handles the StartTime event: Request as single Evaluator.
057   */
058  public final class StartHandler implements EventHandler<StartTime> {
059    @Override
060    public void onNext(final StartTime startTime) {
061      HelloDriver.this.requestor.submit(EvaluatorRequest.newBuilder()
062          .setNumber(1)
063          .setMemory(64)
064          .setNumberOfCores(1)
065          .build());
066      LOG.log(Level.INFO, "Requested Evaluator.");
067    }
068  }
069
070  /**
071   * Handles AllocatedEvaluator: Submit the HelloTask.
072   */
073  public final class EvaluatorAllocatedHandler implements EventHandler<AllocatedEvaluator> {
074    @Override
075    public void onNext(final AllocatedEvaluator allocatedEvaluator) {
076      LOG.log(Level.INFO, "Submitting HelloREEF task to AllocatedEvaluator: {0}", allocatedEvaluator);
077      final Configuration taskConfiguration = TaskConfiguration.CONF
078          .set(TaskConfiguration.IDENTIFIER, "HelloREEFTask")
079          .set(TaskConfiguration.TASK, HelloTask.class)
080          .build();
081      allocatedEvaluator.submitTask(taskConfiguration);
082    }
083  }
084}