Java Code Examples for io.seata.core.context.RootContext#unbind()
The following examples show how to use
io.seata.core.context.RootContext#unbind() .
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: SeataFilter.java From seata-samples with Apache License 2.0 | 6 votes |
@Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { HttpServletRequest req = (HttpServletRequest) servletRequest; String xid = req.getHeader(RootContext.KEY_XID.toLowerCase()); boolean isBind = false; if (StringUtils.isNotBlank(xid)) { RootContext.bind(xid); isBind = true; } try { filterChain.doFilter(servletRequest, servletResponse); } finally { if (isBind) { RootContext.unbind(); } } }
Example 2
Source File: SeataHandlerInterceptor.java From spring-cloud-alibaba with Apache License 2.0 | 6 votes |
@Override public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception e) { String rpcXid = request.getHeader(RootContext.KEY_XID); if (StringUtils.isEmpty(rpcXid)) { return; } String unbindXid = RootContext.unbind(); if (log.isDebugEnabled()) { log.debug("unbind {} from RootContext", unbindXid); } if (!rpcXid.equalsIgnoreCase(unbindXid)) { log.warn("xid in change during RPC from {} to {}", rpcXid, unbindXid); if (unbindXid != null) { RootContext.bind(unbindXid); log.warn("bind {} back to RootContext", unbindXid); } } }
Example 3
Source File: SeataXidFilter.java From demo-seata-springcloud with Apache License 2.0 | 5 votes |
@Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { String xid = RootContext.getXID(); String restXid = request.getHeader(SeataConstant.XID_HEADER); boolean bind = false; if (StringUtils.isBlank(xid) && StringUtils.isNotBlank(restXid)) { RootContext.bind(restXid); bind = true; if (logger.isDebugEnabled()) { logger.debug("bind[" + restXid + "] to RootContext"); } } try { filterChain.doFilter(request, response); } finally { if (bind) { String unbindXid = RootContext.unbind(); if (logger.isDebugEnabled()) { logger.debug("unbind[" + unbindXid + "] from RootContext"); } if (!restXid.equalsIgnoreCase(unbindXid)) { logger.warn("xid in change during http rest from " + restXid + " to " + unbindXid); if (unbindXid != null) { RootContext.bind(unbindXid); logger.warn("bind [" + unbindXid + "] back to RootContext"); } } } } }
Example 4
Source File: SeataXidFilter.java From demo-seata-springcloud with Apache License 2.0 | 5 votes |
@Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { String xid = RootContext.getXID(); String restXid = request.getHeader(SeataConstant.XID_HEADER); boolean bind = false; if (StringUtils.isBlank(xid) && StringUtils.isNotBlank(restXid)) { RootContext.bind(restXid); bind = true; if (logger.isDebugEnabled()) { logger.debug("bind[" + restXid + "] to RootContext"); } } try { filterChain.doFilter(request, response); } finally { if (bind) { String unbindXid = RootContext.unbind(); if (logger.isDebugEnabled()) { logger.debug("unbind[" + unbindXid + "] from RootContext"); } if (!restXid.equalsIgnoreCase(unbindXid)) { logger.warn("xid in change during http rest from " + restXid + " to " + unbindXid); if (unbindXid != null) { RootContext.bind(unbindXid); logger.warn("bind [" + unbindXid + "] back to RootContext"); } } } } }
Example 5
Source File: SeataXidFilter.java From demo-seata-springcloud with Apache License 2.0 | 5 votes |
@Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { String xid = RootContext.getXID(); String restXid = request.getHeader(SeataConstant.XID_HEADER); boolean bind = false; if (StringUtils.isBlank(xid) && StringUtils.isNotBlank(restXid)) { RootContext.bind(restXid); bind = true; if (logger.isDebugEnabled()) { logger.debug("bind[" + restXid + "] to RootContext"); } } try { filterChain.doFilter(request, response); } finally { if (bind) { String unbindXid = RootContext.unbind(); if (logger.isDebugEnabled()) { logger.debug("unbind[" + unbindXid + "] from RootContext"); } if (!restXid.equalsIgnoreCase(unbindXid)) { logger.warn("xid in change during http rest from " + restXid + " to " + unbindXid); if (unbindXid != null) { RootContext.bind(unbindXid); logger.warn("bind [" + unbindXid + "] back to RootContext"); } } } } }
Example 6
Source File: AutoCpsLocalTransactionExecutor.java From EasyTransaction with Apache License 2.0 | 5 votes |
public static <R> R executeWithGlobalLockCheck(Callable<R> call) throws Exception { try { RootContext.bind("Local Tranaction with Global lock support"); return call.call(); } finally { RootContext.unbind(); } }
Example 7
Source File: AbstractAutoCpsMethod.java From EasyTransaction with Apache License 2.0 | 5 votes |
@Override public final R doAutoCpsBusiness(P param) { TransactionId transactionId = MetaDataFilter.getMetaData(EasytransConstant.CallHeadKeys.PARENT_TRX_ID_KEY); String xid = getFescarXid(transactionId); try { RootContext.bind(xid); return doBusiness(param); } finally { RootContext.unbind(); } }
Example 8
Source File: SeataHystrixConcurrencyStrategy.java From spring-cloud-alibaba with Apache License 2.0 | 5 votes |
@Override public K call() throws Exception { try { RequestContextHolder.setRequestAttributes(requestAttributes); RootContext.bind(xid); return actual.call(); } finally { RootContext.unbind(); RequestContextHolder.resetRequestAttributes(); } }
Example 9
Source File: TransactionPropagationFilter.java From jboot with Apache License 2.0 | 5 votes |
@Override public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { if (!JbootSeataManager.me().isEnable()){ return invoker.invoke(invocation); } String xid = RootContext.getXID(); String rpcXid = RpcContext.getContext().getAttachment(RootContext.KEY_XID); if (LOGGER.isDebugEnabled()) { LOGGER.debug("xid in RootContext[" + xid + "] xid in RpcContext[" + rpcXid + "]"); } boolean bind = false; if (xid != null) { RpcContext.getContext().setAttachment(RootContext.KEY_XID, xid); } else { if (rpcXid != null) { RootContext.bind(rpcXid); bind = true; if (LOGGER.isDebugEnabled()) { LOGGER.debug("bind[" + rpcXid + "] to RootContext"); } } } try { return invoker.invoke(invocation); } finally { if (bind) { String unbindXid = RootContext.unbind(); if (LOGGER.isDebugEnabled()) { LOGGER.debug("unbind[" + unbindXid + "] from RootContext"); } if (!rpcXid.equalsIgnoreCase(unbindXid)) { LOGGER.warn("xid in change during RPC from " + rpcXid + " to " + unbindXid); if (unbindXid != null) { RootContext.bind(unbindXid); LOGGER.warn("bind [" + unbindXid + "] back to RootContext"); } } } } }
Example 10
Source File: SeataATShardingTransactionManager.java From shardingsphere with Apache License 2.0 | 5 votes |
@Override @SneakyThrows public void commit() { Preconditions.checkState(enableSeataAT, "sharding seata-at transaction has been disabled."); try { SeataTransactionHolder.get().commit(); } finally { SeataTransactionHolder.clear(); RootContext.unbind(); } }
Example 11
Source File: SeataATShardingTransactionManager.java From shardingsphere with Apache License 2.0 | 5 votes |
@Override @SneakyThrows public void rollback() { Preconditions.checkState(enableSeataAT, "sharding seata-at transaction has been disabled."); try { SeataTransactionHolder.get().rollback(); } finally { SeataTransactionHolder.clear(); RootContext.unbind(); } }
Example 12
Source File: SeataATShardingTransactionManagerTest.java From shardingsphere with Apache License 2.0 | 5 votes |
@After public void tearDown() { ExecutorDataMap.getValue().clear(); RootContext.unbind(); SeataTransactionHolder.clear(); seataATShardingTransactionManager.close(); releaseRpcClient(); requestQueue.clear(); responseQueue.clear(); }
Example 13
Source File: TransactionalSQLExecutionHook.java From shardingsphere with Apache License 2.0 | 4 votes |
@Override public void finishSuccess() { if (seataBranch) { RootContext.unbind(); } }
Example 14
Source File: TransactionalSQLExecutionHook.java From shardingsphere with Apache License 2.0 | 4 votes |
@Override public void finishFailure(final Exception cause) { if (seataBranch) { RootContext.unbind(); } }
Example 15
Source File: TransactionalSQLExecutionHookTest.java From shardingsphere with Apache License 2.0 | 4 votes |
@After public void tearDown() { RootContext.unbind(); }