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> EVALUATOR_CONFIGURATION = new OptionalParameter<>(); 045 public static final OptionalParameter<String> ROOT_SERVICE_CONFIGURATION = new OptionalParameter<>(); 046 public static final OptionalParameter<String> TASK_CONFIGURATION = new OptionalParameter<>(); 047 public static final OptionalParameter<Integer> HEARTBEAT_PERIOD = new OptionalParameter<>(); 048 public static final OptionalParameter<String> APPLICATION_IDENTIFIER = new OptionalParameter<>(); 049 050 /** 051 * The EVALUATOR_CONFIG_MODULE_BUILDER which contains bindings shared for all kinds of Evaluators. 052 */ 053 private static final ConfigurationModuleBuilder EVALUATOR_CONFIG_MODULE_BUILDER = new EvaluatorConfiguration() 054 .bindNamedParameter(DriverRemoteIdentifier.class, DRIVER_REMOTE_IDENTIFIER) 055 .bindNamedParameter(ErrorHandlerRID.class, DRIVER_REMOTE_IDENTIFIER) 056 .bindNamedParameter(EvaluatorIdentifier.class, EVALUATOR_IDENTIFIER) 057 .bindNamedParameter(HeartbeatPeriod.class, HEARTBEAT_PERIOD) 058 .bindNamedParameter(org.apache.reef.runtime.common.evaluator.parameters.EvaluatorConfiguration.class, 059 EVALUATOR_CONFIGURATION) 060 .bindNamedParameter(RootContextConfiguration.class, ROOT_CONTEXT_CONFIGURATION) 061 .bindNamedParameter(InitialTaskConfiguration.class, TASK_CONFIGURATION) 062 .bindNamedParameter(RootServiceConfiguration.class, ROOT_SERVICE_CONFIGURATION) 063 .bindNamedParameter(ApplicationIdentifier.class, APPLICATION_IDENTIFIER) 064 .bindNamedParameter(LaunchID.class, APPLICATION_IDENTIFIER); 065 066 /** 067 * This is ConfigurationModule for CLR Evaluator. 068 */ 069 public static final ConfigurationModule CONFCLR = EVALUATOR_CONFIG_MODULE_BUILDER.build(); 070 071 /** 072 * This is ConfigurationModule for Java Evaluator. 073 */ 074 public static final ConfigurationModule CONF = EVALUATOR_CONFIG_MODULE_BUILDER 075 .bindImplementation(TempFileCreator.class, WorkingDirectoryTempFileCreator.class) 076 .bindSetEntry(Clock.RuntimeStartHandler.class, EvaluatorRuntime.RuntimeStartHandler.class) 077 .bindSetEntry(Clock.RuntimeStopHandler.class, EvaluatorRuntime.RuntimeStopHandler.class) 078 .bindConstructor(ExecutorService.class, ExecutorServiceConstructor.class) 079 .build(); 080 081 private static final class ExecutorServiceConstructor implements ExternalConstructor<ExecutorService> { 082 083 @Inject 084 ExecutorServiceConstructor() { 085 } 086 087 @Override 088 public ExecutorService newInstance() { 089 return Executors.newCachedThreadPool(); 090 } 091 } 092}