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.ContextSubmittable;
025import org.apache.reef.driver.TaskSubmittable;
026import org.apache.reef.io.naming.Identifiable;
027import org.apache.reef.tang.Configuration;
028
029/**
030 * Represents an active context on an Evaluator.
031 * <p>
032 * A context consists of two configurations:
033 * <ol>
034 * <li>ContextConfiguration: Its visibility is limited to the context itself and tasks spawned from it.</li>
035 * <li>ServiceConfiguration: This is "inherited" by child context spawned.</li>
036 * </ol>
037 * <p>
038 * Contexts have identifiers. A context is instantiated on a single Evaluator. Contexts are either created on an
039 * AllocatedEvaluator (for what is called the "root Context") or by forming sub-Contexts.
040 * <p>
041 * Contexts form a stack. Only the topmost context is active. Child Contexts or Tasks can be submitted to the
042 * active Context. Contexts can be closed, in which case their parent becomes active.
043 * In the case of the root context, closing is equivalent to releasing the Evaluator. A child context "sees" all
044 * Configuration in its parent Contexts.
045 */
046@Public
047@DriverSide
048@Provided
049public interface ActiveContext extends Identifiable, AutoCloseable, ContextBase, TaskSubmittable, ContextSubmittable {
050
051  @Override
052  void close();
053
054  @Override
055  void submitTask(final Configuration taskConf);
056
057  @Override
058  void submitContext(final Configuration contextConfiguration);
059
060  @Override
061  void submitContextAndService(final Configuration contextConfiguration, final Configuration serviceConfiguration);
062
063  /**
064   * Send the active context the message, which will be delivered to all registered
065   * {@link org.apache.reef.evaluator.context.ContextMessageHandler}, for this context.
066   *
067   * @param message The message to be sent.
068   */
069  void sendMessage(final byte[] message);
070
071}