Retry Logic
DWR has built-in automatic retry logic for reverse AJAX/polling calls. Our default retry configuration will work well for the great majority of our users provided that a custom pollStatusHandler has been set. If you would like to learn more about how our default retry policy works or would like to customize it please continue reading.How are default retry policy works
When a problem occurs on a polling request any registered errorHandlers will be ignored. DWR's retry policy will be initiated and in 1 second DWR will try another poll request. If this poll request fails DWR will try another poll request in 3 seconds. If this poll request fails DWR will go offline. At this point DWR will call the pollStatusHandler with a flag indicating that DWR is offline and continue to check for a heartbeat indefinitely at 3 second intervals. If a connection is re-established while DWR is offline the pollStatusHandler will be called with a flag indicating that DWR is back online.Please note that a custom pollStatusHandler should be set (dwr.engine.setPollStatusHandler) otherwise the errorHandler will be used. If the errorHandler is used it will only be called when DWR goes offline, it will NOT be called when a connection is re-established.
Custom Retry Policy
If our default retry policy doesn't fit your needs the policy is highly configurable - please read the sections below to learn more.Retry Intervals
At the heart of the DWR retry policy is the retryIntervals array. The default array [ 1, 3, 3 ] may be overridden by calling dwr.engine.setRetryIntervals. An explanation of the retryIntervals array:- retryIntervals[0 through retryIntervals.length - 1] - Each value in this range indicates a retry interval - DWR is still online!
- retryIntervals.length - 1 = The number of retry attempts until DWR is offline.
- retryIntervals[retryIntervals.length - 1] = The heartbeat interval - how often we check for a re-established connection when DWR is offline.
Poll Status handler
The pollStatusHandler is a function DWR calls when:- DWR goes offline
- DWR comes back online
- maxRetries has been reached
dwr.engine._pollStatusHandler(newStatus, ex, maxRetriesReached)Please note: a custom pollStatusHandler should be set (dwr.engine.setPollStatusHandler) otherwise the errorHandler will be used. If the errorHandler is used it will only be called when DWR goes offline, it will NOT be called when a connection is re-established.