public abstract class AbstractComponentControllerBase<COMPONENT extends IComponent> extends Object implements IComponentControllerBase<COMPONENT>
IComponentControllerBase.
Namely:
getComponent()getComponentControl()isRunning()isPaused()awaitState(ComponentState...)awaitState(long, ComponentState...)getState()inState(ComponentState...)notInState(ComponentState...)IComponent.
getComponent()getComponentControl()isRunning()isPaused()awaitState(ComponentState...)awaitState(long, ComponentState...)getState()inState(ComponentState...)notInState(ComponentState...)
Suitable for creating custom IComponentControllers or ISharedComponentControllers.
| Modifier and Type | Class and Description |
|---|---|
protected static class |
AbstractComponentControllerBase.AwaitState
Used for filtering states we're awaiting on.
|
| Modifier and Type | Field and Description |
|---|---|
protected boolean |
broadcastingEvents
Tells whether the controller sends events about the state of the
component, i.e., whether it should automatically send starting/stopping
events or not.
|
protected COMPONENT |
component
Component controlled by this controller.
|
protected cz.cuni.amis.utils.flag.Flag<ComponentState> |
componentState
State of the controlled component.
|
protected IComponentControlHelper |
control
Method providing means for direct control of the
component. |
protected cz.cuni.amis.utils.token.IToken |
controllerId
Unique (in context of one agent) id of this controller.
|
protected Logger |
log
Log used by the class, is never null.
|
| Constructor and Description |
|---|
AbstractComponentControllerBase(COMPONENT component,
IComponentControlHelper componentControlHelper,
Logger log)
Initialize the controller.
|
AbstractComponentControllerBase(cz.cuni.amis.utils.token.IToken componentControllerId,
COMPONENT component,
IComponentControlHelper componentControlHelper,
Logger log)
Initialize controller with specific componentControllerId.
|
| Modifier and Type | Method and Description |
|---|---|
ComponentState |
awaitState(ComponentState... states)
Waits until the component reaches one of 'states' or KILLING / KILLED state is reached.
|
ComponentState |
awaitState(long timeoutMillis,
ComponentState... states)
Waits until the component reaches one of 'states' or KILLING / KILLED state is reached.
|
COMPONENT |
getComponent()
Returns controlled component instance.
|
IComponentControlHelper |
getComponentControl()
Returns component control with lifecycle methods of the component controlled by this instance.
|
cz.cuni.amis.utils.token.IToken |
getComponentId()
Unique identification of the component.
|
Logger |
getLog() |
cz.cuni.amis.utils.flag.ImmutableFlag<ComponentState> |
getState()
Returns state of the controlled component (state of the component life-cycle).
|
protected String |
id(IComponent component)
Returns component id or null.
|
boolean |
inState(ComponentState... states)
Whether the component is in one of 'states'.
|
boolean |
isBroadcastingEvents()
Tells whether the controller sends events about the state of the component, i.e., whether it should automatically send
starting/stopping events or not.
|
boolean |
isPaused()
Whether the component is paused (or is pausing/resuming).
|
boolean |
isRunning()
Whether the component has been started, is not stopped or killed, may be paused.
|
boolean |
notInState(ComponentState... states)
Whether the component is not in any of 'states'.
|
void |
setBroadcastingEvents(boolean broadcastingEvents)
Enables (== true) / Disables (== false) sending events about the state of the component, i.e., whether it should automatically send
starting/stopping events or not.
|
protected void |
setState(ComponentState state)
Changes the
componentState to desired state. |
String |
toString() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitfatalError, fatalError, getFatalError, manualKill, manualPause, manualResume, manualStart, manualStartPaused, manualStopprotected cz.cuni.amis.utils.token.IToken controllerId
protected IComponentControlHelper control
component. This object is passed from the outside
of the controller, usually created by the component itself.protected COMPONENT extends IComponent component
protected Logger log
protected cz.cuni.amis.utils.flag.Flag<ComponentState> componentState
Use setState(ComponentState) to alter the value of the flag.
Should not be set manually, use setState(ComponentState) instead.
protected boolean broadcastingEvents
DEFAULT: TRUE (the controller is broadcasting events as default)
Exception: IComponentControllerBase.fatalError(String) and IComponentControllerBase.fatalError(String, Throwable)
must always send fatal error!
public AbstractComponentControllerBase(COMPONENT component, IComponentControlHelper componentControlHelper, Logger log)
controllerId
(adding suffix "-controller" to the IComponent.getComponentId().component - componentControlHelper - log - public AbstractComponentControllerBase(cz.cuni.amis.utils.token.IToken componentControllerId,
COMPONENT component,
IComponentControlHelper componentControlHelper,
Logger log)
componentControllerId - component - componentControlHelper - log - public cz.cuni.amis.utils.token.IToken getComponentId()
IComponentgetComponentId in interface IComponentpublic Logger getLog()
public COMPONENT getComponent()
IComponentControllerBasegetComponent in interface IComponentControllerBase<COMPONENT extends IComponent>public boolean isBroadcastingEvents()
IComponentControllerBaseDEFAULT: TRUE (the controller is broadcasting events as default)
Exception: IComponentControllerBase.fatalError(String) and IComponentControllerBase.fatalError(String, Throwable)
must always send fatal error!
isBroadcastingEvents in interface IComponentControllerBase<COMPONENT extends IComponent>public void setBroadcastingEvents(boolean broadcastingEvents)
IComponentControllerBase
Exception: IComponentControllerBase.fatalError(String) and IComponentControllerBase.fatalError(String, Throwable)
must always send fatal error!
setBroadcastingEvents in interface IComponentControllerBase<COMPONENT extends IComponent>broadcastingEvents - Enables (== true) / Disables (== false)public IComponentControlHelper getComponentControl()
IComponentControllerBaseIComponentControllerBase.getComponent().
IT IS DISCOURAGED TO USE METHODS OF THE IComponentControlHelper DIRECTLY! IT DEFIES THE PURPOSE OF THE CONTROLLER TOTALLY
AND THE CONTROLLER WILL PROBABLY WON'T COPE WITH SUCH BEHAVIOR.
But what the hell, if it solves your problem, go ahead ;-)
getComponentControl in interface IComponentControllerBase<COMPONENT extends IComponent>public boolean isRunning()
IComponentControllerBaseisRunning in interface IComponentControllerBase<COMPONENT extends IComponent>public boolean isPaused()
IComponentControllerBaseisPaused in interface IComponentControllerBase<COMPONENT extends IComponent>public cz.cuni.amis.utils.flag.ImmutableFlag<ComponentState> getState()
IComponentControllerBase
It returns flag - therefore you may use WaitForFlagChange to synchronize on the flag changes in other threads or use
awaitState() method.
getState in interface IComponentControllerBase<COMPONENT extends IComponent>public boolean inState(ComponentState... states)
IComponentControllerBaseinState in interface IComponentControllerBase<COMPONENT extends IComponent>public boolean notInState(ComponentState... states)
IComponentControllerBasenotInState in interface IComponentControllerBase<COMPONENT extends IComponent>public ComponentState awaitState(ComponentState... states) throws ComponentKilledException
IComponentControllerBase
If KILLING / KILLED state is not among 'states' then reaching of this state will throw ComponentKilledException exception.
If interrupted, PogamutInterruptedException is thrown.
awaitState in interface IComponentControllerBase<COMPONENT extends IComponent>ComponentKilledExceptionComponentKilledExceptionpublic ComponentState awaitState(long timeoutMillis, ComponentState... states) throws ComponentKilledException
IComponentControllerBase
If KILLING / KILLED state is not among 'states' then reaching of this state will throw ComponentKilledException exception.
If interrupted, PogamutInterruptedException is thrown.
If times out, null is returned.
awaitState in interface IComponentControllerBase<COMPONENT extends IComponent>ComponentKilledExceptionComponentKilledExceptionprotected String id(IComponent component)
component - protected void setState(ComponentState state)
componentState to desired state.state - Copyright © 2012 AMIS research group, Faculty of Mathematics and Physics, Charles University in Prague, Czech Republic. All Rights Reserved.