Parses the "rate" section of the query string and returns an instance of the RateOptions class that contains the values found. The format of the rate specification is rate[{counter[,#[,#]]}]. @param rate If true, then the query is set as a rate query and the rate specification will be parsed. I
(final boolean rate,
final String spec)
| 756 | * @since 2.0 |
| 757 | */ |
| 758 | static final public RateOptions parseRateOptions(final boolean rate, |
| 759 | final String spec) { |
| 760 | if (!rate || spec.length() == 4) { |
| 761 | return new RateOptions(false, Long.MAX_VALUE, |
| 762 | RateOptions.DEFAULT_RESET_VALUE); |
| 763 | } |
| 764 | |
| 765 | if (spec.length() < 6) { |
| 766 | throw new BadRequestException("Invalid rate options specification: " |
| 767 | + spec); |
| 768 | } |
| 769 | |
| 770 | String[] parts = Tags |
| 771 | .splitString(spec.substring(5, spec.length() - 1), ','); |
| 772 | if (parts.length < 1 || parts.length > 3) { |
| 773 | throw new BadRequestException( |
| 774 | "Incorrect number of values in rate options specification, must be " + |
| 775 | "counter[,counter max value,reset value], recieved: " |
| 776 | + parts.length + " parts"); |
| 777 | } |
| 778 | |
| 779 | final boolean counter = parts[0].endsWith("counter"); |
| 780 | try { |
| 781 | final long max = (parts.length >= 2 && parts[1].length() > 0 ? Long |
| 782 | .parseLong(parts[1]) : Long.MAX_VALUE); |
| 783 | try { |
| 784 | final long reset = (parts.length >= 3 && parts[2].length() > 0 ? Long |
| 785 | .parseLong(parts[2]) : RateOptions.DEFAULT_RESET_VALUE); |
| 786 | final boolean drop_counter = parts[0].equals("dropcounter"); |
| 787 | return new RateOptions(counter, max, reset, drop_counter); |
| 788 | } catch (NumberFormatException e) { |
| 789 | throw new BadRequestException( |
| 790 | "Reset value of counter was not a number, received '" + parts[2] |
| 791 | + "'"); |
| 792 | } |
| 793 | } catch (NumberFormatException e) { |
| 794 | throw new BadRequestException( |
| 795 | "Max value of counter was not a number, received '" + parts[1] + "'"); |
| 796 | } |
| 797 | } |
| 798 | |
| 799 | /** |
| 800 | * Parses a last point query from the URI string |
no test coverage detected