1 /*
2  * Hunt - A refined core library for D programming language.
3  *
4  * Copyright (C) 2018-2019 HuntLabs
5  *
6  * Website: https://www.huntlabs.net/
7  *
8  * Licensed under the Apache-2.0 License.
9  *
10  */
11 
12 module hunt.util.ApplicationEvent;
13 
14 import hunt.util.DateTime;
15 import hunt.util.ObjectUtils;
16 
17 /**
18  * Class to be extended by all application events. Abstract as it
19  * doesn't make sense for generic events to be published directly.
20  *
21  * @author Rod Johnson
22  * @author Juergen Hoeller
23  */
24 abstract class ApplicationEvent : EventObject {
25 
26 	/** System time when the event happened. */
27 	private long timestamp;
28 
29 
30 	/**
31 	 * Create a new ApplicationEvent.
32 	 * @param source the object on which the event initially occurred (never {@code null})
33 	 */
34 	this(Object source) {
35 		super(source);
36 		this.timestamp = DateTime.currentTimeMillis();
37 	}
38 
39 
40 	/**
41 	 * Return the system time in milliseconds when the event happened.
42 	 */
43 	final long getTimestamp() {
44 		return this.timestamp;
45 	}
46 
47 }
48 
49 
50 
51 /**
52  * Interface that encapsulates event publication functionality.
53  * Serves as super-interface for {@link ApplicationContext}.
54  *
55  * @author Juergen Hoeller
56  * @author Stephane Nicoll
57  * @see ApplicationContext
58  * @see ApplicationEventPublisherAware
59  * @see hunt.framework.context.ApplicationEvent
60  * @see hunt.framework.context.event.EventPublicationInterceptor
61  */
62 interface ApplicationEventPublisher {
63 
64 	/**
65 	 * Notify all <strong>matching</strong> listeners registered with this
66 	 * application of an application event. Events may be framework events
67 	 * (such as RequestHandledEvent) or application-specific events.
68 	 * @param event the event to publish
69 	 * @see hunt.framework.web.context.support.RequestHandledEvent
70 	 */
71 	final void publishEvent(ApplicationEvent event) {
72 		publishEvent(cast(Object) event);
73 	}
74 
75 	/**
76 	 * Notify all <strong>matching</strong> listeners registered with this
77 	 * application of an event.
78 	 * <p>If the specified {@code event} is not an {@link ApplicationEvent},
79 	 * it is wrapped in a {@link PayloadApplicationEvent}.
80 	 * @param event the event to publish
81 	 * @since 4.2
82 	 * @see PayloadApplicationEvent
83 	 */
84 	void publishEvent(Object event);
85 
86 }