add javadoc for rate-limit functionality
refactor rate-limit code to reduce code duplication
add rate limit sample code.