Skip to content

Commit

Permalink
2.2.0 - Attached event buses only receive parent post calls
Browse files Browse the repository at this point in the history
  • Loading branch information
ZeroMemes committed Jul 4, 2022
1 parent 487916e commit 53d4d6b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 37 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group 'me.zero'
version '2.1.0'
version '2.2.0'

apply plugin: 'java'

Expand Down
12 changes: 5 additions & 7 deletions src/main/java/me/zero/alpine/bus/AttachableEventBus.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
package me.zero.alpine.bus;

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

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

Expand All @@ -24,7 +23,6 @@ public interface AttachableEventBus extends EventBus {
* already been called on the given bus.
*
* @param bus The bus
* @see AttachableEventBus#attach(EventBus)
*/
void detach(EventBus bus);
}
31 changes: 2 additions & 29 deletions src/main/java/me/zero/alpine/bus/AttachableEventManager.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package me.zero.alpine.bus;

import me.zero.alpine.listener.EventSubscriber;
import me.zero.alpine.listener.Listener;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

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

public AttachableEventManager(String name) {
super(name);
Expand All @@ -27,30 +24,6 @@ public AttachableEventManager(String name) {
super(name, recursiveDiscovery, superListeners);
}

@Override
public void subscribe(EventSubscriber subscriber) {
super.subscribe(subscriber);
this.attached.forEach(bus -> bus.subscribe(subscriber));
}

@Override
public void subscribe(Listener<?> listener) {
super.subscribe(listener);
this.attached.forEach(bus -> bus.subscribe(listener));
}

@Override
public void unsubscribe(EventSubscriber subscriber) {
super.unsubscribe(subscriber);
this.attached.forEach(bus -> bus.unsubscribe(subscriber));
}

@Override
public void unsubscribe(Listener<?> listener) {
super.unsubscribe(listener);
this.attached.forEach(bus -> bus.unsubscribe(listener));
}

@Override
public void post(Object event) {
super.post(event);
Expand Down

0 comments on commit 53d4d6b

Please sign in to comment.