Skip to content

Commit

Permalink
SCB-571 reformate the code of omega-transport-dubbo
Browse files Browse the repository at this point in the history
  • Loading branch information
WillemJiang committed May 10, 2018
1 parent 287a0ef commit 944e745
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,27 @@

/**
* 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
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;
Expand All @@ -31,33 +32,33 @@

/**
* 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;
}
}

0 comments on commit 944e745

Please sign in to comment.