This is an automated email from the ASF dual-hosted git repository.

ningjiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-saga.git

commit 877a2783f9a3336b71230eadef7fd54a5b40a125
Author: Willem Jiang <jiangni...@huawei.com>
AuthorDate: Thu May 10 17:00:15 2018 +0800

    SCB-571 reformate the code of omega-transport-dubbo
---
 .../transport/dubbo/SagaDubboConsumerFilter.java   | 39 +++++++++--------
 .../transport/dubbo/SagaDubboProviderFilter.java   | 51 +++++++++++-----------
 2 files changed, 46 insertions(+), 44 deletions(-)

diff --git 
a/omega/omega-transport/omega-transport-dubbo/src/main/java/org/apache/servicecomb/saga/omega/transport/dubbo/SagaDubboConsumerFilter.java
 
b/omega/omega-transport/omega-transport-dubbo/src/main/java/org/apache/servicecomb/saga/omega/transport/dubbo/SagaDubboConsumerFilter.java
index a6a73e8..35f02a2 100644
--- 
a/omega/omega-transport/omega-transport-dubbo/src/main/java/org/apache/servicecomb/saga/omega/transport/dubbo/SagaDubboConsumerFilter.java
+++ 
b/omega/omega-transport/omega-transport-dubbo/src/main/java/org/apache/servicecomb/saga/omega/transport/dubbo/SagaDubboConsumerFilter.java
@@ -37,26 +37,27 @@ import static 
org.apache.servicecomb.saga.omega.context.OmegaContext.LOCAL_TX_ID
 
 /**
  * add saga transaction id to dubbo invocation
-*/
+ */
 @Activate(group = {Constants.CONSUMER})
 public class SagaDubboConsumerFilter implements Filter {
-    private static final Logger LOG = 
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
-
-    public Result invoke(Invoker<?> invoker, Invocation invocation) throws 
RpcException {
-        // TODO not sure if it's a good way to look up OmegaContext during 
every invoke
-        OmegaContext omegaContext = (OmegaContext) (new 
SpringExtensionFactory()).getExtension(OmegaContext.class, "omegaContext");
-        if(omegaContext != null){
-            invocation.getAttachments().put(GLOBAL_TX_ID_KEY, 
omegaContext.globalTxId());
-            invocation.getAttachments().put(LOCAL_TX_ID_KEY, 
omegaContext.localTxId());
-        }
-        if (omegaContext != null && omegaContext.globalTxId() != null) {
-            LOG.info("Added {} {} and {} {} to dubbo invocation", new 
Object[]{GLOBAL_TX_ID_KEY, omegaContext.globalTxId(),
-                    LOCAL_TX_ID_KEY, omegaContext.localTxId()});
-        }
-
-        if (invoker != null) {
-            return invoker.invoke(invocation);
-        }
-        return null;
+  private static final Logger LOG = 
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+  public Result invoke(Invoker<?> invoker, Invocation invocation) throws 
RpcException {
+    // TODO not sure if it's a good way to look up OmegaContext during every 
invoke
+    OmegaContext omegaContext = (OmegaContext) (new SpringExtensionFactory())
+        .getExtension(OmegaContext.class, "omegaContext");
+    if (omegaContext != null) {
+      invocation.getAttachments().put(GLOBAL_TX_ID_KEY, 
omegaContext.globalTxId());
+      invocation.getAttachments().put(LOCAL_TX_ID_KEY, 
omegaContext.localTxId());
+    }
+    if (omegaContext != null && omegaContext.globalTxId() != null) {
+      LOG.info("Added {} {} and {} {} to dubbo invocation", new Object[] 
{GLOBAL_TX_ID_KEY, omegaContext.globalTxId(),
+          LOCAL_TX_ID_KEY, omegaContext.localTxId()});
+    }
+
+    if (invoker != null) {
+      return invoker.invoke(invocation);
     }
+    return null;
+  }
 }
diff --git 
a/omega/omega-transport/omega-transport-dubbo/src/main/java/org/apache/servicecomb/saga/omega/transport/dubbo/SagaDubboProviderFilter.java
 
b/omega/omega-transport/omega-transport-dubbo/src/main/java/org/apache/servicecomb/saga/omega/transport/dubbo/SagaDubboProviderFilter.java
index 32d253b..acb0524 100644
--- 
a/omega/omega-transport/omega-transport-dubbo/src/main/java/org/apache/servicecomb/saga/omega/transport/dubbo/SagaDubboProviderFilter.java
+++ 
b/omega/omega-transport/omega-transport-dubbo/src/main/java/org/apache/servicecomb/saga/omega/transport/dubbo/SagaDubboProviderFilter.java
@@ -20,6 +20,7 @@ import com.alibaba.dubbo.common.Constants;
 import com.alibaba.dubbo.common.extension.Activate;
 import com.alibaba.dubbo.config.spring.extension.SpringExtensionFactory;
 import com.alibaba.dubbo.rpc.*;
+
 import org.apache.servicecomb.saga.omega.context.OmegaContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -31,33 +32,33 @@ import static 
org.apache.servicecomb.saga.omega.context.OmegaContext.LOCAL_TX_ID
 
 /**
  * get saga transaction id from dubbo invocation and set into omega context
-*/
+ */
 @Activate(group = Constants.PROVIDER)
 public class SagaDubboProviderFilter implements Filter {
 
-    private static final Logger LOG = 
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
-
-    @Override
-    public Result invoke(Invoker<?> invoker, Invocation invocation) throws 
RpcException {
-        // TODO not sure if it's a good way to look up OmegaContext during 
every invoke
-        OmegaContext omegaContext = new 
SpringExtensionFactory().getExtension(OmegaContext.class, "omegaContext");
-        if (omegaContext != null) {
-          String globalTxId = invocation.getAttachment(GLOBAL_TX_ID_KEY);
-          if (globalTxId == null) {
-            LOG.info("no such omega context global id: {}", GLOBAL_TX_ID_KEY);
-          } else {
-            omegaContext.setGlobalTxId(globalTxId);
-            
omegaContext.setLocalTxId(invocation.getAttachment(LOCAL_TX_ID_KEY));
-            LOG.info("Added {} {} and {} {} to omegaContext", new Object[] 
{GLOBAL_TX_ID_KEY, omegaContext.globalTxId(),
-                LOCAL_TX_ID_KEY, omegaContext.localTxId()});
-          }
-          invocation.getAttachments().put(GLOBAL_TX_ID_KEY, null);
-          invocation.getAttachments().put(LOCAL_TX_ID_KEY, null);
-        }
-
-        if(invoker != null){
-            return invoker.invoke(invocation);
-        }
-        return null;
+  private static final Logger LOG = 
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+  @Override
+  public Result invoke(Invoker<?> invoker, Invocation invocation) throws 
RpcException {
+    // TODO not sure if it's a good way to look up OmegaContext during every 
invoke
+    OmegaContext omegaContext = new 
SpringExtensionFactory().getExtension(OmegaContext.class, "omegaContext");
+    if (omegaContext != null) {
+      String globalTxId = invocation.getAttachment(GLOBAL_TX_ID_KEY);
+      if (globalTxId == null) {
+        LOG.info("no such omega context global id: {}", GLOBAL_TX_ID_KEY);
+      } else {
+        omegaContext.setGlobalTxId(globalTxId);
+        omegaContext.setLocalTxId(invocation.getAttachment(LOCAL_TX_ID_KEY));
+        LOG.info("Added {} {} and {} {} to omegaContext", new Object[] 
{GLOBAL_TX_ID_KEY, omegaContext.globalTxId(),
+            LOCAL_TX_ID_KEY, omegaContext.localTxId()});
+      }
+      invocation.getAttachments().put(GLOBAL_TX_ID_KEY, null);
+      invocation.getAttachments().put(LOCAL_TX_ID_KEY, null);
+    }
+
+    if (invoker != null) {
+      return invoker.invoke(invocation);
     }
+    return null;
+  }
 }

-- 
To stop receiving notification emails like this one, please contact
ningji...@apache.org.

Reply via email to