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