Interface OnlineCalculatable
public interface OnlineCalculatable
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
OnlineCalculatable.Marker
If passed as value it will cause marker to be drawn at that place (currently works only forLayer1ApiUserMessageModifyIndicator.GraphType.PRIMARY
).static class
OnlineCalculatable.ValueBundle
-
Method Summary
Modifier and Type Method Description default boolean
allowPartialUpdates(java.lang.String indicatorName, java.lang.String alias)
void
calculateValuesInRange(java.lang.String indicatorName, java.lang.String indicatorAlias, long t0, long intervalWidth, int intervalsNumber, CalculatedResultListener listener)
1st request type: Should calculate left to right values in given time points t0; t0 + intervalWidth; t0 + 2 * intervalWidth ...OnlineValueCalculatorAdapter
createOnlineValueCalculator(java.lang.String indicatorName, java.lang.String indicatorAlias, long time, java.util.function.Consumer<java.lang.Object> listener, InvalidateInterface invalidateInterface)
2nd request type:default boolean
shouldRepeatCalculateValuesInRange(java.lang.String indicatorName, java.lang.String indicatorAlias, long intervalWidth, long timePassed)
Experimental! Note that if you use this functionality, you should always useOnlineValueCalculatorAdapter.onTimeSourceProvided(LongSupplier)
as your time source!
-
Method Details
-
calculateValuesInRange
void calculateValuesInRange(java.lang.String indicatorName, java.lang.String indicatorAlias, long t0, long intervalWidth, int intervalsNumber, CalculatedResultListener listener)1st request type: Should calculate left to right values in given time points t0; t0 + intervalWidth; t0 + 2 * intervalWidth ... t0 + (intervalsNumber - 1) * intervalWidh)- Parameters:
indicatorName
- name of indicatorindicatorAlias
- alias of this indicatort0
- time of 1st value (in ns)intervalWidth
- width of one calculated interval (in ns)intervalsNumber
- number of values to calculate, >= 0listener
-
-
createOnlineValueCalculator
OnlineValueCalculatorAdapter createOnlineValueCalculator(java.lang.String indicatorName, java.lang.String indicatorAlias, long time, java.util.function.Consumer<java.lang.Object> listener, InvalidateInterface invalidateInterface)2nd request type:- Parameters:
indicatorName
- name of indicatorindicatorAlias
- alias of this indicatortime
- starting with this time values are computed onlinelistener
- can be used in following ways:
a) you can return generated events via listener (seeCalculatedResultListener.provideResponse(Object)
for supported object types
b) you can useIndicatorFullValues
to fully update historical values of your indicatorinvalidateInterface
- can be used to invalidate indicator- Returns:
- value calculator for this strategy
-
shouldRepeatCalculateValuesInRange
default boolean shouldRepeatCalculateValuesInRange(java.lang.String indicatorName, java.lang.String indicatorAlias, long intervalWidth, long timePassed)Experimental! Note that if you use this functionality, you should always useOnlineValueCalculatorAdapter.onTimeSourceProvided(LongSupplier)
as your time source!
By default Bookmap will repeat
calculateValuesInRange(String, String, long, long, int, CalculatedResultListener)
request if by the time response is handled more than one intervalWidth passed. However sometimes (if calculateValuesInRange is relatively slow and/or user is zoomed in closely, so chart moves fast) it can be repeated too many times (or even continiously, as long as chart moves). While it can be acceptable in some cases, you can improve the performance by telling bookmap to switch toOnlineValueCalculatorAdapter
earlier.You can return false when you believe there are not too many intervals and not too much time passed for your strategy to effectively process all data in that time interval. This will be called by Bookmap only if all data in requested range is ready (Bookmap will drop data for for which too many seconds and too many intervals passed)
It's important that this method doesn't block for too long.- Parameters:
indicatorName
- name of indicatorindicatorAlias
- alias of this indicatorintervalWidth
- width of one calculated interval (in ns).timePassed
- time passed since the end ofcalculateValuesInRange(String, String, long, long, int, CalculatedResultListener)
range- Returns:
- false to switch to
OnlineValueCalculatorAdapter
, true to usecalculateValuesInRange(String, String, long, long, int, CalculatedResultListener)
again.
-
allowPartialUpdates
default boolean allowPartialUpdates(java.lang.String indicatorName, java.lang.String alias)- Parameters:
indicatorName
- name of indicatoralias
- alias of this indicator Override you want your indicator to receive only full chart range requests (i.e. you don't want to receive 0-1000 pixels request, and then 1000-1020 request to catch up with chart)- Returns:
- true if you allow partial requests (default implementation), false otherwise
-