root / main / java / net / elasticgrid / rackspace / cloudservers / Limits.java @ f8be9cce
History | View | Annotate | Download (3.7 kB)
1 |
/**
|
---|---|
2 |
* Licensed to the Apache Software Foundation (ASF) under one
|
3 |
* or more contributor license agreements. See the NOTICE file
|
4 |
* distributed with this work for additional information
|
5 |
* regarding copyright ownership. The ASF licenses this file
|
6 |
* to you under the Apache License, Version 2.0 (the
|
7 |
* "License"); you may not use this file except in compliance
|
8 |
* with the License. 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,
|
13 |
* software distributed under the License is distributed on an
|
14 |
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
15 |
* KIND, either express or implied. See the License for the
|
16 |
* specific language governing permissions and limitations
|
17 |
* under the License.
|
18 |
*/
|
19 |
package net.elasticgrid.rackspace.cloudservers; |
20 |
|
21 |
import java.io.*; |
22 |
import java.util.*; |
23 |
|
24 |
/**
|
25 |
* Rackspace API limits.
|
26 |
* @author Jerome Bernard
|
27 |
*/
|
28 |
public class Limits implements Serializable { |
29 |
private final List<RateLimit> rateLimits; |
30 |
private final List<AbsoluteLimit> absoluteLimits; |
31 |
|
32 |
public Limits(List<RateLimit> rateLimits, List<AbsoluteLimit> absoluteLimits) { |
33 |
this.rateLimits = Collections.unmodifiableList(rateLimits); |
34 |
this.absoluteLimits = Collections.unmodifiableList(absoluteLimits); |
35 |
} |
36 |
|
37 |
public List<RateLimit> getRateLimits() { |
38 |
return rateLimits;
|
39 |
} |
40 |
|
41 |
public List<AbsoluteLimit> getAbsoluteLimits() { |
42 |
return absoluteLimits;
|
43 |
} |
44 |
|
45 |
} |
46 |
|
47 |
class RateLimit implements Serializable { |
48 |
private final HTTPVerb verb; |
49 |
private final String URI; |
50 |
private final String regex; |
51 |
private final int value; |
52 |
private final int remaining; |
53 |
private final RateLimit.Unit unit; |
54 |
private final long resetTime; |
55 |
|
56 |
RateLimit(HTTPVerb verb, String URI, String regex, int value, int remaining, RateLimit.Unit unit, long resetTime) { |
57 |
this.verb = verb;
|
58 |
this.URI = URI; |
59 |
this.regex = regex;
|
60 |
this.value = value;
|
61 |
this.remaining = remaining;
|
62 |
this.unit = unit;
|
63 |
this.resetTime = resetTime;
|
64 |
} |
65 |
|
66 |
public HTTPVerb getVerb() {
|
67 |
return verb;
|
68 |
} |
69 |
|
70 |
public String getURI() { |
71 |
return URI; |
72 |
} |
73 |
|
74 |
public String getRegex() { |
75 |
return regex;
|
76 |
} |
77 |
|
78 |
public int getValue() { |
79 |
return value;
|
80 |
} |
81 |
|
82 |
public int getRemaining() { |
83 |
return remaining;
|
84 |
} |
85 |
|
86 |
public RateLimit.Unit getUnit() {
|
87 |
return unit;
|
88 |
} |
89 |
|
90 |
public long getResetTime() { |
91 |
return resetTime;
|
92 |
} |
93 |
|
94 |
@Override
|
95 |
public String toString() { |
96 |
final StringBuilder sb = new StringBuilder(); |
97 |
sb.append("RateLimit");
|
98 |
sb.append("{verb=").append(verb);
|
99 |
sb.append(", URI='").append(URI).append('\''); |
100 |
sb.append(", regex='").append(regex).append('\''); |
101 |
sb.append(", value=").append(value);
|
102 |
sb.append(", remaining=").append(remaining);
|
103 |
sb.append(", unit=").append(unit);
|
104 |
sb.append(", resetTime=").append(resetTime);
|
105 |
sb.append('}');
|
106 |
return sb.toString();
|
107 |
} |
108 |
|
109 |
enum Unit implements Serializable { |
110 |
MINUTE, HOUR, DAY |
111 |
} |
112 |
} |
113 |
|
114 |
class AbsoluteLimit implements Serializable { |
115 |
private final String name; |
116 |
private final int value; |
117 |
|
118 |
public AbsoluteLimit(String name, int value) { |
119 |
this.name = name;
|
120 |
this.value = value;
|
121 |
} |
122 |
|
123 |
public String getName() { |
124 |
return name;
|
125 |
} |
126 |
|
127 |
public int getValue() { |
128 |
return value;
|
129 |
} |
130 |
|
131 |
@Override
|
132 |
public String toString() { |
133 |
final StringBuilder sb = new StringBuilder(); |
134 |
sb.append("AbsoluteLimit");
|
135 |
sb.append("{name='").append(name).append('\''); |
136 |
sb.append(", value=").append(value);
|
137 |
sb.append('}');
|
138 |
return sb.toString();
|
139 |
} |
140 |
} |