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, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018 019 package org.apache.hadoop.yarn.api.records.timeline; 020 021 import java.util.HashMap; 022 import java.util.Map; 023 024 import javax.xml.bind.annotation.XmlAccessType; 025 import javax.xml.bind.annotation.XmlAccessorType; 026 import javax.xml.bind.annotation.XmlElement; 027 import javax.xml.bind.annotation.XmlRootElement; 028 029 import org.apache.hadoop.classification.InterfaceAudience.Public; 030 import org.apache.hadoop.classification.InterfaceStability.Unstable; 031 032 /** 033 * The class that contains the information of an event that is related to some 034 * conceptual entity of an application. Users are free to define what the event 035 * means, such as starting an application, getting allocated a container and 036 * etc. 037 */ 038 @XmlRootElement(name = "event") 039 @XmlAccessorType(XmlAccessType.NONE) 040 @Public 041 @Unstable 042 public class TimelineEvent implements Comparable<TimelineEvent> { 043 044 private long timestamp; 045 private String eventType; 046 private Map<String, Object> eventInfo = new HashMap<String, Object>(); 047 048 public TimelineEvent() { 049 } 050 051 /** 052 * Get the timestamp of the event 053 * 054 * @return the timestamp of the event 055 */ 056 @XmlElement(name = "timestamp") 057 public long getTimestamp() { 058 return timestamp; 059 } 060 061 /** 062 * Set the timestamp of the event 063 * 064 * @param timestamp 065 * the timestamp of the event 066 */ 067 public void setTimestamp(long timestamp) { 068 this.timestamp = timestamp; 069 } 070 071 /** 072 * Get the event type 073 * 074 * @return the event type 075 */ 076 @XmlElement(name = "eventtype") 077 public String getEventType() { 078 return eventType; 079 } 080 081 /** 082 * Set the event type 083 * 084 * @param eventType 085 * the event type 086 */ 087 public void setEventType(String eventType) { 088 this.eventType = eventType; 089 } 090 091 /** 092 * Set the information of the event 093 * 094 * @return the information of the event 095 */ 096 @XmlElement(name = "eventinfo") 097 public Map<String, Object> getEventInfo() { 098 return eventInfo; 099 } 100 101 /** 102 * Add one piece of the information of the event to the existing information 103 * map 104 * 105 * @param key 106 * the information key 107 * @param value 108 * the information value 109 */ 110 public void addEventInfo(String key, Object value) { 111 this.eventInfo.put(key, value); 112 } 113 114 /** 115 * Add a map of the information of the event to the existing information map 116 * 117 * @param eventInfo 118 * a map of of the information of the event 119 */ 120 public void addEventInfo(Map<String, Object> eventInfo) { 121 this.eventInfo.putAll(eventInfo); 122 } 123 124 /** 125 * Set the information map to the given map of the information of the event 126 * 127 * @param eventInfo 128 * a map of of the information of the event 129 */ 130 public void setEventInfo(Map<String, Object> eventInfo) { 131 this.eventInfo = eventInfo; 132 } 133 134 @Override 135 public int compareTo(TimelineEvent other) { 136 if (timestamp > other.timestamp) { 137 return -1; 138 } else if (timestamp < other.timestamp) { 139 return 1; 140 } else { 141 return eventType.compareTo(other.eventType); 142 } 143 } 144 145 @Override 146 public boolean equals(Object o) { 147 if (this == o) 148 return true; 149 if (o == null || getClass() != o.getClass()) 150 return false; 151 152 TimelineEvent event = (TimelineEvent) o; 153 154 if (timestamp != event.timestamp) 155 return false; 156 if (!eventType.equals(event.eventType)) 157 return false; 158 if (eventInfo != null ? !eventInfo.equals(event.eventInfo) : 159 event.eventInfo != null) 160 return false; 161 162 return true; 163 } 164 165 @Override 166 public int hashCode() { 167 int result = (int) (timestamp ^ (timestamp >>> 32)); 168 result = 31 * result + eventType.hashCode(); 169 result = 31 * result + (eventInfo != null ? eventInfo.hashCode() : 0); 170 return result; 171 } 172 }