public class LifeCycleEventDispatcher extends java.lang.Object implements IBlaubotAdminMessageListener, IBlaubotConnectionStateMachineListener
CensusMessage
s, calculates the diff (left or joined
devices and prince changes) and communicates them through the ILifecycleListener
s attached to this Blaubot
instance.
If attached to a ConnectionStateMachine
, dispatches the corresponding
events to it's listeners when a kingdom merge takes place, the king dies, the prince takes over and so on.Modifier and Type | Field and Description |
---|---|
static java.lang.String |
LOG_TAG |
Constructor and Description |
---|
LifeCycleEventDispatcher(IBlaubotDevice ownDevice) |
Modifier and Type | Method and Description |
---|---|
void |
addLifecycleListener(ILifecycleListener lifecycleListener)
Adds an
ILifecycleListener |
void |
notifyConnectedToNetwork()
Simply calls onConnected() on all registered listeners
|
void |
notifyDisconnectedFromNetwork(java.lang.String oldKingUniqueId)
Triggers onDeviceLeft(..) for all of the known devices from the old
network (except the own devices) followed by a onDisconnected() on
the
ILifecycleListener added to this Blaubot
instance. |
void |
onAdminMessage(AbstractAdminMessage adminMessage)
Called when an admin message was received
|
void |
onStateChanged(IBlaubotState oldState,
IBlaubotState newState)
Gets called when the
ConnectionStateMachine 's state changed to state. |
void |
onStateMachineStarted()
Gets called when the
ConnectionStateMachine changes it's IBlaubotState
from the StoppedState to another IBlaubotState . |
void |
onStateMachineStopped()
Gets called when the
ConnectionStateMachine stopped. |
void |
removeLifecycleListener(ILifecycleListener lifecycleListener)
Removes an
ILifecycleListener |
public static final java.lang.String LOG_TAG
public LifeCycleEventDispatcher(IBlaubotDevice ownDevice)
public void onAdminMessage(AbstractAdminMessage adminMessage)
IBlaubotAdminMessageListener
onAdminMessage
in interface IBlaubotAdminMessageListener
adminMessage
- the received admin messagepublic void onStateChanged(IBlaubotState oldState, IBlaubotState newState)
IBlaubotConnectionStateMachineListener
ConnectionStateMachine
's state changed to state.onStateChanged
in interface IBlaubotConnectionStateMachineListener
oldState
- the former state (can be null)newState
- the new statepublic void notifyConnectedToNetwork()
public void notifyDisconnectedFromNetwork(java.lang.String oldKingUniqueId)
ILifecycleListener
added to this Blaubot
instance.oldKingUniqueId
- the uniqueDeviceId of the former network's king device.public void onStateMachineStopped()
IBlaubotConnectionStateMachineListener
ConnectionStateMachine
stopped.
This means a state change to StoppedState
and is a shorthand for
public void onStateChange(IBlaubotState state) {
if(state instanceof StoppedState) {
// code
}
}onStateMachineStopped
in interface IBlaubotConnectionStateMachineListener
public void onStateMachineStarted()
IBlaubotConnectionStateMachineListener
ConnectionStateMachine
changes it's IBlaubotState
from the StoppedState
to another IBlaubotState
.onStateMachineStarted
in interface IBlaubotConnectionStateMachineListener
public void addLifecycleListener(ILifecycleListener lifecycleListener)
ILifecycleListener
lifecycleListener
- the listener to addpublic void removeLifecycleListener(ILifecycleListener lifecycleListener)
ILifecycleListener
lifecycleListener
- the listener to remove