Coverage Report - org.apache.giraph.graph.TaskInfo
 
Classes in this File Line Coverage Branch Coverage Complexity
TaskInfo
0%
0/44
0%
0/12
1.5
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one
 3  
  * or more contributor license agreements.  See the NOTICE file
 4  
  * distributed with this work for additional information
 5  
  * regarding copyright ownership.  The ASF licenses this file
 6  
  * to you under the Apache License, Version 2.0 (the
 7  
  * "License"); you may not use this file except in compliance
 8  
  * with the License.  You may obtain a copy of the License at
 9  
  *
 10  
  *     http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing, software
 13  
  * distributed under the License is distributed on an "AS IS" BASIS,
 14  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15  
  * See the License for the specific language governing permissions and
 16  
  * limitations under the License.
 17  
  */
 18  
 
 19  
 package org.apache.giraph.graph;
 20  
 
 21  
 import org.apache.hadoop.io.Writable;
 22  
 
 23  
 import java.io.DataInput;
 24  
 import java.io.DataOutput;
 25  
 import java.io.IOException;
 26  
 import java.net.InetSocketAddress;
 27  
 
 28  
 /**
 29  
  * Abstract class for information about any task - worker or master.
 30  
  */
 31  
 public abstract class TaskInfo implements Writable {
 32  
   /** Task hostname */
 33  
   private String hostname;
 34  
   /** Port that the IPC server is using */
 35  
   private int port;
 36  
   /** Task partition id */
 37  0
   private int taskId = -1;
 38  
   /** Task host IP */
 39  
   private String hostOrIp;
 40  
 
 41  
   /**
 42  
    * Constructor
 43  
    */
 44  0
   public TaskInfo() {
 45  0
   }
 46  
 
 47  
   /**
 48  
    * Get this task's hostname
 49  
    *
 50  
    * @return Hostname
 51  
    */
 52  
   public String getHostname() {
 53  0
     return hostname.toLowerCase();
 54  
   }
 55  
 
 56  
   /**
 57  
    * Get this task's host address. Could be IP.
 58  
    *
 59  
    * @return host address
 60  
    */
 61  
   public String getHostOrIp() {
 62  0
     return hostOrIp;
 63  
   }
 64  
 
 65  
   /**
 66  
    * Get port that the IPC server of this task is using
 67  
    *
 68  
    * @return Port
 69  
    */
 70  
   public int getPort() {
 71  0
     return port;
 72  
   }
 73  
 
 74  
   /**
 75  
    * Set address that the IPC server of this task is using
 76  
    *
 77  
    * @param address Address
 78  
    * @param host host name or IP
 79  
    */
 80  
   public void setInetSocketAddress(InetSocketAddress address, String host) {
 81  0
     this.port = address.getPort();
 82  0
     this.hostname = address.getHostName();
 83  0
     this.hostOrIp = host;
 84  0
   }
 85  
 
 86  
   /**
 87  
    * Get a new instance of the InetSocketAddress for this hostname and port
 88  
    *
 89  
    * @return InetSocketAddress of the hostname and port.
 90  
    */
 91  
   public InetSocketAddress getInetSocketAddress() {
 92  0
     return new InetSocketAddress(hostOrIp, port);
 93  
   }
 94  
 
 95  
   /**
 96  
    * Set task partition id of this task
 97  
    *
 98  
    * @param taskId partition id
 99  
    */
 100  
   public void setTaskId(int taskId) {
 101  0
     this.taskId = taskId;
 102  0
   }
 103  
 
 104  
   /**
 105  
    * Get task partition id of this task
 106  
    *
 107  
    * @return Task partition id of this task
 108  
    */
 109  
   public int getTaskId() {
 110  0
     return taskId;
 111  
   }
 112  
 
 113  
   /**
 114  
    * Get hostname and task id
 115  
    *
 116  
    * @return Hostname and task id
 117  
    */
 118  
   public String getHostnameId() {
 119  0
     return getHostname() + "_" + getTaskId();
 120  
   }
 121  
 
 122  
   @Override
 123  
   public boolean equals(Object other) {
 124  0
     if (other instanceof TaskInfo) {
 125  0
       TaskInfo taskInfo = (TaskInfo) other;
 126  0
       if (getHostname().equals(taskInfo.getHostname()) &&
 127  0
           getHostOrIp().equals(taskInfo.getHostOrIp()) &&
 128  0
           (getTaskId() == taskInfo.getTaskId()) &&
 129  0
           (port == taskInfo.getPort() &&
 130  0
           (taskId == taskInfo.getTaskId()))) {
 131  0
         return true;
 132  
       }
 133  
     }
 134  0
     return false;
 135  
   }
 136  
 
 137  
   @Override
 138  
   public String toString() {
 139  0
     return "hostname=" + getHostname() +
 140  0
         " hostOrIp=" + getHostOrIp() +
 141  0
         ", MRtaskID=" + getTaskId() +
 142  0
         ", port=" + getPort();
 143  
   }
 144  
 
 145  
   @Override
 146  
   public void readFields(DataInput input) throws IOException {
 147  0
     hostname = input.readUTF();
 148  0
     hostOrIp = input.readUTF();
 149  0
     port = input.readInt();
 150  0
     taskId = input.readInt();
 151  0
   }
 152  
 
 153  
   @Override
 154  
   public void write(DataOutput output) throws IOException {
 155  0
     output.writeUTF(hostname);
 156  0
     output.writeUTF(hostOrIp);
 157  0
     output.writeInt(port);
 158  0
     output.writeInt(taskId);
 159  0
   }
 160  
 
 161  
   @Override
 162  
   public int hashCode() {
 163  0
     int result = 17;
 164  0
     result = 37 * result + getPort();
 165  0
     result = 37 * result + hostname.hashCode();
 166  0
     result = 37 * result + hostOrIp.hashCode();
 167  0
     result = 37 * result + getTaskId();
 168  0
     return result;
 169  
   }
 170  
 
 171  
 }