Java Code Examples for com.alibaba.csp.sentinel.context.Context#getCurNode()
The following examples show how to use
com.alibaba.csp.sentinel.context.Context#getCurNode() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StatisticSlot.java From Sentinel-Dashboard-Nacos with Apache License 2.0 | 5 votes |
@Override public void exit(Context context, ResourceWrapper resourceWrapper, int count, Object... args) { DefaultNode node = (DefaultNode)context.getCurNode(); if (context.getCurEntry().getError() == null) { // Calculate response time (max RT is TIME_DROP_VALVE). long rt = TimeUtil.currentTimeMillis() - context.getCurEntry().getCreateTime(); if (rt > Constants.TIME_DROP_VALVE) { rt = Constants.TIME_DROP_VALVE; } // Record response time and success count. node.addRtAndSuccess(rt, count); if (context.getCurEntry().getOriginNode() != null) { context.getCurEntry().getOriginNode().addRtAndSuccess(rt, count); } node.decreaseThreadNum(); if (context.getCurEntry().getOriginNode() != null) { context.getCurEntry().getOriginNode().decreaseThreadNum(); } if (resourceWrapper.getType() == EntryType.IN) { Constants.ENTRY_NODE.addRtAndSuccess(rt, count); Constants.ENTRY_NODE.decreaseThreadNum(); } } else { // Error may happen. } // Handle exit event with registered exit callback handlers. Collection<ProcessorSlotExitCallback> exitCallbacks = StatisticSlotCallbackRegistry.getExitCallbacks(); for (ProcessorSlotExitCallback handler : exitCallbacks) { handler.onExit(context, resourceWrapper, count, args); } fireExit(context, resourceWrapper, count); }
Example 2
Source File: Tracer.java From Sentinel-Dashboard-Nacos with Apache License 2.0 | 5 votes |
/** * Trace provided {@link Throwable} and add exception count to entry in current context. * * @param e exception to record * @param count exception count to add */ public static void trace(Throwable e, int count) { if (!shouldTrace(e)) { return; } Context context = ContextUtil.getContext(); if (context == null) { return; } DefaultNode curNode = (DefaultNode)context.getCurNode(); traceExceptionToNode(e, count, context.getCurEntry(), curNode); }
Example 3
Source File: Tracer.java From Sentinel-Dashboard-Nacos with Apache License 2.0 | 5 votes |
/** * Trace provided {@link Throwable} and add exception count to current entry in provided context. * * @param e exception to record * @param count exception count to add * @since 1.4.2 */ public static void traceContext(Throwable e, int count, Context context) { if (!shouldTrace(e)) { return; } if (context == null) { return; } DefaultNode curNode = (DefaultNode)context.getCurNode(); traceExceptionToNode(e, count, context.getCurEntry(), curNode); }
Example 4
Source File: StatisticSlot.java From Sentinel with Apache License 2.0 | 5 votes |
@Override public void exit(Context context, ResourceWrapper resourceWrapper, int count, Object... args) { Node node = context.getCurNode(); if (context.getCurEntry().getBlockError() == null) { // Calculate response time (use completeStatTime as the time of completion). long completeStatTime = TimeUtil.currentTimeMillis(); context.getCurEntry().setCompleteTimestamp(completeStatTime); long rt = completeStatTime - context.getCurEntry().getCreateTimestamp(); Throwable error = context.getCurEntry().getError(); // Record response time and success count. recordCompleteFor(node, count, rt, error); recordCompleteFor(context.getCurEntry().getOriginNode(), count, rt, error); if (resourceWrapper.getEntryType() == EntryType.IN) { recordCompleteFor(Constants.ENTRY_NODE, count, rt, error); } } // Handle exit event with registered exit callback handlers. Collection<ProcessorSlotExitCallback> exitCallbacks = StatisticSlotCallbackRegistry.getExitCallbacks(); for (ProcessorSlotExitCallback handler : exitCallbacks) { handler.onExit(context, resourceWrapper, count, args); } fireExit(context, resourceWrapper, count); }