Signed-off-by: yunfeiyanggzq <yunfeiyang@buaa.edu.cn>master
@@ -182,6 +182,15 @@ public class DefaultClusterTokenClient implements ClusterTokenClient { | |||
} | |||
} | |||
@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: | |||
@@ -58,4 +58,13 @@ public class DefaultEmbeddedTokenServer implements EmbeddedClusterTokenServer { | |||
} | |||
return new TokenResult(TokenResultStatus.FAIL); | |||
} | |||
@Override | |||
public TokenResult requestConcurrentToken(String clientAddress, Long ruleId, int acquireCount) { | |||
return null; | |||
} | |||
@Override | |||
public void releaseConcurrentToken(Long tokenId) { | |||
} | |||
} |
@@ -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; | |||
} | |||
@@ -77,10 +88,11 @@ public class TokenResult { | |||
@Override | |||
public String toString() { | |||
return "TokenResult{" + | |||
"status=" + status + | |||
", remaining=" + remaining + | |||
", waitInMs=" + waitInMs + | |||
", attachments=" + attachments + | |||
'}'; | |||
"status=" + status + | |||
", remaining=" + remaining + | |||
", waitInMs=" + waitInMs + | |||
", attachments=" + attachments + | |||
", tokenId=" + tokenId + | |||
'}'; | |||
} | |||
} |
@@ -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() { | |||
} | |||
} |
@@ -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); | |||
} |