Skip to content

Commit

Permalink
Add concurrency token request/release operation in TokenService
Browse files Browse the repository at this point in the history
Signed-off-by: yunfeiyanggzq <[email protected]>
  • Loading branch information
yunfeiyanggzq authored and sczyh30 committed Sep 16, 2020
1 parent 75f1388 commit 473cc84
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,15 @@ public TokenResult requestParamToken(Long flowId, int acquireCount, Collection<O
}
}

@Override
public TokenResult requestConcurrentToken(String clientAddress, Long ruleId, int acquireCount) {
return null;
}

@Override
public void releaseConcurrentToken(Long tokenId) {
}

private void logForResult(TokenResult result) {
switch (result.getStatus()) {
case TokenResultStatus.NO_RULE_EXISTS:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,13 @@ public TokenResult requestParamToken(Long ruleId, int acquireCount, Collection<O
}
return new TokenResult(TokenResultStatus.FAIL);
}

@Override
public TokenResult requestConcurrentToken(String clientAddress, Long ruleId, int acquireCount) {
return null;
}

@Override
public void releaseConcurrentToken(Long tokenId) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,25 @@ public class TokenResult {
private int remaining;
private int waitInMs;

private long tokenId;

private Map<String, String> attachments;

public TokenResult() {}
public TokenResult() {
}

public TokenResult(Integer status) {
this.status = status;
}

public long getTokenId() {
return tokenId;
}

public void setTokenId(long tokenId) {
this.tokenId = tokenId;
}

public Integer getStatus() {
return status;
}
Expand Down Expand Up @@ -77,10 +88,11 @@ public TokenResult setAttachments(Map<String, String> attachments) {
@Override
public String toString() {
return "TokenResult{" +
"status=" + status +
", remaining=" + remaining +
", waitInMs=" + waitInMs +
", attachments=" + attachments +
'}';
"status=" + status +
", remaining=" + remaining +
", waitInMs=" + waitInMs +
", attachments=" + attachments +
", tokenId=" + tokenId +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ public final class TokenResultStatus {
* Token acquire failed (strategy not available).
*/
public static final int NOT_AVAILABLE = 5;
/**
* Token is successfully released.
*/
public static final int RELEASE_OK = 6;
/**
* Token already is released before the request arrives.
*/
public static final int ALREADY_RELEASE=7;

private TokenResultStatus() {}
private TokenResultStatus() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,20 @@ public interface TokenService {
* @return result of the token request
*/
TokenResult requestParamToken(Long ruleId, int acquireCount, Collection<Object> params);

/**
* Request acquire concurrent tokens from remote token server.
*
* @param clientAddress the address of the request belong.
* @param ruleId ruleId the unique rule ID
* @param acquireCount token count to acquire
* @return result of the token request
*/
TokenResult requestConcurrentToken(String clientAddress,Long ruleId,int acquireCount);
/**
* Request release concurrent tokens from remote token server asynchronously.
*
* @param tokenId the unique token ID
*/
void releaseConcurrentToken(Long tokenId);
}

0 comments on commit 473cc84

Please sign in to comment.