use of com.alibaba.csp.sentinel.AsyncEntry in project Sentinel by alibaba.
the class SentinelZuulInboundFilter method doSentinelEntry.
private void doSentinelEntry(String resourceName, final int resType, HttpRequestMessage input, Deque<EntryHolder> holders) throws BlockException {
Object[] params = paramParser.parseParameterFor(resourceName, input, r -> r.getResourceMode() == resType);
AsyncEntry entry = SphU.asyncEntry(resourceName, ResourceTypeConstants.COMMON_API_GATEWAY, EntryType.IN, params);
holders.push(new EntryHolder(entry, params));
}
use of com.alibaba.csp.sentinel.AsyncEntry in project Sentinel by alibaba.
the class SentinelReactorSubscriber method entryWhenSubscribed.
private void entryWhenSubscribed() {
ContextConfig sentinelContextConfig = entryConfig.getContextConfig();
if (sentinelContextConfig != null) {
// If current we're already in a context, the context config won't work.
ContextUtil.enter(sentinelContextConfig.getContextName(), sentinelContextConfig.getOrigin());
}
try {
AsyncEntry entry = SphU.asyncEntry(entryConfig.getResourceName(), entryConfig.getResourceType(), entryConfig.getEntryType(), entryConfig.getAcquireCount(), entryConfig.getArgs());
this.currentEntry = entry;
actual.onSubscribe(this);
} catch (BlockException ex) {
// Mark as completed (exited) explicitly.
entryExited.set(true);
// Signal cancel and propagate the {@code BlockException}.
cancel();
actual.onSubscribe(this);
actual.onError(ex);
} finally {
if (sentinelContextConfig != null) {
ContextUtil.exit();
}
}
}
use of com.alibaba.csp.sentinel.AsyncEntry in project skywalking-java by apache.
the class SentinelCtEntryConstructorInterceptor method onConstruct.
@Override
public void onConstruct(EnhancedInstance objInst, Object[] allArguments) {
if (!(objInst instanceof AsyncEntry)) {
ResourceWrapper resourceWrapper = (ResourceWrapper) allArguments[0];
AbstractSpan activeSpan = ContextManager.createLocalSpan("Sentinel/" + resourceWrapper.getName());
activeSpan.setComponent(ComponentsDefine.SENTINEL);
objInst.setSkyWalkingDynamicField(activeSpan);
ContextManager.getRuntimeContext().put(SENTINEL_SPAN, activeSpan);
}
}
use of com.alibaba.csp.sentinel.AsyncEntry in project skywalking-java by apache.
the class CaseController method testcase.
@RequestMapping("/sentinel-scenario")
@ResponseBody
public String testcase() throws InterruptedException, ExecutionException {
Entry entry = null;
try {
entry = SphU.entry("test_SphU_entry");
if (SphO.entry("test_SphO_entry")) {
Thread.sleep(1000L);
SphO.exit();
}
Thread.sleep(1000L);
} catch (BlockException ex) {
} catch (Exception ex) {
Tracer.traceEntry(ex, entry);
} finally {
if (entry != null) {
entry.exit();
}
}
try {
AsyncEntry asyncEntry = SphU.asyncEntry("test_SphU_asyncEntry");
new Thread(() -> {
try {
Thread.sleep(2000L);
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
asyncEntry.exit();
}
}).start();
} catch (BlockException ex) {
}
return SUCCESS;
}
Aggregations