MCPcopy Create free account
hub / github.com/XUANXUQAQ/File-Engine / Event

Class Event

src/main/java/file/engine/event/handler/Event.java:8–79  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6import java.util.function.Consumer;
7
8public class Event {
9 private final AtomicBoolean isFinished = new AtomicBoolean(false);
10 private final AtomicInteger executeTimes = new AtomicInteger(0);
11 private final AtomicBoolean isBlock = new AtomicBoolean(false);
12 private int maxRetryTimes = 5;
13 private volatile Object returnValue;
14 private Consumer<Event> callback;
15 private Consumer<Event> errorHandler;
16
17 protected void incrementExecuteTimes() {
18 executeTimes.incrementAndGet();
19 }
20
21 protected boolean allRetryFailed() {
22 return executeTimes.get() > maxRetryTimes;
23 }
24
25 public boolean isFinished() {
26 return isFinished.get();
27 }
28
29 public void setBlock() {
30 isBlock.set(true);
31 }
32
33 public boolean isBlock() {
34 return isBlock.get();
35 }
36
37 protected void execErrorHandler() {
38 if (this.errorHandler != null) {
39 this.errorHandler.accept(this);
40 }
41 }
42
43 protected void setFinishedAndExecCallback() {
44 if (this.callback != null) {
45 this.callback.accept(this);
46 }
47 isFinished.set(true);
48 }
49
50 protected void setFinished() {
51 isFinished.set(true);
52 }
53
54 public void setReturnValue(Object obj) {
55 this.returnValue = obj;
56 }
57
58 @SuppressWarnings("unchecked")
59 public <T> Optional<T> getReturnValue() {
60 return Optional.ofNullable((T) returnValue);
61 }
62
63 public void setCallback(Consumer<Event> callback) {
64 this.callback = callback;
65 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected