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.EvaluatorRequestor;
023import org.apache.reef.driver.task.TaskConfiguration;
024import org.apache.reef.tang.Configuration;
025import org.apache.reef.tang.annotations.Unit;
026import org.apache.reef.wake.EventHandler;
027import org.apache.reef.wake.time.event.StartTime;
028
029import javax.inject.Inject;
030import java.util.logging.Level;
031import java.util.logging.Logger;
032
033/**
034 * The Driver code for the Hello REEF Application.
035 */
036@Unit
037public final class HelloDriver {
038
039  private static final Logger LOG = Logger.getLogger(HelloDriver.class.getName());
040
041  private final EvaluatorRequestor requestor;
042
043  /**
044   * Job driver constructor - instantiated via TANG.
045   *
046   * @param requestor evaluator requestor object used to create new evaluator containers.
047   */
048  @Inject
049  private HelloDriver(final EvaluatorRequestor requestor) {
050    this.requestor = requestor;
051    LOG.log(Level.FINE, "Instantiated 'HelloDriver'");
052  }
053
054  /**
055   * Handles the StartTime event: Request as single Evaluator.
056   */
057  public final class StartHandler implements EventHandler<StartTime> {
058    @Override
059    public void onNext(final StartTime startTime) {
060      HelloDriver.this.requestor.newRequest()
061          .setNumber(1)
062          .setMemory(64)
063          .setNumberOfCores(1)
064          .submit();
065      LOG.log(Level.INFO, "Requested Evaluator.");
066    }
067  }
068
069  /**
070   * Handles AllocatedEvaluator: Submit the HelloTask.
071   */
072  public final class EvaluatorAllocatedHandler implements EventHandler<AllocatedEvaluator> {
073    @Override
074    public void onNext(final AllocatedEvaluator allocatedEvaluator) {
075      LOG.log(Level.INFO, "Submitting HelloREEF task to AllocatedEvaluator: {0}", allocatedEvaluator);
076      final Configuration taskConfiguration = TaskConfiguration.CONF
077          .set(TaskConfiguration.IDENTIFIER, "HelloREEFTask")
078          .set(TaskConfiguration.TASK, HelloTask.class)
079          .build();
080      allocatedEvaluator.submitTask(taskConfiguration);
081    }
082  }
083}