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 de13058dbdd7ddfcd444a373cac5c94b74b77481
Author: Willem Jiang <jiangni...@huawei.com>
AuthorDate: Thu May 10 16:52:43 2018 +0800

    SCB-571 Decouple OmegaContext in omega-transport-servicecomb
---
 .../transport/servicecomb/SagaConsumerHandler.java  |  8 +++++---
 .../transport/servicecomb/SagaProviderHandler.java  | 21 +++++++++++++--------
 2 files changed, 18 insertions(+), 11 deletions(-)

diff --git 
a/omega/omega-transport/omega-transport-servicecomb/src/main/java/org/apache/servicecomb/saga/omega/transport/servicecomb/SagaConsumerHandler.java
 
b/omega/omega-transport/omega-transport-servicecomb/src/main/java/org/apache/servicecomb/saga/omega/transport/servicecomb/SagaConsumerHandler.java
index 5e0dcb2..82e49ef 100644
--- 
a/omega/omega-transport/omega-transport-servicecomb/src/main/java/org/apache/servicecomb/saga/omega/transport/servicecomb/SagaConsumerHandler.java
+++ 
b/omega/omega-transport/omega-transport-servicecomb/src/main/java/org/apache/servicecomb/saga/omega/transport/servicecomb/SagaConsumerHandler.java
@@ -36,14 +36,16 @@ public class SagaConsumerHandler implements Handler {
   private static final Logger LOG = 
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
   private final OmegaContext omegaContext;
 
-  @Autowired
-  public SagaConsumerHandler(OmegaContext omegaContext) {
+  public SagaConsumerHandler(@Autowired(required=false) OmegaContext 
omegaContext) {
     this.omegaContext = omegaContext;
+    if (omegaContext == null) {
+      LOG.info("The OmegaContext is not injected, The SagaConsumerHandler is 
disabled.");
+    }
   }
 
   @Override
   public void handle(Invocation invocation, AsyncResponse asyncResponse) 
throws Exception {
-    if (omegaContext.globalTxId() != null) {
+    if (omegaContext!= null && omegaContext.globalTxId() != null) {
       invocation.getContext().put(GLOBAL_TX_ID_KEY, omegaContext.globalTxId());
       invocation.getContext().put(LOCAL_TX_ID_KEY, omegaContext.localTxId());
 
diff --git 
a/omega/omega-transport/omega-transport-servicecomb/src/main/java/org/apache/servicecomb/saga/omega/transport/servicecomb/SagaProviderHandler.java
 
b/omega/omega-transport/omega-transport-servicecomb/src/main/java/org/apache/servicecomb/saga/omega/transport/servicecomb/SagaProviderHandler.java
index 73a7394..a3a72b6 100644
--- 
a/omega/omega-transport/omega-transport-servicecomb/src/main/java/org/apache/servicecomb/saga/omega/transport/servicecomb/SagaProviderHandler.java
+++ 
b/omega/omega-transport/omega-transport-servicecomb/src/main/java/org/apache/servicecomb/saga/omega/transport/servicecomb/SagaProviderHandler.java
@@ -36,19 +36,24 @@ public class SagaProviderHandler implements Handler {
   private static final Logger LOG = 
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
   private final OmegaContext omegaContext;
 
-  @Autowired
-  public SagaProviderHandler(OmegaContext omegaContext) {
+  public SagaProviderHandler(@Autowired(required=false) OmegaContext 
omegaContext) {
     this.omegaContext = omegaContext;
+    if (omegaContext == null) {
+      LOG.info("The OmegaContext is not injected, The SagaProviderHander is 
disabled.");
+    }
   }
 
   @Override
   public void handle(Invocation invocation, AsyncResponse asyncResponse) 
throws Exception {
-    String globalTxId = invocation.getContext().get(GLOBAL_TX_ID_KEY);
-    if (globalTxId == null) {
-      LOG.debug("no such header: {}", GLOBAL_TX_ID_KEY);
-    } else {
-      omegaContext.setGlobalTxId(globalTxId);
-      omegaContext.setLocalTxId(invocation.getContext().get(LOCAL_TX_ID_KEY));
+    if (omegaContext != null) {
+      String globalTxId = invocation.getContext().get(GLOBAL_TX_ID_KEY);
+      if (globalTxId == null) {
+        LOG.debug("no such header: {}", GLOBAL_TX_ID_KEY);
+      } else {
+
+        omegaContext.setGlobalTxId(globalTxId);
+        
omegaContext.setLocalTxId(invocation.getContext().get(LOCAL_TX_ID_KEY));
+      }
     }
 
     invocation.next(asyncResponse);

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

Reply via email to