Interface OnlineCalculatable


public interface OnlineCalculatable
Strategy implementing this interfaces should support 2 types of requests. 1. Calculate value for given time points 2. Calculate value on fly when receiving new updates Calculated value can be any object Bottom panel will currently work with Double objects representing current value
  • 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 indicator
      indicatorAlias - alias of this indicator
      t0 - time of 1st value (in ns)
      intervalWidth - width of one calculated interval (in ns)
      intervalsNumber - number of values to calculate, >= 0
      listener -
    • 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 indicator
      indicatorAlias - alias of this indicator
      time - starting with this time values are computed online
      listener - can be used in following ways:
      a) you can return generated events via listener (see CalculatedResultListener.provideResponse(Object) for supported object types
      b) you can use IndicatorFullValues to fully update historical values of your indicator
      invalidateInterface - 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 use OnlineValueCalculatorAdapter.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 to OnlineValueCalculatorAdapter 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 indicator
      indicatorAlias - alias of this indicator
      intervalWidth - width of one calculated interval (in ns).
      timePassed - time passed since the end of calculateValuesInRange(String, String, long, long, int, CalculatedResultListener) range
      Returns:
      false to switch to OnlineValueCalculatorAdapter, true to use calculateValuesInRange(String, String, long, long, int, CalculatedResultListener) again.
    • allowPartialUpdates

      default boolean allowPartialUpdates​(java.lang.String indicatorName, java.lang.String alias)
      Parameters:
      indicatorName - name of indicator
      alias - 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