Rated Executor

A library of rate limited executors. The executors in this library will execute tasks no faster than some rate. It also exposes many of the generic components to used to construct these executors.

License

License

GroupId

GroupId

com.mattunderscore
ArtifactId

ArtifactId

rated-executor
Last Version

Last Version

0.1.1
Release Date

Release Date

Type

Type

jar
Description

Description

Rated Executor
A library of rate limited executors. The executors in this library will execute tasks no faster than some rate. It also exposes many of the generic components to used to construct these executors.
Source Code Management

Source Code Management

https://github.com/mattunderscorechampion/rated-executor

Download rated-executor

How to add to project

<!-- https://jarcasting.com/artifacts/com.mattunderscore/rated-executor/ -->
<dependency>
    <groupId>com.mattunderscore</groupId>
    <artifactId>rated-executor</artifactId>
    <version>0.1.1</version>
</dependency>
// https://jarcasting.com/artifacts/com.mattunderscore/rated-executor/
implementation 'com.mattunderscore:rated-executor:0.1.1'
// https://jarcasting.com/artifacts/com.mattunderscore/rated-executor/
implementation ("com.mattunderscore:rated-executor:0.1.1")
'com.mattunderscore:rated-executor:jar:0.1.1'
<dependency org="com.mattunderscore" name="rated-executor" rev="0.1.1">
  <artifact name="rated-executor" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.mattunderscore', module='rated-executor', version='0.1.1')
)
libraryDependencies += "com.mattunderscore" % "rated-executor" % "0.1.1"
[com.mattunderscore/rated-executor "0.1.1"]

Dependencies

compile (1)

Group / Artifact Type Version
net.jcip : jcip-annotations jar 1.0

test (2)

Group / Artifact Type Version
junit : junit jar 4.11
org.mockito : mockito-all jar 1.9.5

Project Modules

There are no modules declared in this project.

RatedExecutor

Idea

A colleague was working on a demo that polled the Twitter API. He had to solve the problem where he needed to ensure that the poll did not exceed the rate limits imposed on polling. This problem can easily be generalised into a generic problem, accessing a resource at no greater than a fixed rate. I didn't know of a generalised solution to the problem so I decided to implement one. A Runnable task executor that executes tasks no faster than a fixed rate but as soon as it can otherwise.

Usage

The RatedExecutor supports both Runnable and Callable tasks. Tasks can be submitted to be executed once, a fixed number of repetitions or an unbounded number of times. Callable tasks cannot be scheduled for an unbounded number of repetitions as this presents difficulty in storing the results.

Futures are returned that allow the result of the execution to be retrieved. The futures for tasks scheduled for a fixed number of repetitions allow the result of each repetition to be accessed.

The execute and submit methods schedule the task to be executed once. The difference between them is that execute does not return a future. The schedule methods can be used to repeatedly execute the same task. The schedule method is overloaded so that it can take an optional integer parameter that specifies the number of times to execute the task.

RatedExecutors can be constructed by using the static methods in the RatedExecutors class.

Testing

Automated JUnit tests are included and have reasonable coverage. These tests tend towards integration rather than unit tests. They are subject to intermittent failure as a result of thread scheduling. They have assertions on the promptness and timing of the execution of tasks which make them unsuitable for measuring in terms of success and failure. I will refactor these to be assessed statistically.

Continuous Integration

This project uses Travis CI, a free hosted CI integrated with GitHub. You can see the results for this project here.

Versions

Version
0.1.1
0.1.0
0.0.1