|
@@ -31,7 +31,8 @@ import net.engio.mbassy.listener.Handler;
|
31
|
31
|
import static com.google.common.base.Preconditions.checkNotNull;
|
32
|
32
|
|
33
|
33
|
/**
|
34
|
|
- * Utility for creating and managing instances of {@link com.dmdirc.DMDircMBassador} that are slaved to a parent bus.
|
|
34
|
+ * Utility for creating and managing instances of {@link DMDircMBassador} that are slaved to a
|
|
35
|
+ * parent bus.
|
35
|
36
|
* <p>
|
36
|
37
|
* Any events sent on the child bus will be propagated up to the parent bus.
|
37
|
38
|
*/
|
|
@@ -59,10 +60,11 @@ public class ChildEventBusManager {
|
59
|
60
|
/**
|
60
|
61
|
* Disconnects the child event bus from the parent.
|
61
|
62
|
* <p>
|
62
|
|
- * After this method is called, no further events will be passed to the parent.
|
|
63
|
+ * The child will be disconnected asynchronously, to allow any pending async events to be
|
|
64
|
+ * dispatched. After the bus is disconnected, no future events will be passed to the parent.
|
63
|
65
|
*/
|
64
|
66
|
public void disconnect() {
|
65
|
|
- child.unsubscribe(propagator);
|
|
67
|
+ child.publishAsync(new ChildEventBusDisconnectingEvent());
|
66
|
68
|
}
|
67
|
69
|
|
68
|
70
|
/**
|
|
@@ -78,9 +80,22 @@ public class ChildEventBusManager {
|
78
|
80
|
|
79
|
81
|
@Handler
|
80
|
82
|
public void handleEvent(final DMDircEvent event) {
|
81
|
|
- parent.publish(event);
|
|
83
|
+ if (!(event instanceof ChildEventBusDisconnectingEvent)) {
|
|
84
|
+ // Don't propagate our private event
|
|
85
|
+ parent.publish(event);
|
|
86
|
+ }
|
82
|
87
|
}
|
83
|
88
|
|
|
89
|
+ // Allow all other handlers on the child bus to process this first
|
|
90
|
+ @Handler(priority = Integer.MIN_VALUE)
|
|
91
|
+ public void handleDisconnect(final ChildEventBusDisconnectingEvent event) {
|
|
92
|
+ child.unsubscribe(propagator);
|
|
93
|
+ }
|
|
94
|
+
|
|
95
|
+ }
|
|
96
|
+
|
|
97
|
+ private static class ChildEventBusDisconnectingEvent extends DMDircEvent {
|
|
98
|
+
|
84
|
99
|
}
|
85
|
100
|
|
86
|
101
|
}
|