Signed-off-by: Eric Zhao <sczyh16@gmail.com>master
@@ -18,6 +18,7 @@ package com.alibaba.csp.sentinel.adapter.reactor; | |||
import java.util.Arrays; | |||
import com.alibaba.csp.sentinel.EntryType; | |||
import com.alibaba.csp.sentinel.ResourceTypeConstants; | |||
import com.alibaba.csp.sentinel.util.AssertUtil; | |||
/** | |||
@@ -28,6 +29,8 @@ public class EntryConfig { | |||
private final String resourceName; | |||
private final EntryType entryType; | |||
private final int resourceType; | |||
private final int acquireCount; | |||
private final Object[] args; | |||
private final ContextConfig contextConfig; | |||
@@ -50,11 +53,21 @@ public class EntryConfig { | |||
public EntryConfig(String resourceName, EntryType entryType, int acquireCount, Object[] args, | |||
ContextConfig contextConfig) { | |||
this(resourceName, ResourceTypeConstants.COMMON, entryType, acquireCount, args, contextConfig); | |||
} | |||
public EntryConfig(String resourceName, int resourceType, EntryType entryType, int acquireCount, Object[] args) { | |||
this(resourceName, resourceType, entryType, acquireCount, args, null); | |||
} | |||
public EntryConfig(String resourceName, int resourceType, EntryType entryType, int acquireCount, Object[] args, | |||
ContextConfig contextConfig) { | |||
AssertUtil.assertNotBlank(resourceName, "resourceName cannot be blank"); | |||
AssertUtil.notNull(entryType, "entryType cannot be null"); | |||
AssertUtil.isTrue(acquireCount > 0, "acquireCount should be positive"); | |||
this.resourceName = resourceName; | |||
this.entryType = entryType; | |||
this.resourceType = resourceType; | |||
this.acquireCount = acquireCount; | |||
this.args = args; | |||
// Constructed ContextConfig should be valid here. Null is allowed here. | |||
@@ -81,11 +94,19 @@ public class EntryConfig { | |||
return contextConfig; | |||
} | |||
/** | |||
* @since 1.7.0 | |||
*/ | |||
public int getResourceType() { | |||
return resourceType; | |||
} | |||
@Override | |||
public String toString() { | |||
return "EntryConfig{" + | |||
"resourceName='" + resourceName + '\'' + | |||
", entryType=" + entryType + | |||
", resourceType=" + resourceType + | |||
", acquireCount=" + acquireCount + | |||
", args=" + Arrays.toString(args) + | |||
", contextConfig=" + contextConfig + | |||
@@ -89,8 +89,8 @@ public class SentinelReactorSubscriber<T> extends InheritableBaseSubscriber<T> { | |||
ContextUtil.enter(sentinelContextConfig.getContextName(), sentinelContextConfig.getOrigin()); | |||
} | |||
try { | |||
AsyncEntry entry = SphU.asyncEntry(entryConfig.getResourceName(), entryConfig.getEntryType(), | |||
entryConfig.getAcquireCount(), entryConfig.getArgs()); | |||
AsyncEntry entry = SphU.asyncEntry(entryConfig.getResourceName(), entryConfig.getResourceType(), | |||
entryConfig.getEntryType(), entryConfig.getAcquireCount(), entryConfig.getArgs()); | |||
this.currentEntry = entry; | |||
actual.onSubscribe(this); | |||
} catch (BlockException ex) { | |||
@@ -20,6 +20,7 @@ import java.util.Set; | |||
import java.util.stream.Collectors; | |||
import com.alibaba.csp.sentinel.EntryType; | |||
import com.alibaba.csp.sentinel.ResourceTypeConstants; | |||
import com.alibaba.csp.sentinel.adapter.gateway.common.SentinelGatewayConstants; | |||
import com.alibaba.csp.sentinel.adapter.gateway.common.param.GatewayParamParser; | |||
import com.alibaba.csp.sentinel.adapter.gateway.sc.callback.GatewayCallbackManager; | |||
@@ -70,8 +71,8 @@ public class SentinelGatewayFilter implements GatewayFilter, GlobalFilter, Order | |||
.map(f -> f.apply(exchange)) | |||
.orElse(""); | |||
asyncResult = asyncResult.transform( | |||
new SentinelReactorTransformer<>(new EntryConfig(routeId, EntryType.IN, | |||
1, params, new ContextConfig(contextName(routeId), origin))) | |||
new SentinelReactorTransformer<>(new EntryConfig(routeId, ResourceTypeConstants.COMMON_API_GATEWAY, | |||
EntryType.IN, 1, params, new ContextConfig(contextName(routeId), origin))) | |||
); | |||
} | |||
@@ -80,7 +81,8 @@ public class SentinelGatewayFilter implements GatewayFilter, GlobalFilter, Order | |||
Object[] params = paramParser.parseParameterFor(apiName, exchange, | |||
r -> r.getResourceMode() == SentinelGatewayConstants.RESOURCE_MODE_CUSTOM_API_NAME); | |||
asyncResult = asyncResult.transform( | |||
new SentinelReactorTransformer<>(new EntryConfig(apiName, EntryType.IN, 1, params)) | |||
new SentinelReactorTransformer<>(new EntryConfig(apiName, ResourceTypeConstants.COMMON_API_GATEWAY, | |||
EntryType.IN, 1, params)) | |||
); | |||
} | |||