|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.miv.mbox.MBoxBase
public abstract class MBoxBase
MBox default implementation usable as base class.
The goal of this implementation is to provide a base to construct other
classes able to handle messages comming from different sources and threads.
The presupposed in this class is that the inheriting class will check
messages at regular time using the method processMessages().
MBox| Nested Class Summary | |
|---|---|
static class |
MBoxBase.Message
Simple message container. |
| Field Summary | |
|---|---|
protected ArrayList<MBoxBase.Message> |
messages
List of unread messages. |
protected ArrayList<MBoxBase.Message> |
mtmp
Temporary array to store messages when sent to the listener to avoid blocking the Receiver that can post messages during the execution of messages. |
| Constructor Summary | |
|---|---|
MBoxBase()
New empty Message Box. |
|
| Method Summary | |
|---|---|
int |
getMessageCount()
|
boolean |
isMBoxEmpty()
|
ArrayList<MBoxBase.Message> |
popPendingMessages()
Like processMessages() but instead of calling the
processMessage(String, Object[]) method for each message, returns the list of
pending messages. |
void |
post(String from,
Object... data)
Post a message in the message box. |
abstract void |
processMessage(String from,
Object[] data)
Method to override to process each incomming message. |
void |
processMessages()
Process all messages. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected ArrayList<MBoxBase.Message> mtmp
protected ArrayList<MBoxBase.Message> messages
| Constructor Detail |
|---|
public MBoxBase()
| Method Detail |
|---|
public boolean isMBoxEmpty()
public int getMessageCount()
public void post(String from,
Object... data)
MBox
post in interface MBoxfrom - Identifier of the sending object.data - Array of posted objects.public void processMessages()
processMessage(String, Object[]) for each message in the box.
public ArrayList<MBoxBase.Message> popPendingMessages()
processMessages() but instead of calling the
processMessage(String, Object[]) method for each message, returns the list of
pending messages. The messages are removed from the list of pending messages and therefore
will not be processed by the next calls to processMessages().
public abstract void processMessage(String from,
Object[] data)
processMessage in interface MBoxListenerfrom - The address of the sender.data - The data sent by the sender.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||