public class MessageHandler extends Object
Modifier and Type | Class and Description |
---|---|
static interface |
MessageHandler.Listener
Listener to handle messages from other applications.
|
Modifier and Type | Method and Description |
---|---|
static MessageHandler |
getInstance()
Get
MessageHandler instance |
static boolean |
isValidName(String name)
Check registered name is valid or not
|
void |
register(String name)
Register this application with the specified name.
Must call this method before sending messages, otherwise a MessageException will be thrown out. The maximum length of name is 32, and only digit, alphabetic, '_', '-' can be used. |
void |
sendMessage(String target,
String message)
Send message to target application with specified registered name
|
String |
sendSystemRequest(String message)
Send a request to system to handle
|
void |
setListener(MessageHandler.Listener listener)
Register a callback to be invoked when receive a message.
|
void |
unregister()
Unregister this application
|
public static MessageHandler getInstance()
MessageHandler
instancepublic void setListener(MessageHandler.Listener listener)
listener
- the Listener
that will be run.public static boolean isValidName(String name)
name
- registered namepublic void register(String name) throws MessageException
name
- registered name of this application. If it is null, a default
name will used.MessageException
- If failed to registerunregister()
public void sendMessage(String target, String message) throws MessageException
target
- registered name of target applicationmessage
- message dataMessageException
- If failed to send message. e.g. send before registeredpublic String sendSystemRequest(String message) throws MessageException
message
- request data in json string formatMessageException
- If failed to send request or the request is invalid.public void unregister()
register(java.lang.String)