This is an automated email from the ASF dual-hosted git repository.
jimin pushed a commit to branch 2.1.0
in repository https://gitbox.apache.org/repos/asf/incubator-seata.git
The following commit(s) were added to refs/heads/2.1.0 by this push:
new acb1dedfb9 bugfix: fix hsf ConsumerModel convert error (#6676)
acb1dedfb9 is described below
commit acb1dedfb99a711f80fd6a168c1480eb839e8796
Author: jimin <[email protected]>
AuthorDate: Sun Jul 14 00:30:58 2024 +0800
bugfix: fix hsf ConsumerModel convert error (#6676)
---
.../hsf/HsfTransactionConsumerFilter.java | 61 ++++++++++++++++++++++
...lter.java => HsfTransactionProviderFilter.java} | 40 +++++---------
.../com.taobao.hsf.invocation.filter.RPCFilter | 3 +-
3 files changed, 77 insertions(+), 27 deletions(-)
diff --git
a/integration/hsf/src/main/java/org/apache/seata/integration/hsf/HsfTransactionConsumerFilter.java
b/integration/hsf/src/main/java/org/apache/seata/integration/hsf/HsfTransactionConsumerFilter.java
new file mode 100644
index 0000000000..c291f30df8
--- /dev/null
+++
b/integration/hsf/src/main/java/org/apache/seata/integration/hsf/HsfTransactionConsumerFilter.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.seata.integration.hsf;
+
+import com.taobao.hsf.context.RPCContext;
+import com.taobao.hsf.invocation.Invocation;
+import com.taobao.hsf.invocation.InvocationHandler;
+import com.taobao.hsf.invocation.RPCResult;
+import com.taobao.hsf.invocation.filter.ClientFilter;
+import com.taobao.hsf.util.concurrent.ListenableFuture;
+import org.apache.seata.core.context.RootContext;
+import org.apache.seata.core.model.BranchType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * The type Hsf transaction consumer filter.
+ */
+public class HsfTransactionConsumerFilter implements ClientFilter {
+
+ private static final Logger LOGGER =
LoggerFactory.getLogger(HsfTransactionConsumerFilter.class);
+
+ @Override
+ public ListenableFuture<RPCResult> invoke(InvocationHandler nextHandler,
Invocation invocation) throws Throwable {
+ String xid = RootContext.getXID();
+ BranchType branchType = RootContext.getBranchType();
+
+ if (LOGGER.isDebugEnabled()) {
+ LOGGER.debug("xid in RootContext[{}], branchType in
RootContext[{}]", xid, branchType);
+ }
+ if (xid != null) {
+ RPCContext.getClientContext().putAttachment(RootContext.KEY_XID,
xid);
+
RPCContext.getClientContext().putAttachment(RootContext.KEY_BRANCH_TYPE,
branchType.name());
+ }
+ try {
+ return nextHandler.invoke(invocation);
+ } finally {
+
RPCContext.getClientContext().removeAttachment(RootContext.KEY_XID);
+
RPCContext.getClientContext().removeAttachment(RootContext.KEY_BRANCH_TYPE);
+ }
+ }
+
+ @Override
+ public void onResponse(Invocation invocation, RPCResult rpcResult) {
+
+ }
+}
diff --git
a/integration/hsf/src/main/java/org/apache/seata/integration/hsf/HsfTransactionFilter.java
b/integration/hsf/src/main/java/org/apache/seata/integration/hsf/HsfTransactionProviderFilter.java
similarity index 70%
rename from
integration/hsf/src/main/java/org/apache/seata/integration/hsf/HsfTransactionFilter.java
rename to
integration/hsf/src/main/java/org/apache/seata/integration/hsf/HsfTransactionProviderFilter.java
index c2d5919307..3c85858afb 100644
---
a/integration/hsf/src/main/java/org/apache/seata/integration/hsf/HsfTransactionFilter.java
+++
b/integration/hsf/src/main/java/org/apache/seata/integration/hsf/HsfTransactionProviderFilter.java
@@ -20,7 +20,6 @@ import com.taobao.hsf.context.RPCContext;
import com.taobao.hsf.invocation.Invocation;
import com.taobao.hsf.invocation.InvocationHandler;
import com.taobao.hsf.invocation.RPCResult;
-import com.taobao.hsf.invocation.filter.ClientFilter;
import com.taobao.hsf.invocation.filter.ServerFilter;
import com.taobao.hsf.util.concurrent.ListenableFuture;
import org.apache.seata.common.util.StringUtils;
@@ -30,42 +29,33 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
- * The type Transaction propagation filter.
- *
+ * The type Hsf transaction provider filter.
*/
-public class HsfTransactionFilter implements ClientFilter, ServerFilter {
+public class HsfTransactionProviderFilter implements ServerFilter {
- private static final Logger LOGGER =
LoggerFactory.getLogger(HsfTransactionFilter.class);
+ private static final Logger LOGGER =
LoggerFactory.getLogger(HsfTransactionProviderFilter.class);
@Override
- public ListenableFuture<RPCResult> invoke(InvocationHandler
invocationHandler, Invocation invocation)
- throws Throwable {
- String xid = RootContext.getXID();
- BranchType branchType = RootContext.getBranchType();
+ public ListenableFuture<RPCResult> invoke(InvocationHandler nextHandler,
Invocation invocation) throws Throwable {
Object rpcXid =
RPCContext.getServerContext().getAttachment(RootContext.KEY_XID);
Object rpcBranchType =
RPCContext.getServerContext().getAttachment(RootContext.KEY_BRANCH_TYPE);
if (LOGGER.isDebugEnabled()) {
- LOGGER.debug("xid in RootContext[{}] xid in RpcContext[{}]", xid,
rpcXid);
+ LOGGER.debug("xid in RpcContext[{}], branchType in
RpcContext[{}]", rpcXid, rpcBranchType);
}
boolean bind = false;
- if (xid != null) {
- RPCContext.getClientContext().putAttachment(RootContext.KEY_XID,
xid);
-
RPCContext.getClientContext().putAttachment(RootContext.KEY_BRANCH_TYPE,
branchType.name());
- } else {
- if (rpcXid != null) {
- RootContext.bind(rpcXid.toString());
- if (StringUtils.equals(BranchType.TCC.name(),
rpcBranchType.toString())) {
- RootContext.bindBranchType(BranchType.TCC);
- }
- bind = true;
- if (LOGGER.isDebugEnabled()) {
- LOGGER.debug("bind xid [{}] branchType [{}] to
RootContext", rpcXid, rpcBranchType);
- }
+ if (rpcXid != null) {
+ RootContext.bind(rpcXid.toString());
+ if (StringUtils.equals(BranchType.TCC.name(),
rpcBranchType.toString())) {
+ RootContext.bindBranchType(BranchType.TCC);
+ }
+ bind = true;
+ if (LOGGER.isDebugEnabled()) {
+ LOGGER.debug("bind xid [{}] branchType [{}] to RootContext",
rpcXid, rpcBranchType);
}
}
try {
- return invocationHandler.invoke(invocation);
+ return nextHandler.invoke(invocation);
} finally {
if (bind) {
BranchType previousBranchType = RootContext.getBranchType();
@@ -89,8 +79,6 @@ public class HsfTransactionFilter implements ClientFilter,
ServerFilter {
}
}
}
-
RPCContext.getClientContext().removeAttachment(RootContext.KEY_XID);
-
RPCContext.getClientContext().removeAttachment(RootContext.KEY_BRANCH_TYPE);
RPCContext.getServerContext().removeAttachment(RootContext.KEY_XID);
RPCContext.getServerContext().removeAttachment(RootContext.KEY_BRANCH_TYPE);
}
diff --git
a/integration/hsf/src/main/resources/META-INF/services/com.taobao.hsf.invocation.filter.RPCFilter
b/integration/hsf/src/main/resources/META-INF/services/com.taobao.hsf.invocation.filter.RPCFilter
index bd53bc9e9e..371dd4f395 100644
---
a/integration/hsf/src/main/resources/META-INF/services/com.taobao.hsf.invocation.filter.RPCFilter
+++
b/integration/hsf/src/main/resources/META-INF/services/com.taobao.hsf.invocation.filter.RPCFilter
@@ -1 +1,2 @@
-org.apache.seata.integration.hsf.HsfTransactionFilter
\ No newline at end of file
+org.apache.seata.integration.hsf.HsfTransactionConsumerFilter
+org.apache.seata.integration.hsf.HsfTransactionProviderFilter
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]