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.runtime.common.evaluator.parameters.*; 022import org.apache.reef.tang.ExternalConstructor; 023import org.apache.reef.tang.formats.ConfigurationModule; 024import org.apache.reef.tang.formats.ConfigurationModuleBuilder; 025import org.apache.reef.tang.formats.OptionalParameter; 026import org.apache.reef.tang.formats.RequiredParameter; 027import org.apache.reef.wake.time.Clock; 028 029import javax.inject.Inject; 030import java.util.concurrent.ExecutorService; 031import java.util.concurrent.Executors; 032 033/** 034 * The runtime configuration of an evaluator. 035 */ 036public final class EvaluatorConfiguration extends ConfigurationModuleBuilder { 037 public static final RequiredParameter<String> DRIVER_REMOTE_IDENTIFIER = new RequiredParameter<>(); 038 public static final RequiredParameter<String> EVALUATOR_IDENTIFIER = new RequiredParameter<>(); 039 public static final RequiredParameter<String> ROOT_CONTEXT_CONFIGURATION = new RequiredParameter<>(); 040 public static final OptionalParameter<String> ROOT_SERVICE_CONFIGURATION = new OptionalParameter<>(); 041 public static final OptionalParameter<String> TASK_CONFIGURATION = new OptionalParameter<>(); 042 public static final OptionalParameter<Integer> HEARTBEAT_PERIOD = new OptionalParameter<>(); 043 public static final OptionalParameter<String> APPLICATION_IDENTIFIER = new OptionalParameter<>(); 044 public static final ConfigurationModule CONF = new EvaluatorConfiguration() 045 .bindSetEntry(Clock.RuntimeStartHandler.class, EvaluatorRuntime.RuntimeStartHandler.class) 046 .bindSetEntry(Clock.RuntimeStopHandler.class, EvaluatorRuntime.RuntimeStopHandler.class) 047 .bindConstructor(ExecutorService.class, ExecutorServiceConstructor.class) 048 .bindNamedParameter(DriverRemoteIdentifier.class, DRIVER_REMOTE_IDENTIFIER) 049 .bindNamedParameter(EvaluatorIdentifier.class, EVALUATOR_IDENTIFIER) 050 .bindNamedParameter(HeartbeatPeriod.class, HEARTBEAT_PERIOD) 051 .bindNamedParameter(RootContextConfiguration.class, ROOT_CONTEXT_CONFIGURATION) 052 .bindNamedParameter(InitialTaskConfiguration.class, TASK_CONFIGURATION) 053 .bindNamedParameter(RootServiceConfiguration.class, ROOT_SERVICE_CONFIGURATION) 054 .bindNamedParameter(ApplicationIdentifier.class, APPLICATION_IDENTIFIER) 055 .build(); 056 057 private final static class ExecutorServiceConstructor implements ExternalConstructor<ExecutorService> { 058 059 @Inject 060 ExecutorServiceConstructor() { 061 } 062 063 @Override 064 public ExecutorService newInstance() { 065 return Executors.newCachedThreadPool(); 066 } 067 } 068}