Search in sources :

Example 6 with AsyncEntry

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));
}
Also used : EntryHolder(com.alibaba.csp.sentinel.adapter.gateway.zuul2.filters.EntryHolder) AsyncEntry(com.alibaba.csp.sentinel.AsyncEntry)

Example 7 with AsyncEntry

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();
        }
    }
}
Also used : BlockException(com.alibaba.csp.sentinel.slots.block.BlockException) AsyncEntry(com.alibaba.csp.sentinel.AsyncEntry)

Example 8 with AsyncEntry

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);
    }
}
Also used : ResourceWrapper(com.alibaba.csp.sentinel.slotchain.ResourceWrapper) AsyncEntry(com.alibaba.csp.sentinel.AsyncEntry) AbstractSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)

Example 9 with AsyncEntry

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;
}
Also used : AsyncEntry(com.alibaba.csp.sentinel.AsyncEntry) Entry(com.alibaba.csp.sentinel.Entry) BlockException(com.alibaba.csp.sentinel.slots.block.BlockException) AsyncEntry(com.alibaba.csp.sentinel.AsyncEntry) ExecutionException(java.util.concurrent.ExecutionException) BlockException(com.alibaba.csp.sentinel.slots.block.BlockException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

AsyncEntry (com.alibaba.csp.sentinel.AsyncEntry)9 BlockException (com.alibaba.csp.sentinel.slots.block.BlockException)6 Entry (com.alibaba.csp.sentinel.Entry)1 EntryType (com.alibaba.csp.sentinel.EntryType)1 SphU (com.alibaba.csp.sentinel.SphU)1 Tracer (com.alibaba.csp.sentinel.Tracer)1 GatewayFlowRule (com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayFlowRule)1 EntryHolder (com.alibaba.csp.sentinel.adapter.gateway.zuul2.filters.EntryHolder)1 Context (com.alibaba.csp.sentinel.context.Context)1 ResourceWrapper (com.alibaba.csp.sentinel.slotchain.ResourceWrapper)1 ExecutionException (java.util.concurrent.ExecutionException)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 AbstractSpan (org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1 Mono (reactor.core.publisher.Mono)1