|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object cz.cuni.amis.pogamut.base.component.bus.ComponentBus
public class ComponentBus
Too complex - not suitable for inheritance ... copy paste source code and change it manually.
For more documentation see IComponentBus
.
Field Summary | |
---|---|
static IToken |
COMPONENT_ID
|
Constructor Summary | |
---|---|
ComponentBus(IAgentLogger logger)
|
Method Summary | ||
---|---|---|
void |
addEventListener(java.lang.Class<?> event,
java.lang.Class<?> component,
IComponentEventListener<?> listener)
Attach listener to all events of class 'event' that is produced by any component of class 'component'. |
|
void |
addEventListener(java.lang.Class<?> event,
IComponentEventListener<?> listener)
Attach listener to all events of class 'event'. |
|
void |
addEventListener(java.lang.Class<?> event,
IComponent component,
IComponentEventListener<?> listener)
Attach listener to all events of class 'event' that is produced by the 'component'. |
|
void |
addEventListener(java.lang.Class<?> event,
IToken componentName,
IComponentEventListener<?> listener)
Attach listener to all events of class 'event' that is produced by \component with name 'componentName'. |
|
boolean |
event(IComponentEvent event)
Propagates new event. |
|
void |
eventTransactional(IComponentEvent event)
Propagates new event in the context of current event (if called within the context of event). |
|
|
getComponent(java.lang.Class<T> cls)
Returns component of class 'cls', if there is more then one component for that class than an exception is thrown. |
|
IComponent |
getComponent(IToken name)
Returns registered component of 'componentId'. |
|
IToken |
getComponentId()
Unique identification of the component. |
|
|
getComponents(java.lang.Class<T> cls)
Return all registered components that descend from / implement class 'cls'. |
|
IComponentBus |
getEventBus()
IComponentBus that the instance is working with. |
|
java.util.logging.Logger |
getLog()
|
|
boolean |
isListening(java.lang.Class<?> event,
java.lang.Class<?> component,
IComponentEventListener<?> listener)
Tests whether 'listener' is listening on events of class 'event' on components of class 'component'. |
|
boolean |
isListening(java.lang.Class<?> event,
IComponentEventListener<?> listener)
Tests whether 'listener' is listening on events of class 'class'. |
|
boolean |
isListening(java.lang.Class<?> event,
IComponent component,
IComponentEventListener<?> listener)
Tests whether 'listener' is listening on events of class 'event' on the 'component'. |
|
boolean |
isListening(java.lang.Class<?> event,
IToken componentId,
IComponentEventListener<?> listener)
Tests whether 'listener' is listening on events of class 'event' on component of name 'componentName'. |
|
boolean |
isRunning()
Whether the bus is propagating events. |
|
void |
register(IComponent component)
Registers component into the bus. |
|
void |
remove(IComponent component)
Removes component from the bus. |
|
void |
removeEventListener(java.lang.Class<?> event,
java.lang.Class<?> component,
IComponentEventListener<?> listener)
Removes 'listener' from event 'event' on component 'component'. |
|
void |
removeEventListener(java.lang.Class<?> event,
IComponentEventListener<?> listener)
Removes 'listener' from event 'event'. |
|
void |
removeEventListener(java.lang.Class<?> event,
IComponent component,
IComponentEventListener<?> listener)
Removes 'listener' from event 'event' on the 'component'. |
|
void |
removeEventListener(java.lang.Class<?> event,
IToken componentId,
IComponentEventListener<?> listener)
Removes 'listener' from event 'event' on component of name 'componentName'. |
|
void |
reset()
Restarts the bus and the whole agent system. |
|
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final IToken COMPONENT_ID
Constructor Detail |
---|
@Inject public ComponentBus(IAgentLogger logger)
Method Detail |
---|
public java.lang.String toString()
toString
in class java.lang.Object
public IComponentBus getEventBus()
IComponentAware
IComponentBus
that the instance is working with.
Note that by design-choice - the IComponentBus
is a singleton inside AgentScoped
,
therefore you don't have to necessarily obtain the instance through the component, it suffice
to obtain it using injection into your object.
getEventBus
in interface IComponentAware
public IToken getComponentId()
IComponent
getComponentId
in interface IComponent
public java.util.logging.Logger getLog()
public boolean isRunning()
IComponentBus
Whenever IFatalErrorEvent
is caught - the component bus will stop working immediately and propagate
the fatal error as the last event (so if you will receive IFatalErrorEvent
inside your object then it
is pointless to send more events to the bus.
The only way to make the bus working is to reset() it.
Use this method to examine whether IFatalErrorEvent
occured on the bus (and was broadcast) or not.
isRunning
in interface IComponentBus
public void reset() throws ResetFailedException
IComponentBus
Broadcasts IResetEvent
event. All components should stop working upon reset event and reinitialize their inner data structures
into the initial state. If reset is not possible, the component should throw an exception.
If exception is caught during the reset(), the IFatalErrorEvent
is propagated and the component bus won't start.
If reset() is called, when the component bus is still running, it first broadcasts IFatalErrorEvent
.
Note that you can't propagate any events during the reset (they will be discarded).
reset
in interface IComponentBus
ResetFailedException
- thrown when an exception happens during reset operation, nested exception is available through Throwable.getCause()
public <T> T getComponent(java.lang.Class<T> cls) throws MoreComponentsForClassException
IComponentBus
If no components exist for 'cls', returns empty set.
getComponent
in interface IComponentBus
MoreComponentsForClassException
public <T> java.util.Set<T> getComponents(java.lang.Class<T> cls)
IComponentBus
getComponents
in interface IComponentBus
public void register(IComponent component) throws ComponentIdClashException
IComponentBus
If different component with the same IComponent.getComponentId()
is already registered,
than it throws ComponentIdClashException
and broadcast IFatalErrorEvent
.
register
in interface IComponentBus
ComponentIdClashException
public void remove(IComponent component)
IComponentBus
remove
in interface IComponentBus
public IComponent getComponent(IToken name)
IComponentBus
Returns null if no such component exists.
getComponent
in interface IComponentBus
public void addEventListener(java.lang.Class<?> event, IComponentEventListener<?> listener)
IComponentBus
addEventListener
in interface IComponentBus
public void addEventListener(java.lang.Class<?> event, java.lang.Class<?> component, IComponentEventListener<?> listener)
IComponentBus
addEventListener
in interface IComponentBus
public void addEventListener(java.lang.Class<?> event, IToken componentName, IComponentEventListener<?> listener)
IComponentBus
Note that every component should have unique ID in the context of component bus instance.
addEventListener
in interface IComponentBus
public void addEventListener(java.lang.Class<?> event, IComponent component, IComponentEventListener<?> listener)
IComponentBus
Note that every component should have unique ID in the context of component bus instance.
addEventListener
in interface IComponentBus
public boolean isListening(java.lang.Class<?> event, IComponentEventListener<?> listener)
IComponentBus
isListening
in interface IComponentBus
public boolean isListening(java.lang.Class<?> event, java.lang.Class<?> component, IComponentEventListener<?> listener)
IComponentBus
isListening
in interface IComponentBus
public boolean isListening(java.lang.Class<?> event, IToken componentId, IComponentEventListener<?> listener)
IComponentBus
isListening
in interface IComponentBus
public boolean isListening(java.lang.Class<?> event, IComponent component, IComponentEventListener<?> listener)
IComponentBus
isListening
in interface IComponentBus
public void removeEventListener(java.lang.Class<?> event, IComponentEventListener<?> listener)
IComponentBus
removeEventListener
in interface IComponentBus
public void removeEventListener(java.lang.Class<?> event, java.lang.Class<?> component, IComponentEventListener<?> listener)
IComponentBus
removeEventListener
in interface IComponentBus
public void removeEventListener(java.lang.Class<?> event, IToken componentId, IComponentEventListener<?> listener)
IComponentBus
removeEventListener
in interface IComponentBus
public void removeEventListener(java.lang.Class<?> event, IComponent component, IComponentEventListener<?> listener)
IComponentBus
removeEventListener
in interface IComponentBus
public boolean event(IComponentEvent event) throws ComponentBusNotRunningException, ComponentBusErrorException, FatalErrorPropagatingEventException
IComponentBus
If this event is produced as an answer to other event (that is in the context of the listener call), than the event will be propagated after all listeners reacting to current event finishes. That is - the event will be postponed.
Can't be used to propagate IResetEvent
.
event
in interface IComponentBus
ComponentBusNotRunningException
- thrown when the bus is not running
ComponentBusErrorException
- bus exception (report to authors)
FatalErrorPropagatingEventException
- thrown when some listener throws an exception during the event propagation (use Throwable.getCause()
to get the original exception).'public void eventTransactional(IComponentEvent event) throws ComponentBusNotRunningException, ComponentBusErrorException, FatalErrorPropagatingEventException
IComponentBus
If this method is called from in the context of some listener - then the event will be immediately propagate (unless some other eventTransactional() call is made). It allows you to create chain of events that create something like "transaction". If exception is thrown during this process, every listener will be notified about that and may act accordingly.
Note that if this method is not called in the context of listener then it will be postponed as if event() method is called.
Can't be used to propagate IResetEvent
.
eventTransactional
in interface IComponentBus
ComponentBusNotRunningException
- thrown when the bus is not running
ComponentBusErrorException
- whenever an exception happened during the propagation of the event (wrapped exception is accessible under Throwable.getCause()
)
FatalErrorPropagatingEventException
- thrown when some listener throws an exception during the event propagation (use Throwable.getCause()
to get the original exception).
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |