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.runtime.common.evaluator;
020
021import org.apache.reef.io.TempFileCreator;
022import org.apache.reef.io.WorkingDirectoryTempFileCreator;
023import org.apache.reef.runtime.common.evaluator.parameters.*;
024import org.apache.reef.runtime.common.launch.parameters.ErrorHandlerRID;
025import org.apache.reef.runtime.common.launch.parameters.LaunchID;
026import org.apache.reef.tang.ExternalConstructor;
027import org.apache.reef.tang.formats.ConfigurationModule;
028import org.apache.reef.tang.formats.ConfigurationModuleBuilder;
029import org.apache.reef.tang.formats.OptionalParameter;
030import org.apache.reef.tang.formats.RequiredParameter;
031import org.apache.reef.wake.time.Clock;
032
033import javax.inject.Inject;
034import java.util.concurrent.ExecutorService;
035import java.util.concurrent.Executors;
036
037/**
038 * The runtime configuration of an evaluator.
039 */
040public final class EvaluatorConfiguration extends ConfigurationModuleBuilder {
041  public static final RequiredParameter<String> DRIVER_REMOTE_IDENTIFIER = new RequiredParameter<>();
042  public static final RequiredParameter<String> EVALUATOR_IDENTIFIER = new RequiredParameter<>();
043  public static final RequiredParameter<String> ROOT_CONTEXT_CONFIGURATION = new RequiredParameter<>();
044  public static final OptionalParameter<String> ROOT_SERVICE_CONFIGURATION = new OptionalParameter<>();
045  public static final OptionalParameter<String> TASK_CONFIGURATION = new OptionalParameter<>();
046  public static final OptionalParameter<Integer> HEARTBEAT_PERIOD = new OptionalParameter<>();
047  public static final OptionalParameter<String> APPLICATION_IDENTIFIER = new OptionalParameter<>();
048
049  /**
050   * The EVALUATOR_CONFIG_MODULE_BUILDER which contains bindings shared for all kinds of Evaluators.
051   */
052  private static final ConfigurationModuleBuilder EVALUATOR_CONFIG_MODULE_BUILDER = new EvaluatorConfiguration()
053      .bindNamedParameter(DriverRemoteIdentifier.class, DRIVER_REMOTE_IDENTIFIER)
054      .bindNamedParameter(ErrorHandlerRID.class, DRIVER_REMOTE_IDENTIFIER)
055      .bindNamedParameter(EvaluatorIdentifier.class, EVALUATOR_IDENTIFIER)
056      .bindNamedParameter(HeartbeatPeriod.class, HEARTBEAT_PERIOD)
057      .bindNamedParameter(RootContextConfiguration.class, ROOT_CONTEXT_CONFIGURATION)
058      .bindNamedParameter(InitialTaskConfiguration.class, TASK_CONFIGURATION)
059      .bindNamedParameter(RootServiceConfiguration.class, ROOT_SERVICE_CONFIGURATION)
060      .bindNamedParameter(ApplicationIdentifier.class, APPLICATION_IDENTIFIER)
061      .bindNamedParameter(LaunchID.class, APPLICATION_IDENTIFIER);
062
063  /**
064   * This is ConfigurationModule for CLR Evaluator.
065   */
066  public static final ConfigurationModule CONFCLR = EVALUATOR_CONFIG_MODULE_BUILDER.build();
067
068  /**
069   * This is ConfigurationModule for Java Evaluator.
070   */
071  public static final ConfigurationModule CONF = EVALUATOR_CONFIG_MODULE_BUILDER
072      .bindImplementation(TempFileCreator.class, WorkingDirectoryTempFileCreator.class)
073      .bindSetEntry(Clock.RuntimeStartHandler.class, EvaluatorRuntime.RuntimeStartHandler.class)
074      .bindSetEntry(Clock.RuntimeStopHandler.class, EvaluatorRuntime.RuntimeStopHandler.class)
075      .bindConstructor(ExecutorService.class, ExecutorServiceConstructor.class)
076      .build();
077
078  private static final class ExecutorServiceConstructor implements ExternalConstructor<ExecutorService> {
079
080    @Inject
081    ExecutorServiceConstructor() {
082    }
083
084    @Override
085    public ExecutorService newInstance() {
086      return Executors.newCachedThreadPool();
087    }
088  }
089}