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.context; 020 021import org.apache.reef.driver.task.TaskConfigurationOptions; 022import org.apache.reef.evaluator.context.events.ContextStart; 023import org.apache.reef.evaluator.context.events.ContextStop; 024import org.apache.reef.evaluator.context.parameters.ContextStartHandlers; 025import org.apache.reef.evaluator.context.parameters.ContextStopHandlers; 026import org.apache.reef.evaluator.context.parameters.Services; 027import org.apache.reef.tang.formats.ConfigurationModule; 028import org.apache.reef.tang.formats.ConfigurationModuleBuilder; 029import org.apache.reef.tang.formats.OptionalImpl; 030import org.apache.reef.tang.formats.OptionalParameter; 031import org.apache.reef.task.events.TaskStart; 032import org.apache.reef.task.events.TaskStop; 033import org.apache.reef.wake.EventHandler; 034 035/** 036 * Configuration module for services. The configuration created here can be passed alongside a ContextConfiguration 037 * to form a context. Different from bindings made in the ContextConfiguration, those made here will be passed along 038 * to child context. 039 */ 040public class ServiceConfiguration extends ConfigurationModuleBuilder { 041 042 /** 043 * A set of services to instantiate. All classes given here will be instantiated in the context, and their references 044 * will be made available to child context and tasks. 045 */ 046 public static final OptionalParameter<Object> SERVICES = new OptionalParameter<>(); 047 048 /** 049 * Event handler for context start. Defaults to logging if not bound. 050 */ 051 public static final OptionalImpl<EventHandler<ContextStart>> ON_CONTEXT_STARTED = new OptionalImpl<>(); 052 053 /** 054 * Event handler for context stop. Defaults to logging if not bound. 055 */ 056 public static final OptionalImpl<EventHandler<ContextStop>> ON_CONTEXT_STOP = new OptionalImpl<>(); 057 058 /** 059 * Event handlers to be informed right before a Task enters its call() method. 060 */ 061 public static final OptionalImpl<EventHandler<TaskStart>> ON_TASK_STARTED = new OptionalImpl<>(); 062 063 /** 064 * Event handlers to be informed right after a Task exits its call() method. 065 */ 066 public static final OptionalImpl<EventHandler<TaskStop>> ON_TASK_STOP = new OptionalImpl<>(); 067 068 /** 069 * ConfigurationModule for services. 070 */ 071 public static final ConfigurationModule CONF = new ServiceConfiguration() 072 .bindSetEntry(Services.class, SERVICES) 073 .bindSetEntry(ContextStartHandlers.class, ON_CONTEXT_STARTED) 074 .bindSetEntry(ContextStopHandlers.class, ON_CONTEXT_STOP) 075 .bindSetEntry(TaskConfigurationOptions.StartHandlers.class, ON_TASK_STARTED) 076 .bindSetEntry(TaskConfigurationOptions.StopHandlers.class, ON_TASK_STOP) 077 .build(); 078 079}