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