Ajax Message Queue is an ajax control which is able to poll messages (IJSONMessage) from server.
This control can be used to poll messages :
On server side, messages are stored into a queue. Queue is defined by :
Swith scope queue, ServletContext, HttpSession are used to store queues. Those context are available with HttpServletRequest. But sometimes in some case, this context doesn't exist. For instance log4j have not this HttpServletRequest context. To resolve this problem the HttpServletRequest object is setted into ThreadLocal, by the the Filter MessageQueueFilter.
Message Queue Repository helper class which is used to get queue (and store queue in the good context) can be therefore used, by any classes (HttpServletRequest is not waited into parameter of the method getQueue).
Here a schema which show the role of Message Queue Filter for any http request :
Message Queue Filter is too used for poll messages when JSControlsTags.AjaxMessageQueue javascript control call server. Here a schema which show the role of Message Queue Filter for AJAX http request :
Message Queue Filter must be defined into your web.xml :
<!-- Message Queue Filter --> <filter> <filter-name>MessageQueueFilter</filter-name> <filter-class>net.sourceforge.jscontrolstags.messagequeue.MessageQueueFilter</filter-class> <init-param> <param-name>config</param-name> <param-value>/WEB-INF/messagequeue-config.xml</param-value> </init-param> </filter> <filter-mapping> <filter-name>MessageQueueFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
Queue can be configurate (TODO).
Exemple of messagequeue-config.xml
<messagequeue> <exclude extension="js,css" /> <!-- JSONMessage Queue Context used into WEB Application. --> <context name="log4j" > <scope name="request" clear="true" > </scope> </context> <context name="log4j_with_lazy_false" > <scope name="request" lazy="false" > </scope> </context> </messagequeue>
<!-- include javascript scriptaculous --> <script language="javascript" type="text/javascript" src="../js/scriptaculous/prototype.js"></script> <script language="javascript" type="text/javascript" src="../js/scriptaculous/effects.js"></script> <script language="javascript" type="text/javascript" src="../js/scriptaculous/controls.js"></script> <!-- include javascript jscontrolstags messagequeue --> <script language="javascript" type="text/javascript" src="../js/jscontrolstags-messagequeue.js"></script>
<!-- Include javascript required --> ... <jscontrols-ajax:messageQueue var="ajaxMessageQueue_RequestScope" source="log4jMessages_request" context="log4j" scope="request" fromRequestURI="${pageContext.request.contextPath}/log4jmessage.do" frequency="2" batchSize="$('messageBatchSize_request').value" startPollingOnLoad="false" repeatAfterEmptyMessageReceived="3" onStartPolling="onStartMessage_request" onStopPolling="onStopMessage_request" onEmptyMessageReceived="onEmptyMessage_request" />
Parameter | Description | Required |
var | Name of the JavaScript AjaxMessageQueue created. | no |
source | HTML element to update when messages are received from server. | yes |
context | Context (log4j, ...) of the queue to poll messages. | yes |
scope | Scope (application, session and request) of the queue to poll messages. By default scope=application. | no |
fromRequestURI | This parameter is used only with scope=request. AjaxMessageQueue will be received messages from queue where messages are added with this requestURI. | no |
format | Format of message. | no |
frequency | Interval (not frequency) between refreshes, in seconds. Defaults to 2 seconds. This number will be multiplied by the current decay when invoking theAjax.Updater object | no |
decay | Keeps the current decay level applied when re-executing the task. | no |
batchSize | Number of messages to poll in each request. If not specified, defaults to 10. | no |
startPollingOnLoad | true if AjaxMessageQueue must start poll messages from server when page is loaded, false otherwise. By default startPollingOnLoad=false. | no |
stopPollingAtEmptyMessageReceived | true if AjaxMessageQueue must stop polling messages when it received empty message, and false otherwise. By default stopPollingAtEmptyMessageReceived=true. | no |
onStartPolling | Callback called when AjaxMessageQueue start polling messages. | no |
onStopPolling | Callback called when AjaxMessageQueue stop polling messages. | no |
isStopPolling | Function to stop polling with custom condition. | no |
onEmptyMessageReceived | Callback called when AjaxMessageQueue received empty message. | no |
onMessageReceived | Callback called when AjaxMessageQueue received message. | no |
defaultMessageReceived | true if default message received (insertion of message into source container) must be executed and false otherwise. By default defaultMessageReceived=true | no |
repeatAfterEmptyMessageReceived | no |