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.io.network.group.api.task;
020
021import org.apache.reef.io.network.exception.ParentDeadException;
022import org.apache.reef.io.network.group.api.operators.Reduce.ReduceFunction;
023import org.apache.reef.io.network.group.impl.GroupCommunicationMessage;
024import org.apache.reef.io.network.proto.ReefNetworkGroupCommProtos;
025import org.apache.reef.io.serialization.Codec;
026
027import java.util.Map;
028
029/**
030 * Represents the local topology of tasks for an operator. It
031 * provides methods to send/rcv from parents and children
032 * <p>
033 * Every operator is an {@code EventHandler<GroupCommunicationMessage>}
034 * and it will use an instance of this type to delegate the
035 * handling of the message and also uses it to communicate
036 * with its parents and children
037 * <p>
038 * This is an operator facing interface. The actual topology is
039 * maintained in OperatorTopologyStruct. Current strategy is to
040 * maintain two versions of the topology and current operations
041 * are always delegated to effectiveTopology and the baseTopology
042 * is updated while initialization and when user calls updateTopology.
043 * So this is only a wrapper around the two versions of topologies
044 * and manages when to create/update them based on the messages from
045 * the driver.
046 */
047public interface OperatorTopology {
048
049  void handle(GroupCommunicationMessage msg);
050
051  void sendToParent(byte[] encode, ReefNetworkGroupCommProtos.GroupCommMessage.Type reduce) throws ParentDeadException;
052
053  byte[] recvFromParent(ReefNetworkGroupCommProtos.GroupCommMessage.Type msgType) throws ParentDeadException;
054
055  void sendToChildren(byte[] data, ReefNetworkGroupCommProtos.GroupCommMessage.Type msgType) throws ParentDeadException;
056
057  void sendToChildren(Map<String, byte[]> dataMap,
058                      ReefNetworkGroupCommProtos.GroupCommMessage.Type msgType) throws ParentDeadException;
059
060  <T> T recvFromChildren(ReduceFunction<T> redFunc, Codec<T> dataCodec) throws ParentDeadException;
061
062  byte[] recvFromChildren() throws ParentDeadException;
063
064  void initialize() throws ParentDeadException;
065}