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(); } }); }
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(); } }); }
hostWithPathEntry.exit(); ContextUtil.exit();
entry.exit(); ContextUtil.exit();
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); }
/** * While loop will exit all entries, * Case serviceId and URL entry twice in {@link SentinelPreFilter}. * The ContextUtil.getContext().getCurEntry() will exit from inner to outer. */ @Override public Object run() throws ZuulException { while (ContextUtil.getContext() != null && ContextUtil.getContext().getCurEntry() != null) { ContextUtil.getContext().getCurEntry().exit(); } ContextUtil.exit(); return null; } }
/** * Trace not {@link BlockException} ex. * While loop will exit all entries, * Case serviceId and URL entry twice in {@link SentinelPreFilter}. * The ContextUtil.getContext().getCurEntry() will exit from inner to outer. */ @Override public Object run() throws ZuulException { try { RequestContext ctx = RequestContext.getCurrentContext(); Throwable throwable = ctx.getThrowable(); if (throwable != null) { if (!BlockException.isBlockException(throwable)) { Tracer.trace(throwable.getCause()); RecordLog.info("[Sentinel Error Filter] Trace cause", throwable.getCause()); } } } finally { while (ContextUtil.getContext() != null && ContextUtil.getContext().getCurEntry() != null) { ContextUtil.getContext().getCurEntry().exit(); } ContextUtil.exit(); } return null; } }
entry.exit(); ContextUtil.exit();
@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(); } }
entry.exit(); ContextUtil.exit();
ContextUtil.exit();
interfaceEntry.exit(); ContextUtil.exit();
hostWithPathEntry.exit(); ContextUtil.exit();
entry.exit(); ContextUtil.exit();
entry.exit(); ContextUtil.exit();
@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.exit();
interfaceEntry.exit(); ContextUtil.exit();