Skip to content

Commit

Permalink
Automatically reset ratelimiter on 429s
Browse files Browse the repository at this point in the history
Added regex parsing in Items to get missing stats
Added effect replacement for spell tooltips
  • Loading branch information
robrua committed Mar 19, 2015
1 parent 7eac2ff commit 793c36c
Show file tree
Hide file tree
Showing 12 changed files with 278 additions and 23 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Standard Java
<dependency>
<groupId>com.robrua</groupId>
<artifactId>orianna</artifactId>
<version>2.1.2</version>
<version>2.1.3</version>
</dependency>
```

Expand All @@ -45,7 +45,7 @@ Android
<dependency>
<groupId>com.robrua</groupId>
<artifactId>orianna-android</artifactId>
<version>2.1.2</version>
<version>2.1.3</version>
</dependency>
```

Expand All @@ -58,7 +58,7 @@ repositories {
}
dependencies {
compile 'com.robrua:orianna:2.1.2'
compile 'com.robrua:orianna:2.1.3'
}
```

Expand All @@ -69,7 +69,7 @@ repositories {
}
dependencies {
compile 'com.robrua:orianna-android:2.1.2'
compile 'com.robrua:orianna-android:2.1.3'
}
```

Expand Down
2 changes: 1 addition & 1 deletion android-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>orianna-android</artifactId>
<version>2.1.2</version>
<version>2.1.3</version>
<packaging>jar</packaging>

<parent>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>orianna</artifactId>
<version>2.1.2</version>
<version>2.1.3</version>
<packaging>jar</packaging>

<parent>
Expand Down
12 changes: 10 additions & 2 deletions src/com/robrua/orianna/api/dto/BaseRiotAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ static String get(final URI uri, final boolean staticServer) {
rateLimiter.waitForCall();
}

final boolean registered = false;

