001/* 002 * Copyright 2002-2019 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.context; 018 019import java.util.EventObject; 020 021/** 022 * Class to be extended by all application events. Abstract as it 023 * doesn't make sense for generic events to be published directly. 024 * 025 * @author Rod Johnson 026 * @author Juergen Hoeller 027 * @see org.springframework.context.ApplicationListener 028 * @see org.springframework.context.event.EventListener 029 */ 030public abstract class ApplicationEvent extends EventObject { 031 032 /** use serialVersionUID from Spring 1.2 for interoperability. */ 033 private static final long serialVersionUID = 7099057708183571937L; 034 035 /** System time when the event happened. */ 036 private final long timestamp; 037 038 039 /** 040 * Create a new {@code ApplicationEvent}. 041 * @param source the object on which the event initially occurred or with 042 * which the event is associated (never {@code null}) 043 */ 044 public ApplicationEvent(Object source) { 045 super(source); 046 this.timestamp = System.currentTimeMillis(); 047 } 048 049 050 /** 051 * Return the system time in milliseconds when the event occurred. 052 */ 053 public final long getTimestamp() { 054 return this.timestamp; 055 } 056 057}