Skip to content

Commit 53d4d6b

Browse files
committed
2.2.0 - Attached event buses only receive parent post calls
1 parent 487916e commit 53d4d6b

3 files changed

Lines changed: 8 additions & 37 deletions

File tree

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
group 'me.zero'
2-
version '2.1.0'
2+
version '2.2.0'
33

44
apply plugin: 'java'
55

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
package me.zero.alpine.bus;
22

33
/**
4-
* A type of {@link EventBus} that can have child event buses "attached" to it, allowing them to receive the same method
5-
* calls as the "parent" event bus.
4+
* A type of {@link EventBus} that can have child event buses "attached" to it, allowing them to receive the same events
5+
* that get posted to the parent. In applications with a central {@link EventBus}, this allows users making extensions
6+
* to applications to use their own event bus(es).
67
*
78
* @author Brady
89
* @since 9/15/2018
910
*/
1011
public interface AttachableEventBus extends EventBus {
1112

1213
/**
13-
* Attaches another {@link EventBus} onto this event bus, allowing it to receive the same method calls as this bus.
14-
* In applications with a central {@link EventBus}, this allows users making extensions to applications to use their
15-
* own event bus. Method calls being carried out should prioritize the parent {@link EventBus}.
14+
* Attaches another {@link EventBus} onto this event bus, allowing it to receive the events posted to this bus. Has
15+
* no effect if the given bus has already been attached to this bus.
1616
*
1717
* @param bus The bus
18-
* @see AttachableEventBus#detach(EventBus)
1918
*/
2019
void attach(EventBus bus);
2120

@@ -24,7 +23,6 @@ public interface AttachableEventBus extends EventBus {
2423
* already been called on the given bus.
2524
*
2625
* @param bus The bus
27-
* @see AttachableEventBus#attach(EventBus)
2826
*/
2927
void detach(EventBus bus);
3028
}

src/main/java/me/zero/alpine/bus/AttachableEventManager.java

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
package me.zero.alpine.bus;
22

3-
import me.zero.alpine.listener.EventSubscriber;
4-
import me.zero.alpine.listener.Listener;
5-
6-
import java.util.ArrayList;
73
import java.util.List;
4+
import java.util.concurrent.CopyOnWriteArrayList;
85

96
/**
107
* Implementation of {@link EventManager} that is an {@link AttachableEventBus}.
@@ -17,7 +14,7 @@ public class AttachableEventManager extends EventManager implements AttachableEv
1714
/**
1815
* List of attached event buses.
1916
*/
20-
protected final List<EventBus> attached = new ArrayList<>();
17+
protected final List<EventBus> attached = new CopyOnWriteArrayList<>();
2118

2219
public AttachableEventManager(String name) {
2320
super(name);
@@ -27,30 +24,6 @@ public AttachableEventManager(String name) {
2724
super(name, recursiveDiscovery, superListeners);
2825
}
2926

30-
@Override
31-
public void subscribe(EventSubscriber subscriber) {
32-
super.subscribe(subscriber);
33-
this.attached.forEach(bus -> bus.subscribe(subscriber));
34-
}
35-
36-
@Override
37-
public void subscribe(Listener<?> listener) {
38-
super.subscribe(listener);
39-
this.attached.forEach(bus -> bus.subscribe(listener));
40-
}
41-
42-
@Override
43-
public void unsubscribe(EventSubscriber subscriber) {
44-
super.unsubscribe(subscriber);
45-
this.attached.forEach(bus -> bus.unsubscribe(subscriber));
46-
}
47-
48-
@Override
49-
public void unsubscribe(Listener<?> listener) {
50-
super.unsubscribe(listener);
51-
this.attached.forEach(bus -> bus.unsubscribe(listener));
52-
}
53-
5427
@Override
5528
public void post(Object event) {
5629
super.post(event);

0 commit comments

Comments
 (0)