Top | Previous | Next |
Message Handler Scripts |
Message handler scripts run when system.util.sendMessage() is called on a remote Client or on the Gateway to send a message. Message handlers can be created for both Gateway and Client scopes. Threading By default, all message handlers for a project execute on a single shared background thread. This arrangement is normally the most efficient. However, if a message handler is performing a lengthy operation, messages may become backed up while waiting for the shared thread. In order to prevent this, you can specify that a message handler runs on its own dedicated thread by setting the Threading value to "Dedicated".
Message payload A message sent using system.util.sendMessage()may optionally contain a message payload Dictionary object to access custom message parameters. This Dictionary can be accessed from the "payload" variable as shown in the example below. If no Dictionary was passed when sending the message, then the "payload" variable will be an empty Dictionary.
Example send script payloadDict = {} payloadDict['first']="Hello" payloadDict['second']="World"
system.util.sendMessage("ProjectX","myHandler",payloadDict)
Example message handler using invokeLater() def handleMessage(payload): """ message = "Message received by ProjectX myHandler. "
if payload.has_key('first'): message += "First param=" + str(payload['first']) + ". "
if payload.has_key('second'): message += "Second param=" + str(payload['second']) + ". "
def handleMessage(theMessage=message): import system window = system.gui.getWindow("Main Window") rootContainer = window.getRootContainer() textarea = rootContainer.getComponent("receivedMessages") textarea.text += theMessage + "\n"
system.util.invokeLater(handleMessage) |