public void setDefaultCapacity(long capacity) {
this.defaultCapacity = capacity;
}
protected boolean processRequest(TokenRequest request) {
IBWControllable bc = request.initialBC;
while (bc != null) {
BWContext context = contextMap.get(bc);
if (context == null) {
rollbackRequest(request);
return false;
}
synchronized (context) {
if (context.bwConfig != null) {
boolean result;
if (request.type == TokenRequestType.BLOCKING) {
result = processBlockingRequest(request, context);
} else if (request.type == TokenRequestType.NONBLOCKING) {
result = processNonblockingRequest(request, context);
} else {
result = processBestEffortRequest(request, context);
}
if (!result) {
// for non-blocking mode, the callback is
// recorded and will be rolled back when being reset,
// so we don't need to do rollback here.
if (request.type != TokenRequestType.NONBLOCKING) {
rollbackRequest(request);
}
return false;
}
}
TokenRequestContext requestContext = new TokenRequestContext();
requestContext.acquiredToken = request.requestToken;
requestContext.bc = bc;
request.acquiredStack.push(requestContext);
}
bc = bc.getParentBWControllable();
}
// for best effort request, we need to rollback over-charged tokens
if (request.type == TokenRequestType.BEST_EFFORT) {
rollbackRequest(request);
}