1 package dst.ass2.aop.event;
3 import org.springframework.util.Assert;
5 import dst.ass2.aop.IPluginExecutable;
8 * Events triggered by {@link IPluginExecutable}s.
11 private final long time = System.currentTimeMillis();
12 private Class<? extends IPluginExecutable> pluginClass;
13 private EventType type;
14 private String message;
16 public Event(EventType type, Class<? extends IPluginExecutable> pluginClass, String message) {
18 this.pluginClass = pluginClass;
19 this.message = message;
21 StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
22 int pos = stackTrace[1].getMethodName().equals("<init>") ? 1 : 2;
23 Assert.state(stackTrace[pos].getMethodName().equals("<init>"), "Invalid Event Creation");
24 Assert.state(stackTrace[pos + 1].getClassName().equals(EventBus.class.getName()), "Invalid Event Creation");
25 Assert.state(stackTrace[pos + 1].getMethodName().equals("add"), "Invalid Event Creation");
29 * Returns the time when the event occurred.
31 * @return the event creation time
33 public long getTime() {
38 * Returns the type of the plugin that triggered the event.
40 * @return the plugin type
42 public Class<? extends IPluginExecutable> getPluginClass() {
47 * Returns the type of the event.
49 * @return the event type
51 public EventType getType() {
56 * Returns the message of the event
58 * @return the event message
60 public String getMessage() {
65 public String toString() {
66 final StringBuilder sb = new StringBuilder();
68 sb.append("{time=").append(time);
69 sb.append(", pluginClass=").append(pluginClass);
70 sb.append(", type=").append(type);