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 = DateTimeHelper.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 * @since 1.1.1 58 * @see ApplicationContext 59 * @see ApplicationEventPublisherAware 60 * @see hunt.framework.context.ApplicationEvent 61 * @see hunt.framework.context.event.EventPublicationInterceptor 62 */ 63 interface ApplicationEventPublisher { 64 65 /** 66 * Notify all <strong>matching</strong> listeners registered with this 67 * application of an application event. Events may be framework events 68 * (such as RequestHandledEvent) or application-specific events. 69 * @param event the event to publish 70 * @see hunt.framework.web.context.support.RequestHandledEvent 71 */ 72 final void publishEvent(ApplicationEvent event) { 73 publishEvent(cast(Object) event); 74 } 75 76 /** 77 * Notify all <strong>matching</strong> listeners registered with this 78 * application of an event. 79 * <p>If the specified {@code event} is not an {@link ApplicationEvent}, 80 * it is wrapped in a {@link PayloadApplicationEvent}. 81 * @param event the event to publish 82 * @since 4.2 83 * @see PayloadApplicationEvent 84 */ 85 void publishEvent(Object event); 86 87 }