Smart Polling

poller  1.0.0

Smart Polling > poller > Poller
Search:
 
Filters

Class Poller - extends Base

Create a polling task to continually check the server at the specified interval for updates of a resource at a URI. The poller will use conditional GET requests and notifiy the client via Events when the resource has changed.

Constructor

Poller ( config )
Parameters:
config <Object> Configuration Object

Properties

_blurHandle - protected Event.Handle

Event handle referencing the binding to the window's blur event.

_etag - protected String

Etag of the resource returned by the server, used to determine if the resource has changed.

_focusHandle - protected Event.Handle

Event handle referencing the binding to the window's focus event.

_modifiedDate - protected String

Last-Modified date of the resource that the server returned, used to determine if the resource has changed.

_paused - protected Y.later

Reference to the timer object which is waiting to resume from a pause request.

_poller - protected Y.later

Reference to the timer object that's polling the server.

Poller.ATTRS - static Object

Static property used to define the default attribute configuration of the component.

Poller.NAME - static String

The identity of the component.

Properties inherited from Attribute:

Properties inherited from Base:

Methods

_afterHeadersChange

protected void _afterHeadersChange ( e )
Invalidate the cached etag and modifiedDate used to determine if the resource has been changed. Changing the HTTP headers can effect the response returned by the server. Changing this attributed is treated like the changing the url attribute.
Parameters:
e <Event> headersChange custom event
Returns: void

_afterIntervalChange

protected void _afterIntervalChange ( e )
If the polling task is active, it will be stopped then started to use the new interval.
Parameters:
e <Event> intervalChange custom event
Returns: void

_afterPauseInactiveChange

protected void _afterPauseInactiveChange ( e )
Enable/disable the pausing/resuming of the polling task when the window has become inactive/active.
Parameters:
e <Event> pauseInactiveChange custom event
Returns: void

_afterUrlChange

protected void _afterUrlChange ( e )
Invalidate the cached etag and modifiedDate used to determine if the resource has been changed. If the polling task is active then send a request to the server right away.
Parameters:
e <Event> urlChange custom event
Returns: void

_clearPause

protected void _clearPause ( )
Utility method used to clear a pause timer that has been set.
Returns: void

_disablePauseInactive

protected void _disablePauseInactive ( )
Detacheds the event handles from the window's focus and blur events. Preventing the polling to pause when the window is inactive, polling will continue until stop or pause is called.
Returns: void

_enablePauseInactive

protected void _enablePauseInactive ( )
Attaches the event handles to the focus and blur events on the window. Provides a way to automatically pause polling when the browser window is inactive, and starts the polling process right when the windows becomes active again.
Returns: void

_handleBlur

