Class ExternalApiAccessLimit

java.lang.Object
com.e1c.langtool.external.ExternalApiAccessLimit

public class ExternalApiAccessLimit extends Object
The class allows to describe access limits to the service. Allows to limit API calls and to limit total symbols send to the API. When any of limits exceeded first then thread will sleep until can proceed again. So it is better to set minimal period (duration) for both limits to use the limit smoothly. This class is thread-safe.
  • Constructor Details

    • ExternalApiAccessLimit

      public ExternalApiAccessLimit(Duration accessApiPeriod, int accessApiLimit, Duration symbolPeriod, int symbolLimit)
      Instantiates a new external API access limit.
      Parameters:
      accessApiPeriod - the access API period.
      accessApiLimit - the access API limit of calls during the period.
      symbolPeriod - the symbol limit period.
      symbolLimit - the total symbol length limit during the period
  • Method Details

    • checkOrWaitAccessApiLimits

      public void checkOrWaitAccessApiLimits()
      Check Access API limits or thread will wait when until my proceed.
    • checkOrWaitSymbolLimits

      public void checkOrWaitSymbolLimits(int textLength)
      Check symbol limits or thread will wait until may proceed.
      Parameters:
      textLength - the text length that will be sent to the API call