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.driver; 020 021import org.apache.reef.io.network.group.impl.GroupCommunicationMessage; 022 023/** 024 * A node in the Topology representing a Task on the driver. 025 * Impl should maintain state relating to whether task is running/dead and 026 * status of neighboring nodes and send ctrl msgs to the tasks indicating 027 * topology changing events 028 */ 029public interface TaskNode { 030 031 String getTaskId(); 032 033 int getVersion(); 034 035 int getNumberOfChildren(); 036 037 TaskNode getParent(); 038 039 void setParent(TaskNode parent); 040 041 Iterable<TaskNode> getChildren(); 042 043 void addChild(TaskNode child); 044 045 void removeChild(TaskNode taskNode); 046 047 boolean isRunning(); 048 049 void onRunningTask(); 050 051 void onFailedTask(); 052 053 boolean hasChanges(); 054 055 boolean isNeighborActive(String neighborId); 056 057 void onReceiptOfAcknowledgement(GroupCommunicationMessage msg); 058 059 void onParentRunning(); 060 061 void onParentDead(); 062 063 void onChildRunning(String childId); 064 065 void onChildDead(String childId); 066 067 /** 068 * Check if this node is ready for sending. 069 * TopologySetup 070 */ 071 void checkAndSendTopologySetupMessage(); 072 073 /** 074 * Check if the neighbor node with id source. 075 * is ready for sending TopologySetup 076 * @param source 077 */ 078 void checkAndSendTopologySetupMessageFor(String source); 079 080 /** 081 * reset topology setup ensures that update topology is not sent to someone. 082 * who is already updating topology which is usually when they are just 083 * (re)starting 084 * 085 * @return 086 */ 087 boolean resetTopologySetupSent(); 088 089 void waitForTopologySetupOrFailure(); 090 091 void setSibling(TaskNode leaf); 092 093 TaskNode successor(); 094 095 void updatingTopology(); 096}