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.driver.task;
020
021import org.apache.reef.tang.formats.*;
022import org.apache.reef.task.Task;
023import org.apache.reef.task.TaskMessageSource;
024import org.apache.reef.task.events.*;
025import org.apache.reef.wake.EventHandler;
026
027/**
028 * A ConfigurationModule to fill out to generate legal task Configurations that can be submitted.
029 */
030public class TaskConfiguration extends ConfigurationModuleBuilder {
031
032  /**
033   * Identifier for the task.
034   */
035  public static final RequiredParameter<String> IDENTIFIER = new RequiredParameter<>();
036
037  /**
038   * The task to instantiate.
039   */
040  public static final RequiredImpl<Task> TASK = new RequiredImpl<>();
041
042  /**
043   * Handler for task suspension. Defaults to task failure if not bound.
044   */
045  public static final OptionalImpl<EventHandler<SuspendEvent>> ON_SUSPEND = new OptionalImpl<>();
046
047  /**
048   * Handler for messages from the driver. Defaults to task failure if not bound.
049   */
050  public static final OptionalImpl<EventHandler<DriverMessage>> ON_MESSAGE = new OptionalImpl<>();
051
052  /**
053   * Handler for closure requests from the driver. Defaults to task failure if not bound.
054   */
055  public static final OptionalImpl<EventHandler<CloseEvent>> ON_CLOSE = new OptionalImpl<>();
056
057  /**
058   * The Base64 encoded memento to be passed to Task.call().
059   * You can do the encoding for example via DatatypeConverter.printBase64Binary()
060   */
061  public static final OptionalParameter<String> MEMENTO = new OptionalParameter<>();
062
063  /**
064   * Message source invoked upon each evaluator heartbeat.
065   */
066  public static final OptionalImpl<TaskMessageSource> ON_SEND_MESSAGE = new OptionalImpl<>();
067
068  /**
069   * Event handler to receive TaskStart after the Task.call() method was called.
070   */
071  public static final OptionalImpl<EventHandler<TaskStart>> ON_TASK_STARTED = new OptionalImpl<>();
072
073  /**
074   * Event handler to receive TaskStop after the Task.call() method returned.
075   */
076  public static final OptionalImpl<EventHandler<TaskStop>> ON_TASK_STOP = new OptionalImpl<>();
077
078  /**
079   * ConfigurationModule to fill out for a Task configuration.
080   */
081  public static final ConfigurationModule CONF = new TaskConfiguration()
082      .bindNamedParameter(TaskConfigurationOptions.Identifier.class, IDENTIFIER)
083      .bindImplementation(Task.class, TASK)
084      .bindNamedParameter(TaskConfigurationOptions.Memento.class, MEMENTO)
085      .bindNamedParameter(TaskConfigurationOptions.CloseHandler.class, ON_CLOSE)
086      .bindNamedParameter(TaskConfigurationOptions.SuspendHandler.class, ON_SUSPEND)
087      .bindNamedParameter(TaskConfigurationOptions.MessageHandler.class, ON_MESSAGE)
088      .bindSetEntry(TaskConfigurationOptions.TaskMessageSources.class, ON_SEND_MESSAGE)
089      .bindSetEntry(TaskConfigurationOptions.StartHandlers.class, ON_TASK_STARTED)
090      .bindSetEntry(TaskConfigurationOptions.StopHandlers.class, ON_TASK_STOP)
091      .build();
092}