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.event;
020
021 import org.apache.hadoop.classification.InterfaceAudience.Public;
022 import org.apache.hadoop.classification.InterfaceStability.Evolving;
023
024 /**
025 * Parent class of all the events. All events extend this class.
026 */
027 @Public
028 @Evolving
029 public abstract class AbstractEvent<TYPE extends Enum<TYPE>>
030 implements Event<TYPE> {
031
032 private final TYPE type;
033 private final long timestamp;
034
035 // use this if you DON'T care about the timestamp
036 public AbstractEvent(TYPE type) {
037 this.type = type;
038 // We're not generating a real timestamp here. It's too expensive.
039 timestamp = -1L;
040 }
041
042 // use this if you care about the timestamp
043 public AbstractEvent(TYPE type, long timestamp) {
044 this.type = type;
045 this.timestamp = timestamp;
046 }
047
048 @Override
049 public long getTimestamp() {
050 return timestamp;
051 }
052
053 @Override
054 public TYPE getType() {
055 return type;
056 }
057
058 @Override
059 public String toString() {
060 return "EventType: " + getType();
061 }
062 }