/** * <p> * Enter the invocation context. The context is ThreadLocal, meaning that * each thread has it's own {@link Context}. New context will be created if * current thread doesn't have one. * </p> * <p> * A context will related to A {@link EntranceNode}, which is the entrance * of the invocation tree. New {@link EntranceNode} will be created if * current context does't have one. Note that same resource name will share * same {@link EntranceNode} globally. * </p> * <p> * Same resource in different context will count separately, see {@link NodeSelectorSlot}. * </p> * * @param name the context name. * @return The invocation context of the current thread. */ public static Context enter(String name) { return enter(name, ""); }
private static void testFor(/*@NonNull*/ String resource, /*@NonNull*/ String origin) { ContextUtil.enter(resource, origin); Entry entry = null; try { entry = SphU.entry(resource); System.out.println(String.format("Passed for resource %s, origin is %s", resource, origin)); } catch (BlockException ex) { System.err.println(String.format("Blocked for resource %s, origin is %s", resource, origin)); } finally { if (entry != null) { entry.exit(); } ContextUtil.exit(); } }
private static void doSomething(MessageExt message) { pool.submit(() -> { Entry entry = null; try { ContextUtil.enter(KEY); entry = SphU.entry(KEY, EntryType.OUT); // Your business logic here. System.out.printf("[%d][%s][Success: %d] Receive New Messages: %s %n", System.currentTimeMillis(), Thread.currentThread().getName(), SUCCESS_COUNT.addAndGet(1), new String(message.getBody())); } catch (BlockException ex) { // Blocked. System.out.println("Blocked: " + FAIL_COUNT.addAndGet(1)); } finally { if (entry != null) { entry.exit(); } ContextUtil.exit(); } }); }
@Override public void run() { long startTime = System.currentTimeMillis(); ContextUtil.enter(String.valueOf(startTime)); while (!stop) {
private static void doSomething(MessageExt message) { pool.submit(() -> { Entry entry = null; try { ContextUtil.enter(KEY); entry = SphU.entry(KEY, EntryType.OUT); // Your business logic here. System.out.printf("[%d][%s][Success: %d] Receive New Messages: %s %n", System.currentTimeMillis(), Thread.currentThread().getName(), SUCCESS_COUNT.addAndGet(1), new String(message.getBody())); } catch (BlockException ex) { // Blocked. System.out.println("Blocked: " + FAIL_COUNT.addAndGet(1)); } finally { if (entry != null) { entry.exit(); } ContextUtil.exit(); } }); }
ClientHttpResponse response; try { ContextUtil.enter(hostWithPathResource); if (entryWithPath) { hostWithPathEntry = SphU.entry(hostWithPathResource);
Entry entry = null; try { ContextUtil.enter(resourceName); entry = SphU.entry(resourceName, EntryType.OUT, 1, args); result = methodHandler.invoke(args);
public static void main(String[] args) throws Exception { initFlowRule(); AsyncEntryDemo service = new AsyncEntryDemo(); // Expected invocation chain: // // EntranceNode: machine-root // -EntranceNode: async-context // --test-top // ---test-sync // ---test-async // ----test-another-async // -----test-another-sync-in-async // ----test-sync-in-async ContextUtil.enter("async-context", "originA"); Entry entry = null; try { entry = SphU.entry("test-top"); System.out.println("Do something..."); service.doAsyncThenSync(); } catch (BlockException ex) { // Request blocked, handle the exception. ex.printStackTrace(); } finally { if (entry != null) { entry.exit(); } ContextUtil.exit(); } TimeUnit.SECONDS.sleep(20); }
if (StringUtil.isNotEmpty(serviceTarget)) { RecordLog.info(String.format("[Sentinel Pre Filter] Origin: %s enter ServiceId: %s", origin, serviceTarget)); ContextUtil.enter(serviceTarget, origin); SphU.entry(serviceTarget, EntryType.IN); } else { RecordLog.info("[Sentinel Pre Filter] ServiceId is empty"); ContextUtil.enter(ZUUL_DEFAULT_CONTEXT, origin);
ContextUtil.enter(target, origin); entry = SphU.entry(target, EntryType.IN);
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest sRequest = (HttpServletRequest)request; String target = FilterUtil.filterTarget(sRequest); target = WebCallbackManager.getUrlCleaner().clean(target); Entry entry = null; try { ContextUtil.enter(target); entry = SphU.entry(TOTAL_URL_REQUEST); chain.doFilter(request, response); } catch (BlockException e) { HttpServletResponse sResponse = (HttpServletResponse)response; WebCallbackManager.getUrlBlockHandler().blocked(sRequest, sResponse, e); } catch (IOException e2) { Tracer.trace(e2); throw e2; } catch (ServletException e3) { Tracer.trace(e3); throw e3; } catch (RuntimeException e4) { Tracer.trace(e4); throw e4; } finally { if (entry != null) { entry.exit(); } ContextUtil.exit(); } }
ContextUtil.enter(resourceName); entry = SphU.entry(resourceName, EntryType.IN);
String resourceName = getResourceName(invoker, invocation); String interfaceName = invoker.getInterface().getName(); ContextUtil.enter(resourceName, application); interfaceEntry = SphU.entry(interfaceName, EntryType.IN); methodEntry = SphU.entry(resourceName, EntryType.IN, 1, invocation.getArguments());
/** * <p> * Enter the invocation context. The context is ThreadLocal, meaning that * each thread has it's own {@link Context}. New context will be created if * current thread doesn't have one. * </p> * <p> * A context will related to A {@link EntranceNode}, which is the entrance * of the invocation tree. New {@link EntranceNode} will be created if * current context does't have one. Note that same resource name will share * same {@link EntranceNode} globally. * </p> * <p> * Same resource in different context will count separately, see {@link NodeSelectorSlot}. * </p> * * @param name the context name. * @return The invocation context of the current thread. */ public static Context enter(String name) { return enter(name, ""); }
ClientHttpResponse response; try { ContextUtil.enter(hostWithPathResource); if (entryWithPath) { hostWithPathEntry = SphU.entry(hostWithPathResource);
Entry entry = null; try { ContextUtil.enter(resourceName); entry = SphU.entry(resourceName, EntryType.OUT, 1, args); result = methodHandler.invoke(args);
ContextUtil.enter(target, origin); entry = SphU.entry(target, EntryType.IN);
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest sRequest = (HttpServletRequest)request; String target = FilterUtil.filterTarget(sRequest); target = WebCallbackManager.getUrlCleaner().clean(target); Entry entry = null; try { ContextUtil.enter(target); entry = SphU.entry(TOTAL_URL_REQUEST); chain.doFilter(request, response); } catch (BlockException e) { HttpServletResponse sResponse = (HttpServletResponse)response; WebCallbackManager.getUrlBlockHandler().blocked(sRequest, sResponse, e); } catch (IOException e2) { Tracer.trace(e2); throw e2; } catch (ServletException e3) { Tracer.trace(e3); throw e3; } catch (RuntimeException e4) { Tracer.trace(e4); throw e4; } finally { if (entry != null) { entry.exit(); } ContextUtil.exit(); } }
String resourceName = getResourceName(invoker, invocation); String interfaceName = invoker.getInterface().getName(); ContextUtil.enter(resourceName, application); interfaceEntry = SphU.entry(interfaceName, EntryType.IN); methodEntry = SphU.entry(resourceName, EntryType.IN, 1, invocation.getArguments());