Eradicated BusAccess and RootBusNode.

Buss is now to be accessed from some static method or field.
master
Ondřej Hruška 11 years ago
parent fbd1ac78fa
commit ab75bb018f
  1. 16
      src/mightypork/utils/eventbus/BusAccess.java
  2. 9
      src/mightypork/utils/eventbus/EventBus.java
  3. 62
      src/mightypork/utils/eventbus/clients/BusNode.java
  4. 60
      src/mightypork/utils/eventbus/clients/RootBusNode.java

@ -1,16 +0,0 @@
package mightypork.utils.eventbus;
/**
* Access to an {@link EventBus} instance
*
* @author Ondřej Hruška (MightyPork)
*/
public interface BusAccess {
/**
* @return event bus
*/
EventBus getEventBus();
}

@ -25,7 +25,7 @@ import mightypork.utils.logging.Log;
* *
* @author Ondřej Hruška (MightyPork) * @author Ondřej Hruška (MightyPork)
*/ */
final public class EventBus implements Destroyable, BusAccess { final public class EventBus implements Destroyable {
/** /**
* Queued event holder * Queued event holder
@ -375,11 +375,4 @@ final public class EventBus implements Destroyable, BusAccess {
return true; return true;
} }
@Override
public EventBus getEventBus()
{
return this; // just for compatibility use-case
}
} }

@ -5,8 +5,6 @@ import java.util.Collection;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.Set; import java.util.Set;
import mightypork.utils.annotations.Stub;
import mightypork.utils.eventbus.BusAccess;
import mightypork.utils.eventbus.EventBus; import mightypork.utils.eventbus.EventBus;
@ -16,58 +14,13 @@ import mightypork.utils.eventbus.EventBus;
* *
* @author Ondřej Hruška (MightyPork) * @author Ondřej Hruška (MightyPork)
*/ */
public abstract class BusNode implements BusAccess, ClientHub { public abstract class BusNode implements ClientHub {
private BusAccess busAccess;
private final Set<Object> clients = new LinkedHashSet<>(); private final Set<Object> clients = new LinkedHashSet<>();
private boolean listening = true; private boolean listening = true;
private boolean delegating = true; private boolean delegating = true;
/**
* @param busAccess access to bus
*/
public BusNode(BusAccess busAccess) {
setBusAccess(busAccess);
}
/**
* Create without a bus access. Bus access should be set using the
* setBusAccess() method.
*/
public BusNode() {
}
/**
* Handler called when bus access first provides a valid bus instance.<br>
* The node may now eg. subscribe to the bus.
*/
@Stub
public void onBusReady()
{
// do stuff
}
/**
* Assign a bus access. If the buss access provides a buss, the onBusReady()
* method will be called.
*
* @param busAccess the assigned bus access
*/
public final void setBusAccess(BusAccess busAccess)
{
this.busAccess = busAccess;
if (getEventBus() != null) {
onBusReady();
}
}
@Override @Override
public Collection<Object> getChildClients() public Collection<Object> getChildClients()
{ {
@ -97,10 +50,6 @@ public abstract class BusNode implements BusAccess, ClientHub {
@Override @Override
public void addChildClient(Object client) public void addChildClient(Object client)
{ {
if (client instanceof RootBusNode) {
throw new IllegalArgumentException("Cannot nest RootBusNode.");
}
clients.add(client); clients.add(client);
} }
@ -139,13 +88,4 @@ public abstract class BusNode implements BusAccess, ClientHub {
{ {
this.delegating = delegating; this.delegating = delegating;
} }
@Override
public EventBus getEventBus()
{
if(busAccess==null) return null;
return busAccess.getEventBus();
}
} }

@ -1,60 +0,0 @@
package mightypork.utils.eventbus.clients;
import mightypork.utils.annotations.Stub;
import mightypork.utils.eventbus.BusAccess;
import mightypork.utils.interfaces.Destroyable;
/**
* Bus node that should be directly attached to the bus.
*
* @author Ondřej Hruška (MightyPork)
*/
public abstract class RootBusNode extends BusNode implements Destroyable {
/**
* Create with a bus access.
*
* @param busAccess access to bus
*/
public RootBusNode(BusAccess busAccess) {
super(busAccess);
}
/**
* Create without a bus access. It should be assigned later.
*/
public RootBusNode() {
}
@Override
public void onBusReady()
{
getEventBus().subscribe(this);
}
@Override
public final void destroy()
{
deinit();
if (getEventBus() != null) {
getEventBus().unsubscribe(this);
}
}
/**
* Deinitialize the node (subsystem)<br>
* (called during destruction)
*/
@Stub
protected void deinit()
{
}
}
Loading…
Cancel
Save