// Send request to Riot and register call
try {
final HttpGet get = new HttpGet(uri);
Expand All @@ -204,7 +206,13 @@ static String get(final URI uri, final boolean staticServer) {
consume(entity);

// Handle API errors
if(response.getStatusLine().getStatusCode() != 200) {
if(response.getStatusLine().getStatusCode() == 429) {
// Force rate limiter to wait after a 429
final int retryAfter = Integer.parseInt(response.getFirstHeader("Retry-After").getValue()) + 1;
rateLimiter.resetIn(retryAfter * 1000L);
throw new APIException(uri.toString(), 429);
}
else if(response.getStatusLine().getStatusCode() != 200) {
throw new APIException(uri.toString(), response.getStatusLine().getStatusCode());
}

Expand All @@ -219,7 +227,7 @@ static String get(final URI uri, final boolean staticServer) {
throw new OriannaException("Request to Riot server failed! Report this to the Orianna team.");
}
finally {
if(!staticServer) {
if(!staticServer && !registered) {
rateLimiter.registerCall();
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/com/robrua/orianna/store/FileSystemDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ public static class FSIterator<T extends OriannaObject<?>> implements Iterator<T
private final Iterator<File> files;

/**
* @param folder root DB folder for type
* @param clazz the type
* @param folder
* root DB folder for type
* @param clazz
* the type
*/
private FSIterator(final File folder, final Class<T> clazz) {
files = Arrays.asList(folder.listFiles()).iterator();
Expand Down
7 changes: 7 additions & 0 deletions src/com/robrua/orianna/type/api/MultiRateLimiter.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ public synchronized void registerCall() {
}
}

@Override
public synchronized void resetIn(final long millis) {
for(final RateLimiter limit : limits) {
limit.resetIn(millis);
}
}

@Override
public synchronized void waitForCall() {
for(final RateLimiter limit : limits) {
Expand Down
8 changes: 8 additions & 0 deletions src/com/robrua/orianna/type/api/RateLimiter.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ public interface RateLimiter {
*/
public void registerCall();

/**
* Cancels current operation and resets the rate limiter
*
* @param millis
* the number of milliseconds to wait before resetting
*/
public void resetIn(long millis);

/**
* Blocks until a call is available
*/
Expand Down
23 changes: 16 additions & 7 deletions src/com/robrua/orianna/type/api/SingleRateLimiter.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,16 @@ private class ResetTask extends TimerTask {
@Override
public void run() {
semaphore.drainPermits();
resetRunning = false;
resetter = null;
semaphore.release(limit - current);
}
}

private volatile int current;
private final int limit;
private final long millisPerEpoch;
private volatile boolean resetRunning;
private volatile ResetTask resetter;
private final Semaphore semaphore;

private final Timer timer;

/**
Expand All @@ -39,7 +38,7 @@ public void run() {
public SingleRateLimiter(final int callsPerEpoch, final int secondsPerEpoch) {
millisPerEpoch = secondsPerEpoch * 1000L;
limit = callsPerEpoch;
semaphore = new Semaphore(limit);
semaphore = new Semaphore(limit, true);
timer = new Timer(true);
current = 0;
}
Expand All @@ -54,14 +53,24 @@ public SingleRateLimiter(final RateLimit limit) {

@Override
public synchronized void registerCall() {
if(!resetRunning) {
timer.schedule(new ResetTask(), millisPerEpoch);
resetRunning = true;
if(resetter == null) {
resetter = new ResetTask();
timer.schedule(resetter, millisPerEpoch);
}

current--;
}

@Override
public synchronized void resetIn(final long millis) {
if(resetter != null) {
resetter.cancel();
}
resetter = new ResetTask();
semaphore.drainPermits();
timer.schedule(resetter, millis);
}

@Override
public void waitForCall() {
semaphore.acquireUninterruptibly();
Expand Down
55 changes: 55 additions & 0 deletions src/com/robrua/orianna/type/core/staticdata/BasicDataStats.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

public class BasicDataStats extends OriannaObject<com.robrua.orianna.type.dto.staticdata.BasicDataStats> {
private static final long serialVersionUID = 7920872026162580279L;
double percentCooldownReduction, flatArmorPenetration, percentArmorPenetration, flatMagicPenetration, percentMagicPenetration, goldPer10;

/**
* @param data
Expand All @@ -22,6 +23,15 @@ public double getFlatArmorMod() {
return super.getDouble(data.getFlatArmorMod());
}

/**
* Flat Armor Penetration
*
* @return flat armor penetration
*/
public double getFlatArmorPenetration() {
return flatArmorPenetration;
}

/**
* Flat attack speed mod
*
Expand Down Expand Up @@ -112,6 +122,15 @@ public double getFlatMagicDamageMod() {
return super.getDouble(data.getFlatMagicDamageMod());
}

/**
* Flat Magic Penetration
*
* @return flat magic penetration
*/
public double getFlatMagicPenetration() {
return flatMagicPenetration;
}

/**
* Flat movement speed mod
*
Expand Down Expand Up @@ -157,6 +176,15 @@ public double getFlatSpellBlockMod() {
return super.getDouble(data.getFlatSpellBlockMod());
}

/**
* Gold Per 10
*
* @return gold per 10
*/
public double getGoldPer10() {
return goldPer10;
}

/**
* Percent armor mod
*
Expand All @@ -166,6 +194,15 @@ public double getPercentArmorMod() {
return super.getDouble(data.getPercentArmorMod());
}

/**
* Percent Armor Penetration
*
* @return percent armor penetration
*/
public double getPercentArmorPenetration() {
return percentArmorPenetration;
}

/**
* Percent attack speed mod
*
Expand All @@ -184,6 +221,15 @@ public double getPercentBlockMod() {
return super.getDouble(data.getPercentBlockMod());
}

/**
* Cooldown Reduction
*
* @return cooldown reduction
*/
public double getPercentCooldownReduction() {
return percentCooldownReduction;
}

/**
* Percent crit chance mod
*
Expand Down Expand Up @@ -256,6 +302,15 @@ public double getPercentMagicDamageMod() {
return super.getDouble(data.getPercentMagicDamageMod());
}

/**
* Percent Magic Penetration
*
* @return percent magic penetration
*/
public double getPercentMagicPenetration() {
return percentMagicPenetration;
}

/**
* Percent movement speed mod
*
Expand Down
Loading

0 comments on commit 793c36c

Please sign in to comment.