Przeglądaj źródła

Add concurrency token request/release operation in TokenService

Signed-off-by: yunfeiyanggzq <yunfeiyang@buaa.edu.cn>
master
yunfeiyanggzq Eric Zhao 4 lat temu
rodzic
commit
473cc84262
5 zmienionych plików z 62 dodań i 7 usunięć
  1. +9
    -0
      sentinel-cluster/sentinel-cluster-client-default/src/main/java/com/alibaba/csp/sentinel/cluster/client/DefaultClusterTokenClient.java
  2. +9
    -0
      sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/server/DefaultEmbeddedTokenServer.java
  3. +18
    -6
      sentinel-core/src/main/java/com/alibaba/csp/sentinel/cluster/TokenResult.java
  4. +10
    -1
      sentinel-core/src/main/java/com/alibaba/csp/sentinel/cluster/TokenResultStatus.java
  5. +16
    -0
      sentinel-core/src/main/java/com/alibaba/csp/sentinel/cluster/TokenService.java

+ 9
- 0
sentinel-cluster/sentinel-cluster-client-default/src/main/java/com/alibaba/csp/sentinel/cluster/client/DefaultClusterTokenClient.java Wyświetl plik

@@ -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:


+ 9
- 0
sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/server/DefaultEmbeddedTokenServer.java Wyświetl plik

@@ -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) {
}
}

+ 18
- 6
sentinel-core/src/main/java/com/alibaba/csp/sentinel/cluster/TokenResult.java Wyświetl plik

@@ -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 +
'}';
}
}

+ 10
- 1
sentinel-core/src/main/java/com/alibaba/csp/sentinel/cluster/TokenResultStatus.java Wyświetl plik

@@ -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() {
}
}

+ 16
- 0
sentinel-core/src/main/java/com/alibaba/csp/sentinel/cluster/TokenService.java Wyświetl plik

@@ -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);
}

Ładowanie…
Anuluj
Zapisz