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.annotations.Provided; 022import org.apache.reef.annotations.audience.DriverSide; 023import org.apache.reef.annotations.audience.Public; 024import org.apache.reef.driver.task.TaskConfigurationOptions; 025import org.apache.reef.evaluator.context.ContextMessageHandler; 026import org.apache.reef.evaluator.context.ContextMessageSource; 027import org.apache.reef.evaluator.context.events.ContextStart; 028import org.apache.reef.evaluator.context.events.ContextStop; 029import org.apache.reef.evaluator.context.parameters.*; 030import org.apache.reef.runtime.common.evaluator.DefaultDriverConnection; 031import org.apache.reef.runtime.common.evaluator.DriverConnection; 032import org.apache.reef.tang.annotations.Name; 033import org.apache.reef.tang.annotations.NamedParameter; 034import org.apache.reef.tang.formats.ConfigurationModule; 035import org.apache.reef.tang.formats.ConfigurationModuleBuilder; 036import org.apache.reef.tang.formats.OptionalImpl; 037import org.apache.reef.tang.formats.RequiredParameter; 038import org.apache.reef.task.events.TaskStart; 039import org.apache.reef.task.events.TaskStop; 040import org.apache.reef.wake.EventHandler; 041 042/** 043 * A ConfigurationModule for Context Configuration. 044 */ 045@Public 046@DriverSide 047@Provided 048public class ContextConfiguration extends ConfigurationModuleBuilder { 049 050 /** 051 * The identifier of the Context. 052 */ 053 public static final RequiredParameter<String> IDENTIFIER = new RequiredParameter<>(); 054 055 /** 056 * Event handler for context start. Defaults to logging if not bound. 057 */ 058 public static final OptionalImpl<EventHandler<ContextStart>> ON_CONTEXT_STARTED = new OptionalImpl<>(); 059 060 /** 061 * Event handler for context stop. Defaults to logging if not bound. 062 */ 063 public static final OptionalImpl<EventHandler<ContextStop>> ON_CONTEXT_STOP = new OptionalImpl<>(); 064 065 /** 066 * Event handlers to be informed right before a Task enters its call() method. 067 */ 068 public static final OptionalImpl<EventHandler<TaskStart>> ON_TASK_STARTED = new OptionalImpl<>(); 069 070 /** 071 * Event handlers to be informed right after a Task exits its call() method. 072 */ 073 public static final OptionalImpl<EventHandler<TaskStop>> ON_TASK_STOP = new OptionalImpl<>(); 074 075 /** 076 * Source of messages to be called whenever the evaluator is about to make a heartbeat. 077 */ 078 public static final OptionalImpl<ContextMessageSource> ON_SEND_MESSAGE = new OptionalImpl<>(); 079 080 /** 081 * Driver has sent the context a message, and this parameter is used to register a handler 082 * on the context for processing that message. 083 */ 084 public static final OptionalImpl<ContextMessageHandler> ON_MESSAGE = new OptionalImpl<>(); 085 086 /** 087 * Implementation for reconnecting to driver after driver restart. 088 */ 089 public static final OptionalImpl<DriverConnection> ON_DRIVER_RECONNECT = new OptionalImpl<>(); 090 091 /** 092 * A ConfigurationModule for context. 093 */ 094 public static final ConfigurationModule CONF = new ContextConfiguration() 095 .bindNamedParameter(ContextIdentifier.class, IDENTIFIER) 096 .bindNamedParameter(DriverReconnect.class, ON_DRIVER_RECONNECT) 097 .bindSetEntry(ContextStartHandlers.class, ON_CONTEXT_STARTED) 098 .bindSetEntry(ContextStopHandlers.class, ON_CONTEXT_STOP) 099 .bindSetEntry(ContextMessageSources.class, ON_SEND_MESSAGE) 100 .bindSetEntry(ContextMessageHandlers.class, ON_MESSAGE) 101 .bindSetEntry(TaskConfigurationOptions.StartHandlers.class, ON_TASK_STARTED) 102 .bindSetEntry(TaskConfigurationOptions.StopHandlers.class, ON_TASK_STOP) 103 .build(); 104 105 /** 106 * Implementation for re-connecting to driver after driver restart. 107 */ 108 @NamedParameter(doc = "House the implementation for re-connecting to driver after driver restart", 109 default_classes = DefaultDriverConnection.class) 110 public static final class DriverReconnect implements Name<DriverConnection> { 111 } 112}