| 1 | /** |
| 2 | * |
| 3 | * Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com> |
| 4 | * |
| 5 | * ==================================================================== |
| 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | * you may not use this file except in compliance with the License. |
| 8 | * You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, software |
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
| 17 | * ==================================================================== |
| 18 | */ |
| 19 | package org.jclouds.cloudservers.domain; |
| 20 | |
| 21 | import javax.ws.rs.HttpMethod; |
| 22 | |
| 23 | /** |
| 24 | * |
| 25 | * RateLimit. |
| 26 | * <p/> |
| 27 | * we specify rate limits in terms of both a human readable wild-card URI and a machine processable |
| 28 | * regular expression. The regular expression boundary matcher '^' takes affect after the root URI |
| 29 | * path. For example, the regular expression ^/servers would match the bolded portion of the |
| 30 | * following URI: https://servers.api.rackspacecloud.com/v1.0/3542812 /servers . |
| 31 | * <p/> |
| 32 | * Rate limits are applied in order relative to the verb, going from least to most specific. For |
| 33 | * example, although the threshold for POST to /servers is 25 per day, one cannot POST to /servers |
| 34 | * more than 10 times within a single minute because the rate limits for any POST is 10/min. In the |
| 35 | * event you exceed the thresholds established for your identity, a 413 Rate Control HTTP response |
| 36 | * will be returned with a Reply-After header to notify the client when theyagain. |
| 37 | * |
| 38 | * @author Adrian Cole |
| 39 | */ |
| 40 | public class RateLimit { |
| 41 | |
| 42 | private final String uri; |
| 43 | private final String regex; |
| 44 | private final int remaining; |
| 45 | private final long resetTime; |
| 46 | private final RateLimitUnit unit; |
| 47 | private final int value; |
| 48 | private final HttpMethod verb; |
| 49 | |
| 50 | public RateLimit(String uri, String regex, int remaining, long resetTime, RateLimitUnit unit, |
| 51 | int value, HttpMethod verb) { |
| 52 | this.uri = uri; |
| 53 | this.regex = regex; |
| 54 | this.remaining = remaining; |
| 55 | this.resetTime = resetTime; |
| 56 | this.unit = unit; |
| 57 | this.value = value; |
| 58 | this.verb = verb; |
| 59 | } |
| 60 | |
| 61 | public String getUri() { |
| 62 | return uri; |
| 63 | } |
| 64 | |
| 65 | public String getRegex() { |
| 66 | return regex; |
| 67 | } |
| 68 | |
| 69 | public int getRemaining() { |
| 70 | return remaining; |
| 71 | } |
| 72 | |
| 73 | public long getResetTime() { |
| 74 | return resetTime; |
| 75 | } |
| 76 | |
| 77 | public RateLimitUnit getUnit() { |
| 78 | return unit; |
| 79 | } |
| 80 | |
| 81 | public int getValue() { |
| 82 | return value; |
| 83 | } |
| 84 | |
| 85 | public HttpMethod getVerb() { |
| 86 | return verb; |
| 87 | } |
| 88 | |
| 89 | } |