protected void _handleBlur ( e )
Handles the window losing focus, blur. Checks that the component is activly polling (stop hasn't been called), and pauses the polling task.
Parameters:
e <Object>
Returns: void

_handleFocus

protected void _handleFocus ( e )
Handles the window coming into focus. Checks that the component is activly polling (stop hasn't been called), and resumes the polling task.
Parameters:
e <Event> Window focus event
Returns: void

_handleModified

protected void _handleModified ( txId , r , args )
Handles the response from a successful XHR request (2xx response status). The resource has changed on the server if this method has been called. Fires the poller:modified event.
Parameters:
txId <Number> Y.io Transaction ID
r <Object> Y.io Response Object
args <MIXED> Arguments passed to response handler
Returns: void

_handleResponse

protected void _handleResponse ( txId , r , args )
Handles the response from a completed XHR request. Fires the poller:response event.
Parameters:
txId <Number> Y.io Transaction ID
r <Object> Y.io Response Object
args <MIXED> Arguments passed to response handler
Returns: void

_startPolling

protected void _startPolling ( )
Protected method that actually starts the polling task. Calling this method will send a request to the server, fire the poller:start event, and create the interval task.
Returns: void

_stopPolling

protected void _stopPolling ( )
Protected method that actually stops the polling task. Calling this method will stop the poller and fire the poller:stop event.
Returns: void

destructor

protected void destructor ( )
Deconstruction of the component. Stops polling and removes event internal listeners.
Returns: void

initializer

protected void initializer ( config )
Construction of the component linking up and publishing event during initialization.
Parameters:
config <Object> Configuration Ojbect
Returns: void

pause

void pause ( duration )
Pauses the polling task for a duration. This method first calls stop, which will fire the poller:stop event; which will also clear out a waiting pause to resume.
Parameters:
duration <Number> milliseconds until resuming
Returns: void
Chainable: This method is chainable.

sendRequest

void sendRequest ( )
Sends the XHR request to the server at the given URL (resource). This is method is call at the set interval while polling. Calling this method will fire the poller:request event.
Returns: void
Chainable: This method is chainable.

start

void start ( )
Starts the polling task, the poller:start event is fired as a result of calling this method. A request will be sent to the server right at the time of calling this method; continued by sending subsequent requests at the set interval. If the pause method has been called, calling start will clear the pause.
Returns: void
Chainable: This method is chainable.

stop

void stop ( )
Stops the polling task, the poller:stop event is fired. If the paused method has been called, calling start will clear the pause.
Returns: void
Chainable: This method is chainable.

Events

headersChange

headersChange ( event )
Fires when the value for the configuration attribute 'headers' is changed. You can listen for the event using the on method if you wish to be notified before the attribute's value has changed, or using the after method if you wish to be notified after the attribute's value has changed.
Parameters:
event <Event.Facade> An Event Facade object with the following attribute specific properties added:
prevVal
The value of the attribute, prior to it being set
newVal
The value the attribute is to be set to
attrName
The name of the attribute being set
subAttrName
If setting a property within the attribute's value, the name of the sub-attribute property being set

intervalChange

intervalChange ( event )
Fires when the value for the configuration attribute 'interval' is changed. You can listen for the event using the on method if you wish to be notified before the attribute's value has changed, or using the after method if you wish to be notified after the attribute's value has changed.
Parameters:
event <Event.Facade> An Event Facade object with the following attribute specific properties added:
prevVal
The value of the attribute, prior to it being set
newVal
The value the attribute is to be set to
attrName
The name of the attribute being set
subAttrName
If setting a property within the attribute's value, the name of the sub-attribute property being set

modified

modified ( e , txId , r , args )
Signals that the resource the component is pulling the server for has been modified. This is the interesting event for the client ot subscribe to. The subscriber could, for example, update the UI in response to this event, poller:modified.
Parameters:
e <Event.Facade> Event Facade
txId <Number> Y.io Transaction ID
r <Object> Y.io Response Object
args <MIXED> Arguments passed to response handler

pauseInactiveChange

pauseInactiveChange ( event )
Fires when the value for the configuration attribute 'pauseInactive' is changed. You can listen for the event using the on method if you wish to be notified before the attribute's value has changed, or using the after method if you wish to be notified after the attribute's value has changed.
Parameters:
event <Event.Facade> An Event Facade object with the following attribute specific properties added:
prevVal
The value of the attribute, prior to it being set
newVal
The value the attribute is to be set to
attrName
The name of the attribute being set
subAttrName
If setting a property within the attribute's value, the name of the sub-attribute property being set

pollingChange

pollingChange ( event )
Fires when the value for the configuration attribute 'polling' is changed. You can listen for the event using the on method if you wish to be notified before the attribute's value has changed, or using the after method if you wish to be notified after the attribute's value has changed.
Parameters:
event <Event.Facade> An Event Facade object with the following attribute specific properties added:
prevVal
The value of the attribute, prior to it being set
newVal
The value the attribute is to be set to
attrName
The name of the attribute being set
subAttrName
If setting a property within the attribute's value, the name of the sub-attribute property being set

queryParamsChange

queryParamsChange ( event )
Fires when the value for the configuration attribute 'queryParams' is changed. You can listen for the event using the on method if you wish to be notified before the attribute's value has changed, or using the after method if you wish to be notified after the attribute's value has changed.
Parameters:
event <Event.Facade> An Event Facade object with the following attribute specific properties added:
prevVal
The value of the attribute, prior to it being set
newVal
The value the attribute is to be set to
attrName
The name of the attribute being set
subAttrName
If setting a property within the attribute's value, the name of the sub-attribute property being set

request

request ( e , tx )
Signals that the component has sent a XHR request to the Server. The request object is passed to subscribers of the event, poller:request.
Parameters:
e <Event.Facade> Event Facade
tx <Object> Y.io Request Object

response

response ( e , txId , r , args )
Signals that the component has received a response (io:complete) for the server, poller:response.
Parameters:
e <Event.Facade> Event Facade
txId <Number> Y.io Transaction ID
r <Object> Y.io Response Object
args <MIXED> Arguments passed to response handler

start

start ( e )
Signals that polling has started, poller:start.
Parameters:
e <Event.Facade> Event Facade

stop

stop ( e )
Signals that polling has stopped, poller:stop.
Parameters:
e <Event.Facade> Event Facade

timeoutChange

timeoutChange ( event )
Fires when the value for the configuration attribute 'timeout' is changed. You can listen for the event using the on method if you wish to be notified before the attribute's value has changed, or using the after method if you wish to be notified after the attribute's value has changed.
Parameters:
event <Event.Facade> An Event Facade object with the following attribute specific properties added:
prevVal
The value of the attribute, prior to it being set
newVal
The value the attribute is to be set to
attrName
The name of the attribute being set
subAttrName
If setting a property within the attribute's value, the name of the sub-attribute property being set

urlChange

urlChange ( event )
Fires when the value for the configuration attribute 'url' is changed. You can listen for the event using the on method if you wish to be notified before the attribute's value has changed, or using the after method if you wish to be notified after the attribute's value has changed.
Parameters:
event <Event.Facade> An Event Facade object with the following attribute specific properties added:
prevVal
The value of the attribute, prior to it being set
newVal
The value the attribute is to be set to
attrName
The name of the attribute being set
subAttrName
If setting a property within the attribute's value, the name of the sub-attribute property being set

Events inherited from Base:

Configuration Attributes

headers - Object

An Object containing the key : value pairs for any HTTP headers to be send with requests.
Default Value: null

interval - Number

The time in milliseconds for which the component should send a request to the server.
Default Value: 10000

pauseInactive - Boolean

Choice for the polling to be paused if the browser window loses focus, becoming an inactive window.
Default Value: false

polling - readonly Boolean

A read-only attribute the client can check to see if the component is activly polling the server.
Default Value: false

queryParams - String

A set of name=value pairs to be appened to the URL requests will be sent to.
Default Value: null

timeout - Number

The time in milliseconds which the XHR request should abort if no response is received.
Default Value: 5000

url - String

The URL of the resource which the component will check for modifications.
Default Value: null

Configuration attributes inherited from Base:


Copyright © 2009 Eric Ferraiuolo. All rights reserved. YUI is a trademark of Yahoo! Inc.