When the browser becomes over saturated due to the rate of updates it receives, two problems can appear which are detrimental to the use of the browser as a real-time trading platform. These are:
Attributes | Name and Description |
---|---|
|
caplin.core.scheduler.ThreadScheduler( fSetTimeout, fClearTimeout)
|
Attributes | Name and Description |
---|---|
|
UI_EVENT_YIELD_TIME
The time soon after which the thread scheduler will yield control so that any pending UI events can be processed. |
Attributes | Name and Description |
---|---|
|
void
addThreadQueueListener(caplin.core.scheduler.ThreadQueueListener oListener)
Add a listener to be informed of updates to the current number of pending and due threads awaiting processing |
|
void
clearInterval(int nIntervalId)
A replacement for the native |
|
void
clearTimeout(int nTimeoutId)
A replacement for the native |
|
void
preventTimerExecutionAfterThread(String sThreadId, int nTimeout)
Prevent execution of all timeouts and intervals, for the specified period of time, after a thread with the given id is executed. |
|
void
preventTimerExecutionFor(int nTimeout)
Prevent execution of all timeouts and intervals for the specified period of time. |
|
int
setInterval(Function fCallback, int nInterval, String sThreadId)
A replacement for the native |
|
void
setThreadPriorities(Array pThreadIds)
Define the priorities with which threads will be scheduled. |
|
int
setTimeout(Function fCallback, int nTimeout, String sThreadId)
A replacement for the native |
►
caplin.core.scheduler.ThreadScheduler( fSetTimeout, fClearTimeout)
fSetTimeout | ||
fClearTimeout |
►
UI_EVENT_YIELD_TIME
The time soon after which the thread scheduler will yield control so that any pending UI events can be processed.
►
void
addThreadQueueListener(caplin.core.scheduler.ThreadQueueListener oListener)
Add a listener to be informed of updates to the current number of pending and due threads awaiting processing
caplin.core.scheduler.ThreadQueueListener | oListener | The object that will receive the call-back events. |
►
void
clearInterval(int nIntervalId)
A replacement for the native window.clearInterval()
method.
This method replaces, and has the same API as window.clearInterval()
— i.e. invoking window.clearInterval()
actually causes this method to be invoked.
int | nIntervalId | The id of the previously registered interval you wish to cancel. |
►
void
clearTimeout(int nTimeoutId)
A replacement for the native window.clearTimeout()
method.
This method replaces, and has the same API as window.clearTimeout()
— i.e. invoking window.clearTimeout()
actually causes this method to be invoked.
int | nTimeoutId | The id of the previously registered timeout you wish to cancel. |
►
void
preventTimerExecutionAfterThread(String sThreadId, int nTimeout)
Prevent execution of all timeouts and intervals, for the specified period of time, after a thread with the given id is executed.
The primary purpose of this method (and #preventTimerExecutionFor) are to ensure that JavaScript execution pauses for enough time to allow the browser to update the screen. Typically, this will only need to occur after the execution of any display updating threads, for example 'display throttle' and 'SL4B update batcher'.
By default, ThreadScheduler
does not control the execution of UI events, and so
is unable to ensure screen refreshes occur if any long running UI events are running at the same
time. It is therefore the responsibility of application developers to ensure that any long running
UI events defer their operation using window.setTimeout()
, also bringing these threads
under the control of ThreadScheduler
.
String | sThreadId | The name of the thread after which timer execution should be prevented. |
int | nTimeout | The number of milliseconds timer execution will be prevented for. |
►
void
preventTimerExecutionFor(int nTimeout)
Prevent execution of all timeouts and intervals for the specified period of time.
int | nTimeout | The number of milliseconds for which timer execution will be prevented. |
►
int
setInterval(Function fCallback, int nInterval, String sThreadId)
A replacement for the native window.setInterval()
method.
This method has the same API as window.setInterval()
, except that it
supports an optional sThreadId
parameter that helps developers visualise
thread usage, and is a pre-requisite for the use of the #preventTimerExecutionAfterThread
method. You do not need to call caplin.core.scheduler.ThreadScheduler.setInterval()
directly
as it also replaces the native window.setInterval()
method.
Function | fCallback | The function that will be invoked each time the the interval elapses. |
int | nInterval | The number of milliseconds between each invocation of the call-back. |
String | sThreadId | A logical name for the thread that is being invoked (Optional). |
►
void
setThreadPriorities(Array pThreadIds)
Define the priorities with which threads will be scheduled.
The following example prioritises two named threads, while another thread is explicitly de-prioritised:
caplin.core.scheduler.ThreadScheduler.setThreadPriorities([ "highest-priority-thread", "high-priority-thread", "*", "lowest-priority-thread"]);
Array | pThreadIds | A list of thread identifiers, in priority order — a wildcard thread identifier (i.e. '*') can be used to explicitly de-prioritize any threads specified after that point. |
►
int
setTimeout(Function fCallback, int nTimeout, String sThreadId)
A replacement for the native window.setTimeout()
method.
This method has the same API as window.setTimeout()
, except that it
supports an optional sThreadId
parameter that helps developers visualise
thread usage, and is a pre-requisite for the use of the #preventTimerExecutionAfterThread
method. You do not need to call caplin.core.scheduler.ThreadScheduler.setTimeout()
directly
as it also replaces the native window.setTimeout()
method.
Function | fCallback | The function that will be invoked once the timeout period has elapsed. |
int | nTimeout | The number of milliseconds until the call-back will be invoked. |
String | sThreadId | A logical name for the thread that is being invoked (Optional). |