Previous Next        Current Page: NeXtMidas Training / Primitives / Working with Messages / processMessage
back
Start Here   
Background   
Common Midas Concepts   
Getting Started - Part 1   
Getting Started - Part 2   
Working with Files   
Option Trees   
Macros - Part 1 (Basics)   
Macros - Part 2 (Graphics)   
NetBeans - Part 1 (Setup)   
NetBeans - Part 2 (GUIs)   
NetBeans - Part 3 (Profiler)   
Eclipse - Part 1 (Setup)   
Eclipse - Part 2 (GUIs)   
Primitives   
   + Overview   
   + Open, Process, Close   
   + Building   
   + The NeXtMidas API   
   + Lab 1   
   + Special Variables   
   + Lab 2   
   + Lab 3*   
   + Files in a Primitive   
   + Lab 4   
   + Lab 5*   
   + Test Macros   
   + Lab 6   
   + Real Time Controls   
   + Lab 7   
   - Working with Messages   
      - processMessage   
      - Sending Messages   
   + Lab 8   
   + Primitive Restarts   
   + Introduction to DSP   
   + Lab 9   
WebStart   
Maps & Imagery   
X-Midas Interoperability   
RMIF & Remoting   
Installing NeXtMidas   
Support & Maintenance   
File Handlers   


  • 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.)
    • Since processMessage(Message) is public it is possible to call it from another thread. This is prevented by adding the if (!thisIsMe()) { MQ.put(msg); return NOOP; } line to the top of the processMessage(Message msg)
    • Typical layout:
        if (!thisIsMe()) { MQ.put(msg); return NOOP; }
        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;
        }
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.

back