Current Page:
NeXtMidas Training
Primitives
Working with Messages
processMessage
|
|
- The
processMessage method.
- All messages sent to a primitive are processed by the
processMessage(Message msg)
method.
- The
processMessage(Message msg) is automatically called when a message
arrives. (It is called in between calls to process(int) )
- If you provide a
processMessage(Message msg) method, always make sure
to call super.processMessage(msg) to process any messages not recognized
(this is usually done last -- in the else clause).
- The
processMessage(Message msg) method, returns NORMAL if
a message has been processed and NOOP if it has not. (It is important
to note that some older primitives do not follow this rule.)
- Typical layout:
public int processMessage(Message msg) {
int status = NORMAL;
if (msg.getName().equals("FOO")) {
// do something
} else if (msg.getName().equals("BAR")) {
// do something
} else if (msg.getName().equals("BAZ")) {
// do something
} else {
status = super.processMessage(msg);
}
return status;
}
- Since
processMessage(Message) is public it is possible to call it from
another thread. To guard against this, many primitives add the following line to the
top of processMessage(Message) that will add the message to the message
queue for processing in the proper thread:
if (!thisIsMe()) { MQ.put(msg); return NOOP; }
X-Midas Users Take Note: |
X-Midas requires manual polling for messages from a global message section. In NeXtMidas
there is no "global" message system, all messages are directly sent to their intended
recipient. If the recipient is a primitive, it will automatically be passed into the
processMessage(Message) method.
|
|
|
|