public abstract class Messaging
extends java.lang.Object
Messaging
is an abstract base class for defining a messaging system.Modifier | Constructor and Description |
---|---|
protected |
Messaging()
Constructs a new
Messaging instance. |
Modifier and Type | Method and Description |
---|---|
void |
addMessagingObserver(MessagingObserver messagingObserver)
Adds a
MessagingObserver to this Messaging . |
java.util.List<MessagingObserver> |
getMessagingObservers()
Returns a
List containing all currently added MessagingObserver s. |
java.lang.String |
getName()
Returns the name of this
Messaging instance. |
boolean |
hasStarted()
Returns
true if, and only if, this Messaging has started, false otherwise. |
protected void |
onStart()
Override this method to handle start logic for this
Messaging . |
protected void |
onStop()
Override this method to handle stop logic for this
Messaging . |
void |
removeMessagingObserver(MessagingObserver messagingObserver)
Removes a
MessagingObserver from this Messaging . |
void |
setName(java.lang.String name)
Sets a new name for this
Messaging instance. |
void |
start()
Call this method when you want to start this
Messaging . |
void |
stop()
Call this method when you want to stop this
Messaging . |
public final boolean hasStarted()
true
if, and only if, this Messaging
has started, false
otherwise.true
if, and only if, this Messaging
has started, false
otherwisepublic final java.util.List<MessagingObserver> getMessagingObservers()
List
containing all currently added MessagingObserver
s.
If no MessagingObserver
s have been added, an empty List
will be returned, not null
.
Modifying the returned List
will not affect this Messaging
instance.
List
containing all currently added MessagingObserver
spublic final java.lang.String getName()
Messaging
instance.
By default the name will be equal to getClass().getName()
.
Messaging
instancepublic final void addMessagingObserver(MessagingObserver messagingObserver)
MessagingObserver
to this Messaging
.
If it has already been added, nothing will happen.
If messagingObserver
is null
, a NullPointerException
will be thrown.
messagingObserver
- the MessagingObserver
to addjava.lang.NullPointerException
- thrown if, and only if, messagingObserver
is null
protected void onStart()
Messaging
.
This method will be called as soon as the start()
method is called. This will happen prior to the notification of all currently added MessagingObserver
s.
By default this method does nothing.
protected void onStop()
Messaging
.
This method will be called as soon as the stop()
method is called. This will happen prior to the notification of all currently added MessagingObserver
s.
By default this method does nothing.
public final void removeMessagingObserver(MessagingObserver messagingObserver)
MessagingObserver
from this Messaging
.
If it has not already been added, nothing will happen.
If messagingObserver
is null
, a NullPointerException
will be thrown.
messagingObserver
- the MessagingObserver
to removejava.lang.NullPointerException
- thrown if, and only if, messagingObserver
is null
public final void setName(java.lang.String name)
Messaging
instance.
If name
is null
, a NullPointerException
will be thrown.
By default the name will be equal to getClass().getName()
.
name
- the new name for this Messaging
instancejava.lang.NullPointerException
- thrown if, and only if, name
is null
public final void start()
Messaging
.
This method will first make a call to the onStart()
method. Then all currently added MessagingObserver
s will be notified.
If it has already started, nothing will happen.
public final void stop()
Messaging
.
This method will first make a call to the onStop()
method. Then all currently added MessagingObserver
s will be notified.
If it has already stopped or it has never started, nothing will happen.