Skip to content

Commit

Permalink
fix dubbo rpc offline npe issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
changmingxie committed Mar 4, 2022
1 parent 1020697 commit 789d4b7
Show file tree
Hide file tree
Showing 12 changed files with 57 additions and 23 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<properties>

<java.version>1.8</java.version>
<revision>1.8.0</revision>
<revision>1.8.1</revision>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.target>${java.version}</maven.compiler.target>
<maven.compiler.source>${java.version}</maven.compiler.source>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.aspectj.lang.reflect.MethodSignature;
import org.mengyun.tcctransaction.api.Compensable;
import org.mengyun.tcctransaction.api.TransactionContextEditor;
import org.mengyun.tcctransaction.utils.ReflectionUtils;

import java.lang.reflect.Method;

Expand All @@ -13,10 +14,14 @@ public class AspectJTransactionMethodJoinPoint implements TransactionMethodJoinP
Compensable compensable;
Class<? extends TransactionContextEditor> transactionContextEditorClass;

private Class declaredClass = null;

public AspectJTransactionMethodJoinPoint(ProceedingJoinPoint pjp, Compensable compensable, Class<? extends TransactionContextEditor> transactionContextEditorClass) {
this.pjp = pjp;
this.compensable = compensable;
this.transactionContextEditorClass = transactionContextEditorClass;

declaredClass = ReflectionUtils.getDeclaringType(pjp.getTarget().getClass(), getMethod().getName(), getMethod().getParameterTypes());
}

@Override
Expand All @@ -29,6 +34,11 @@ public Class<? extends TransactionContextEditor> getTransactionContextEditorClas
return transactionContextEditorClass;
}

@Override
public Class<?> getDeclaredClass() {
return declaredClass;
}

