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.driver.evaluator;
020
021import org.apache.reef.runtime.common.files.ClasspathProvider;
022import org.apache.reef.runtime.common.files.RuntimePathProvider;
023import org.apache.reef.runtime.common.launch.JavaLaunchCommandBuilder;
024
025import java.util.Collections;
026import java.util.List;
027
028/**
029 * Defines the setup of a JVM process.
030 * Users can set JVM options via {@link #setMemory(int)} and {@link #addOption(String)}.
031 * Runtimes can also set JVM options, but should not do so if users have set options by
032 * checking {@link #isOptionSet()}.
033 */
034public final class JVMProcess implements EvaluatorProcess {
035  private final JavaLaunchCommandBuilder commandBuilder = new JavaLaunchCommandBuilder();
036  private final RuntimePathProvider runtimePathProvider;
037  private final ClasspathProvider classpathProvider;
038  private boolean optionSet = false;
039
040  /**
041   * Instantiated via JVMProcessFactory.
042   */
043  JVMProcess(final RuntimePathProvider runtimePathProvider,
044             final ClasspathProvider classpathProvider) {
045    this.runtimePathProvider = runtimePathProvider;
046    this.classpathProvider = classpathProvider;
047  }
048
049  @Override
050  public List<String> getCommandLine() {
051    return commandBuilder
052        .setJavaPath(runtimePathProvider.getPath())
053        .setClassPath(classpathProvider.getEvaluatorClasspath())
054        .build();
055  }
056
057  @Override
058  public EvaluatorType getType() {
059    return EvaluatorType.JVM;
060  }
061
062  @Override
063  public JVMProcess setMemory(final int megaBytes) {
064    commandBuilder.setMemory(megaBytes);
065    optionSet = true;
066    return this;
067  }
068
069  @Override
070  public boolean isOptionSet() {
071    return optionSet;
072  }
073
074  @Override
075  public JVMProcess setConfigurationFileName(final String configurationFileName) {
076    commandBuilder.setConfigurationFilePaths(Collections.singletonList(configurationFileName));
077    return this;
078  }
079
080  @Override
081  public JVMProcess setStandardOut(final String standardOut) {
082    commandBuilder.setStandardOut(standardOut);
083    return this;
084  }
085
086  @Override
087  public JVMProcess setStandardErr(final String standardErr) {
088    commandBuilder.setStandardErr(standardErr);
089    return this;
090  }
091
092  /**
093   * Add a JVM option.
094   * @param option The full option, e.g. "-XX:+PrintGCDetails", "-Xms500m"
095   * @return this
096   */
097  public JVMProcess addOption(final String option) {
098    commandBuilder.addOption(option);
099    optionSet = true;
100    return this;
101  }
102}