Create a new MessagesImpl instance
the internal session
Command service to send request-response messages specifying a filter
Command service to receive request-response messages
Command service to send request-response messages to a single session
Command service to deregister a request handler
The internal session
The streams registered for the request-response service
Register a request handler to handle requests from other client sessions for a branch of the message path hierarchy.
Each control session may register a single handler for a branch. When the handler is no longer required, it may be closed using the Registration provided by the result. To change the handler for a particular branch the previous handler must first be closed.
Example:
// Create a request handler that handles strings
var handler = {
onRequest: function(request, context, responder) {
console.log(request); // Log the request
responder.respond('something');
},
onError: function() {},
onClose: function() {}
};
// Register the handler
control.messages.addRequestHandler('test/topic', handler).then(function() {
// Registration happened successfully
}, function(error) {
// Registration failed
});
the registration Result that resolves when the handler has been registered, returning a Registration which can be used to unregister the handler.
Otherwise, the Result will fail with an error. Common reasons for failure include:
REGISTER_HANDLER
permission to
register a request handler on the server;
VIEW_SESSION
permission to access
the client's session properties.
Remove the request stream at a particular path.
the request stream that was removed from the path. If
the path does not have a request stream assigned (or the
path does not exist), undefined
will be returned instead.
Send a request to the controller
This is called by sendRequest when no session was specified
a callback to resolve the request
a callback to signal an error
the path to send the request to
the request to send
Send a request to all sessions that satisfy a given session filter.
Example:
// Send a string request to be received by the server and passed to sessions matching the filter.
session.messages.sendRequestToFilter('$Principal NE 'control'', 'test/topic', 'string request', {
onResponse : function(sessionID, response) {
console.log(response); // Log the response
},
onResponseError : function() {},
onError : function() {},
onClose : function() {}});
Example:
// Send a JSON request to be received by the server and passed to sessions matching the filter.
session.messages.sendRequestToFilter('$Principal NE 'control'', 'test/topic',
{ dwarfs: ['sneezy', 'sleepy','dopey' ] },
{
onResponse : function(sessionID, response) {
console.log(response.get()); // Log the response
},
onResponseError : function() {},
onError : function() {},
onClose : function() {}}, diffusion.datatypes.json(), diffusion.datatypes.json());
a Result that resolves when the server has dispatched all the requests.
If the server successfully evaluated the filter, the result of
this contains the number of sessions the request was sent to.
Failure to send a request to a particular matching session is
reported to the callback
.
Otherwise, the Result will fail with an Error. Common reasons for failure include:
filter
parameter could not be parsed;
SEND_TO_SESSION
and
VIEW_SESSION
permissions;
Send a request to a specific session
This is called by sendRequest when a session was specified
a callback to resolve the request
a callback to signal an error
the path to send the request to
the request to send
the target recipient's session ID
Set a request stream to handle requests to a specified path.
Example:
// Set a request stream handler to handle string requests to 'test/topic'
var handler = {
onRequest: function (path, request, responder) {
console.log(request);
responder.respond('hello');
},
onError: function() {}
};
control.messages.setRequestStream('test/topic', handler,
diffusion.datatypes.string(), diffusion.datatypes.string());
undefined
if the request stream is the first stream
to be set to the path, otherwise this method will
return the previously set request stream.
Implementation of the Messages feature