@Override
public Method getMethod() {
return ((MethodSignature) pjp.getSignature()).getMethod();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ public ParticipantRole getParticipantRole() {
return ParticipantRole.NORMAL;
}


public Object proceed() throws Throwable {
return this.pjp.proceed();
}
Expand All @@ -124,4 +123,12 @@ public String getConfirmMethodName() {
public String getCancelMethodName() {
return compensable == null ? pjp.getMethod().getName() : compensable.cancelMethod();
}

public Class<?> getDeclaredClass() {
return pjp.getDeclaredClass();
}

public Object[] getArgs() {
return pjp.getArgs();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import org.mengyun.tcctransaction.TransactionManager;
import org.mengyun.tcctransaction.api.*;
import org.mengyun.tcctransaction.support.FactoryBuilder;
import org.mengyun.tcctransaction.utils.ReflectionUtils;

/**
* Created by changmingxie on 11/8/15.
Expand Down Expand Up @@ -63,15 +62,15 @@ private Participant enlistParticipant(TransactionMethodJoinPoint pjp) {

TransactionXid xid = new TransactionXid(transaction.getXid().getGlobalTransactionId());

Class targetClass = ReflectionUtils.getDeclaringType(pjp.getTarget().getClass(), compensableMethodContext.getMethod().getName(), compensableMethodContext.getMethod().getParameterTypes());
Class targetClass = compensableMethodContext.getDeclaredClass();

InvocationContext confirmInvocation = new InvocationContext(targetClass,
confirmMethodName,
compensableMethodContext.getMethod().getParameterTypes(), pjp.getArgs());
compensableMethodContext.getMethod().getParameterTypes(), compensableMethodContext.getArgs());

InvocationContext cancelInvocation = new InvocationContext(targetClass,
cancelMethodName,
compensableMethodContext.getMethod().getParameterTypes(), pjp.getArgs());
compensableMethodContext.getMethod().getParameterTypes(), compensableMethodContext.getArgs());

Participant participant =
new Participant(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public interface TransactionMethodJoinPoint {

Class<? extends TransactionContextEditor> getTransactionContextEditorClass();

Class<?> getDeclaredClass();

Method getMethod();

Object getTarget();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package org.mengyun.tcctransaction.dubbo.filter;

import org.apache.dubbo.rpc.Constants;
import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.model.ConsumerMethodModel;
import org.apache.dubbo.rpc.model.ConsumerModel;
import org.mengyun.tcctransaction.SystemException;
import org.mengyun.tcctransaction.api.Compensable;
import org.mengyun.tcctransaction.api.TransactionContextEditor;
import org.mengyun.tcctransaction.interceptor.TransactionMethodJoinPoint;
import org.mengyun.tcctransaction.support.FactoryBuilder;

import java.lang.reflect.Method;

Expand All @@ -18,11 +17,22 @@ public class DubboInvokeProceedingJoinPoint implements TransactionMethodJoinPoin
Compensable compensable;
Class<? extends TransactionContextEditor> transactionContextEditorClass;

private Method method = null;
private Object target;

public DubboInvokeProceedingJoinPoint(Invoker invoker, Invocation invocation, Compensable compensable, Class<? extends TransactionContextEditor> transactionContextEditorClass) {
this.invoker = invoker;
this.invocation = invocation;
this.compensable = compensable;
this.transactionContextEditorClass = transactionContextEditorClass;

try {
method = invoker.getInterface().getMethod(invocation.getMethodName(), invocation.getParameterTypes());
} catch (NoSuchMethodException e) {
throw new SystemException(e);
}

target = FactoryBuilder.factoryOf(getDeclaredClass()).getInstance();
}

@Override
Expand All @@ -35,19 +45,19 @@ public Class<? extends TransactionContextEditor> getTransactionContextEditorClas
return transactionContextEditorClass;
}

@Override
public Class<?> getDeclaredClass() {
return invoker.getInterface();
}

@Override
public Method getMethod() {
// try {
// return getTargetClass().getMethod(invocation.getMethodName(), invocation.getParameterTypes());
// } catch (NoSuchMethodException e) {
// throw new SystemException(e);
// }
return ((ConsumerMethodModel) invocation.getAttributes().get(Constants.METHOD_MODEL)).getMethod();
return method;
}

@Override
public Object getTarget() {
return ((ConsumerModel) invocation.getAttributes().get(Constants.CONSUMER_MODEL)).getProxyObject();
return target;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ dubbo.registry.address=zookeeper://127.0.0.1:2181
dubbo.consumer.timeout=600000
dubbo.scan.base-packages=org.tcctransaction.sample.multiple.tier.pay.account
dubbo.protocol.name=dubbo
dubbo.protocol.port=20885
#dubbo.protocol.port=20885
dubbo.protocol.port=-1
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ dubbo.registry.address=zookeeper://127.0.0.1:2181
dubbo.consumer.timeout=600000
dubbo.scan.base-packages=org.tcctransaction.sample.multiple.tier.pay.point
dubbo.protocol.name=dubbo
dubbo.protocol.port=20886
#dubbo.protocol.port=20886
dubbo.protocol.port=-1
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ dubbo.registry.address=zookeeper://127.0.0.1:2181
dubbo.consumer.timeout=600000
dubbo.scan.base-packages=org.tcctransaction.sample.multiple.tier.pay
dubbo.protocol.name=dubbo
dubbo.protocol.port=20884
#dubbo.protocol.port=20884
dubbo.protocol.port=-1
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ dubbo.registry.address=zookeeper://127.0.0.1:2181
dubbo.consumer.timeout=600000
dubbo.scan.base-packages=org.tcctransaction.sample.multiple.tier.trade.order
dubbo.protocol.name=dubbo
dubbo.protocol.port=20882
#dubbo.protocol.port=20882
dubbo.protocol.port=-1
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ dubbo.registry.address=zookeeper://127.0.0.1:2181
dubbo.consumer.timeout=600000
dubbo.scan.base-packages=org.tcctransaction.sample.multiple.tier.trade.point
dubbo.protocol.name=dubbo
dubbo.protocol.port=20883
#dubbo.protocol.port=20883
dubbo.protocol.port=-1
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
spring.application.name=trade
server.port=8881
#server.port=8881


dubbo.registry.address=zookeeper://127.0.0.1:2181
dubbo.consumer.timeout=1200000

dubbo.protocol.name=dubbo
dubbo.protocol.port=20881
#dubbo.protocol.port=20881
dubbo.protocol.port=-1

0 comments on commit 789d4b7

Please sign in to comment.