Skip to content

Commit ba1c5b7

Browse files
committed
Pass resource and entry types in SentinelTemplate
Allow configuring Sentinel resource type and entry traffic type when creating entries. Adds resourceType (int) and trafficType (EntryType) fields with constructors and defaults (COMMON, IN), updates the entry(...) call to pass both type parameters, and includes necessary imports. This enables creating Sentinel entries with explicit resource/traffic types instead of using the single-argument entry(...) overload.
1 parent da7ac3b commit ba1c5b7

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

microsphere-sentinel-commons/src/main/java/io/microsphere/sentinel/common/SentinelTemplate.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@
1818
package io.microsphere.sentinel.common;
1919

2020
import com.alibaba.csp.sentinel.Entry;
21+
import com.alibaba.csp.sentinel.EntryType;
2122
import io.microsphere.logging.Logger;
2223

24+
import static com.alibaba.csp.sentinel.EntryType.IN;
25+
import static com.alibaba.csp.sentinel.ResourceTypeConstants.COMMON;
2326
import static com.alibaba.csp.sentinel.SphU.entry;
2427
import static com.alibaba.csp.sentinel.Tracer.traceEntry;
2528
import static com.alibaba.csp.sentinel.context.ContextUtil.enter;
@@ -38,6 +41,23 @@ public class SentinelTemplate implements SentinelOperations {
3841

3942
private static final Logger logger = getLogger(SentinelTemplate.class);
4043

44+
private final int resourceType;
45+
46+
private final EntryType trafficType;
47+
48+
public SentinelTemplate() {
49+
this(COMMON);
50+
}
51+
52+
public SentinelTemplate(int resourceType) {
53+
this(resourceType, IN);
54+
}
55+
56+
public SentinelTemplate(int resourceType, EntryType trafficType) {
57+
this.resourceType = resourceType;
58+
this.trafficType = trafficType;
59+
}
60+
4161
@Override
4262
public SentinelContext begin(String resourceName, String contextName, String origin) throws Throwable {
4363
String actualContextName = isBlank(contextName) ? DEFAULT_CONTEXT_NAME : contextName;
@@ -47,7 +67,7 @@ public SentinelContext begin(String resourceName, String contextName, String ori
4767
contextName, actualContextName, origin, actualOrigin, resourceName);
4868
}
4969
enter(actualContextName, actualOrigin);
50-
Entry entry = entry(resourceName);
70+
Entry entry = entry(resourceName, this.resourceType, this.trafficType);
5171
return new SentinelContext(resourceName, actualContextName, actualOrigin, entry);
5272
}
5373

0 commit comments

Comments
 (0)