浏览代码

Remove child event busses.

Closes #662.
pull/670/head
Chris Smith 8 年前
父节点
当前提交
4382bce3aa

+ 1
- 7
src/com/dmdirc/FrameContainer.java 查看文件

@@ -37,7 +37,6 @@ import com.dmdirc.parser.common.CompositionState;
37 37
 import com.dmdirc.ui.messages.BackBuffer;
38 38
 import com.dmdirc.ui.messages.BackBufferFactory;
39 39
 import com.dmdirc.ui.messages.UnreadStatusManager;
40
-import com.dmdirc.util.ChildEventBusManager;
41 40
 
42 41
 import java.util.Collection;
43 42
 import java.util.Collections;
@@ -65,8 +64,6 @@ public class FrameContainer implements WindowModel {
65 64
     private final ConfigChangeListener changer = (d, k) -> iconUpdated();
66 65
     /** The UI components that this frame requires. */
67 66
     private final Set<String> components;
68
-    /** The manager to use to manage our event bus. */
69
-    private final ChildEventBusManager eventBusManager;
70 67
     /** Event bus to dispatch events to. */
71 68
     private final DMDircMBassador eventBus;
72 69
     /** The manager handling this frame's unread status. */
@@ -99,9 +96,7 @@ public class FrameContainer implements WindowModel {
99 96
         this.components = new HashSet<>(components);
100 97
         this.backBufferFactory = backBufferFactory;
101 98
 
102
-        eventBusManager = new ChildEventBusManager(eventBus);
103
-        eventBusManager.connect();
104
-        this.eventBus = eventBusManager.getChildBus();
99
+        this.eventBus = eventBus;
105 100
         this.unreadStatusManager = new UnreadStatusManager(this);
106 101
         this.eventBus.subscribe(unreadStatusManager);
107 102
         configManager.getBinder().bind(unreadStatusManager, UnreadStatusManager.class);
@@ -192,7 +187,6 @@ public class FrameContainer implements WindowModel {
192 187
         eventBus.unsubscribe(unreadStatusManager);
193 188
         configManager.getBinder().unbind(unreadStatusManager);
194 189
         eventBus.publish(new FrameClosingEvent(this));
195
-        eventBusManager.disconnect();
196 190
         getBackBuffer().stopAddingEvents();
197 191
     }
198 192
 

+ 0
- 100
src/com/dmdirc/util/ChildEventBusManager.java 查看文件

@@ -1,100 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
3
- *
4
- * Permission is hereby granted, free of charge, to any person obtaining a copy
5
- * of this software and associated documentation files (the "Software"), to deal
6
- * in the Software without restriction, including without limitation the rights
7
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- * copies of the Software, and to permit persons to whom the Software is
9
- * furnished to do so, subject to the following conditions:
10
- *
11
- * The above copyright notice and this permission notice shall be included in
12
- * all copies or substantial portions of the Software.
13
- *
14
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
- * SOFTWARE.
21
- */
22
-
23
-package com.dmdirc.util;
24
-
25
-import com.dmdirc.DMDircMBassador;
26
-import com.dmdirc.events.DMDircEvent;
27
-
28
-import net.engio.mbassy.listener.Handler;
29
-
30
-import static com.google.common.base.Preconditions.checkNotNull;
31
-
32
-/**
33
- * Utility for creating and managing instances of {@link DMDircMBassador} that are slaved to a
34
- * parent bus.
35
- * <p>
36
- * Any events sent on the child bus will be propagated up to the parent bus.
37
- */
38
-public class ChildEventBusManager {
39
-
40
-    private final DMDircMBassador parent;
41
-    private final DMDircMBassador child;
42
-    private final EventPropagator propagator;
43
-
44
-    public ChildEventBusManager(final DMDircMBassador parent) {
45
-        this.parent = checkNotNull(parent);
46
-        this.child = new DMDircMBassador();
47
-        this.propagator = new EventPropagator();
48
-    }
49
-
50
-    /**
51
-     * Connects the child event bus to the parent.
52
-     * <p>
53
-     * After this method is called, all events sent to the child bus will be passed to the parent.
54
-     */
55
-    public void connect() {
56
-        child.subscribe(propagator);
57
-    }
58
-
59
-    /**
60
-     * Disconnects the child event bus from the parent.
61
-     * <p>
62
-     * The child will be disconnected asynchronously, to allow any pending async events to be
63
-     * dispatched. After the bus is disconnected, no future events will be passed to the parent.
64
-     */
65
-    public void disconnect() {
66
-        child.publishAsync(new ChildEventBusDisconnectingEvent());
67
-    }
68
-
69
-    /**
70
-     * Gets the child bus.
71
-     *
72
-     * @return The child bus belonging to this manager.
73
-     */
74
-    public DMDircMBassador getChildBus() {
75
-        return child;
76
-    }
77
-
78
-    private class EventPropagator {
79
-
80
-        @Handler
81
-        public void handleEvent(final DMDircEvent event) {
82
-            if (!(event instanceof ChildEventBusDisconnectingEvent)) {
83
-                // Don't propagate our private event
84
-                parent.publish(event);
85
-            }
86
-        }
87
-
88
-        // Allow all other handlers on the child bus to process this first
89
-        @Handler(priority = EventUtils.PRIORITY_LOWEST)
90
-        public void handleDisconnect(final ChildEventBusDisconnectingEvent event) {
91
-            child.unsubscribe(propagator);
92
-        }
93
-
94
-    }
95
-
96
-    private static class ChildEventBusDisconnectingEvent extends DMDircEvent {
97
-
98
-    }
99
-
100
-}

+ 0
- 93
test/com/dmdirc/util/ChildEventBusManagerTest.java 查看文件

@@ -1,93 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
3
- *
4
- * Permission is hereby granted, free of charge, to any person obtaining a copy
5
- * of this software and associated documentation files (the "Software"), to deal
6
- * in the Software without restriction, including without limitation the rights
7
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- * copies of the Software, and to permit persons to whom the Software is
9
- * furnished to do so, subject to the following conditions:
10
- *
11
- * The above copyright notice and this permission notice shall be included in
12
- * all copies or substantial portions of the Software.
13
- *
14
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
- * SOFTWARE.
21
- */
22
-
23
-package com.dmdirc.util;
24
-
25
-import com.dmdirc.DMDircMBassador;
26
-import com.dmdirc.events.DMDircEvent;
27
-
28
-import org.junit.Before;
29
-import org.junit.Test;
30
-
31
-import net.engio.mbassy.listener.Handler;
32
-
33
-import static org.junit.Assert.assertNull;
34
-import static org.junit.Assert.assertSame;
35
-
36
-public class ChildEventBusManagerTest {
37
-
38
-    private ChildEventBusManager manager;
39
-    private StubHandler handler;
40
-
41
-    @Before
42
-    public void setup() {
43
-        final DMDircMBassador parent = new DMDircMBassador();
44
-        manager = new ChildEventBusManager(parent);
45
-        handler = new StubHandler();
46
-        parent.subscribe(handler);
47
-    }
48
-
49
-    @Test
50
-    public void testDoesNotPropagateBeforeConnect() {
51
-        manager.getChildBus().publish(new StubEvent());
52
-        assertNull(handler.received);
53
-    }
54
-
55
-    @Test
56
-    public void testDoesNotPropagateAfterDisconnect() throws InterruptedException {
57
-        manager.connect();
58
-        manager.disconnect();
59
-
60
-        // Wait for the asynchronous disconnect to go through. This is a bit lame.
61
-        do {
62
-            Thread.sleep(100);
63
-        } while (manager.getChildBus().hasPendingMessages());
64
-
65
-        manager.getChildBus().publish(new StubEvent());
66
-        assertNull(handler.received);
67
-    }
68
-
69
-    @Test
70
-    public void testPropagates() {
71
-        final DMDircEvent stubEvent = new StubEvent();
72
-
73
-        manager.connect();
74
-        manager.getChildBus().publish(stubEvent);
75
-        assertSame(stubEvent, handler.received);
76
-    }
77
-
78
-    private static class StubHandler {
79
-
80
-        public DMDircEvent received;
81
-
82
-        @Handler
83
-        public void handleEvent(final DMDircEvent event) {
84
-            received = event;
85
-        }
86
-
87
-    }
88
-
89
-    private static class StubEvent extends DMDircEvent {
90
-
91
-    }
92
-
93
-}

正在加载...
取消
保存