Skip to content

Commit

Permalink
1. fix tccJdk proxy bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
changming.xie committed Mar 1, 2020
1 parent 7dc1307 commit 8af67fc
Show file tree
Hide file tree
Showing 36 changed files with 84 additions and 165 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>org.mengyun</groupId>
<artifactId>tcc-transaction</artifactId>
<packaging>pom</packaging>
<version>1.2.11</version>
<version>1.2.12</version>

<modules>
<module>tcc-transaction-api</module>
Expand Down
2 changes: 1 addition & 1 deletion tcc-transaction-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>tcc-transaction</artifactId>
<groupId>org.mengyun</groupId>
<version>1.2.11</version>
<version>1.2.12</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion tcc-transaction-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>tcc-transaction</artifactId>
<groupId>org.mengyun</groupId>
<version>1.2.11</version>
<version>1.2.12</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion tcc-transaction-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>tcc-transaction</artifactId>
<groupId>org.mengyun</groupId>
<version>1.2.11</version>
<version>1.2.12</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion tcc-transaction-dubbo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>tcc-transaction</artifactId>
<groupId>org.mengyun</groupId>
<version>1.2.11</version>
<version>1.2.12</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
/*
* Copyright 1999-2011 Alibaba Group.
*
* Licensed 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.mengyun.tcctransaction.dubbo.proxy.javassist;

import org.apache.dubbo.common.utils.ClassHelper;
Expand All @@ -27,12 +12,6 @@
import java.util.*;
import java.util.concurrent.atomic.AtomicLong;

/**
* TccProxy.
*
* @author qian.lei
*/

public abstract class TccProxy {
private static final AtomicLong PROXY_CLASS_COUNTER = new AtomicLong(0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,19 @@ public Object proceed() throws Throwable {

@Override
public Object proceed(Object[] objects) throws Throwable {
throw new UnsupportedOperationException();

// Use reflection to invoke the method.
try {
ReflectionUtils.makeAccessible(method);
return method.invoke(target, objects);
} catch (InvocationTargetException ex) {
throw ex.getTargetException();
} catch (IllegalArgumentException ex) {
throw new SystemException("Tried calling method [" +
method + "] on target [" + target + "] failed", ex);
} catch (IllegalAccessException ex) {
throw new SystemException("Could not access method [" + method + "]", ex);
}
}

public String toShortString() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd">

<dubbo:provider proxy="tccJavassist"/>
<dubbo:provider proxy="tccJavassist"/>
</beans>
4 changes: 2 additions & 2 deletions tcc-transaction-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
<parent>
<artifactId>tcc-transaction</artifactId>
<groupId>org.mengyun</groupId>
<version>1.2.11</version>
<version>1.2.12</version>
</parent>

<modelVersion>4.0.0</modelVersion>
<artifactId>tcc-transaction-server</artifactId>
<version>1.2.11</version>
<version>1.2.12</version>

<packaging>war</packaging>
<name>tcc-transaction-server</name>
Expand Down
2 changes: 1 addition & 1 deletion tcc-transaction-spring/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>tcc-transaction</artifactId>
<groupId>org.mengyun</groupId>
<version>1.2.11</version>
<version>1.2.12</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion tcc-transaction-tutorial-sample/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>tcc-transaction</artifactId>
<groupId>org.mengyun</groupId>
<version>1.2.11</version>
<version>1.2.12</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>tcc-transaction-tutorial-sample</artifactId>
<groupId>org.mengyun</groupId>
<version>1.2.11</version>
<version>1.2.12</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>tcc-transaction-dubbo-sample</artifactId>
<groupId>org.mengyun</groupId>
<version>1.2.11</version>
<version>1.2.12</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>tcc-transaction-dubbo-sample</artifactId>
<groupId>org.mengyun</groupId>
<version>1.2.11</version>
<version>1.2.12</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

<dubbo:application name="sample-dubbo-capital"/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>tcc-transaction-dubbo-sample</artifactId>
<groupId>org.mengyun</groupId>
<version>1.2.11</version>
<version>1.2.12</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ public class PaymentServiceImpl {
OrderRepository orderRepository;

@Compensable(confirmMethod = "confirmMakePayment", cancelMethod = "cancelMakePayment", asyncConfirm = false, delayCancelExceptions = {SocketTimeoutException.class, org.apache.dubbo.remoting.TimeoutException.class})
public void makePayment(@UniqueIdentity String orderNo, Order order, BigDecimal redPacketPayAmount, BigDecimal capitalPayAmount) {
public void makePayment(@UniqueIdentity String orderNo, BigDecimal redPacketPayAmount, BigDecimal capitalPayAmount) {
System.out.println("order try make payment called.time seq:" + DateFormatUtils.format(Calendar.getInstance(), "yyyy-MM-dd HH:mm:ss"));

Order order = orderRepository.findByMerchantOrderNo(orderNo);
//check if the order status is DRAFT, if no, means that another call makePayment for the same order happened, ignore this call makePayment.
if (order.getStatus().equals("DRAFT")) {
order.pay(redPacketPayAmount, capitalPayAmount);
Expand All @@ -50,7 +51,7 @@ public void makePayment(@UniqueIdentity String orderNo, Order order, BigDecimal
String result2 = redPacketTradeOrderService.record(buildRedPacketTradeOrderDto(order));
}

public void confirmMakePayment(String orderNo, Order order, BigDecimal redPacketPayAmount, BigDecimal capitalPayAmount) {
public void confirmMakePayment(String orderNo, BigDecimal redPacketPayAmount, BigDecimal capitalPayAmount) {


try {
Expand All @@ -61,16 +62,16 @@ public void confirmMakePayment(String orderNo, Order order, BigDecimal redPacket

System.out.println("order confirm make payment called. time seq:" + DateFormatUtils.format(Calendar.getInstance(), "yyyy-MM-dd HH:mm:ss"));

Order foundOrder = orderRepository.findByMerchantOrderNo(order.getMerchantOrderNo());
Order foundOrder = orderRepository.findByMerchantOrderNo(orderNo);

//check if the trade order status is PAYING, if no, means another call confirmMakePayment happened, return directly, ensure idempotency.
if (foundOrder != null && foundOrder.getStatus().equals("PAYING")) {
order.confirm();
orderRepository.updateOrder(order);
foundOrder.confirm();
orderRepository.updateOrder(foundOrder);
}
}

public void cancelMakePayment(String orderNo, Order order, BigDecimal redPacketPayAmount, BigDecimal capitalPayAmount) {
public void cancelMakePayment(String orderNo, BigDecimal redPacketPayAmount, BigDecimal capitalPayAmount) {

try {
Thread.sleep(1000l);
Expand All @@ -80,12 +81,12 @@ public void cancelMakePayment(String orderNo, Order order, BigDecimal redPacketP

System.out.println("order cancel make payment called.time seq:" + DateFormatUtils.format(Calendar.getInstance(), "yyyy-MM-dd HH:mm:ss"));

Order foundOrder = orderRepository.findByMerchantOrderNo(order.getMerchantOrderNo());
Order foundOrder = orderRepository.findByMerchantOrderNo(orderNo);

//check if the trade order status is PAYING, if no, means another call cancelMakePayment happened, return directly, ensure idempotency.
if (foundOrder != null && foundOrder.getStatus().equals("PAYING")) {
order.cancelPayment();
orderRepository.updateOrder(order);
foundOrder.cancelPayment();
orderRepository.updateOrder(foundOrder);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public String placeOrder(long payerUserId, long shopId, List<Pair<Long, Integer>
// Future future1 = executorService.submit(new Runnable() {
// @Override
// public void run() {
paymentService.makePayment(order.getMerchantOrderNo(), order, redPacketPayAmount, order.getTotalAmount().subtract(redPacketPayAmount));
paymentService.makePayment(order.getMerchantOrderNo(), redPacketPayAmount, order.getTotalAmount().subtract(redPacketPayAmount));
// }
// });

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">

xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

<context:property-placeholder location="classpath:sample-dubbo-order.properties"/>

Expand All @@ -20,15 +14,19 @@
timeout="${zookeeper.connect.timeout}"/>

<dubbo:reference id="captialTradeOrderService"
interface="org.mengyun.tcctransaction.sample.dubbo.capital.api.CapitalTradeOrderService" timeout="60000"/>
interface="org.mengyun.tcctransaction.sample.dubbo.capital.api.CapitalTradeOrderService"
timeout="60000"/>

<dubbo:reference id="redPacketTradeOrderService"
interface="org.mengyun.tcctransaction.sample.dubbo.redpacket.api.RedPacketTradeOrderService" timeout="60000"/>
interface="org.mengyun.tcctransaction.sample.dubbo.redpacket.api.RedPacketTradeOrderService"
timeout="60000"/>

<dubbo:reference id="redPacketAccountService"
interface="org.mengyun.tcctransaction.sample.dubbo.redpacket.api.RedPacketAccountService" timeout="60000"/>
interface="org.mengyun.tcctransaction.sample.dubbo.redpacket.api.RedPacketAccountService"
timeout="60000"/>

<dubbo:reference id="capitalAccountService"
interface="org.mengyun.tcctransaction.sample.dubbo.capital.api.CapitalAccountService" timeout="60000"/>
interface="org.mengyun.tcctransaction.sample.dubbo.capital.api.CapitalAccountService"
timeout="60000"/>

</beans>
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>tcc-transaction-dubbo-sample</artifactId>
<groupId>org.mengyun</groupId>
<version>1.2.11</version>
<version>1.2.12</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>tcc-transaction-dubbo-sample</artifactId>
<groupId>org.mengyun</groupId>
<version>1.2.11</version>
<version>1.2.12</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">


<context:component-scan base-package="org.mengyun.tcctransaction.sample.dubbo"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>tcc-transaction-tutorial-sample</artifactId>
<groupId>org.mengyun</groupId>
<version>1.2.11</version>
<version>1.2.12</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>tcc-transaction-http-sample</artifactId>
<groupId>org.mengyun</groupId>
<version>1.2.11</version>
<version>1.2.12</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>tcc-transaction-http-sample</artifactId>
<groupId>org.mengyun</groupId>
<version>1.2.11</version>
<version>1.2.12</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand All @@ -30,17 +30,6 @@
<version>${project.version}</version>
</dependency>

<!--<dependency>-->
<!--<groupId>com.101tec</groupId>-->
<!--<artifactId>zkclient</artifactId>-->
<!--</dependency>-->

<!--<dependency>-->
<!--<groupId>com.alibaba</groupId>-->
<!--<artifactId>dubbo</artifactId>-->
<!--</dependency>-->


<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
Expand Down
Loading

0 comments on commit 8af67fc

Please sign in to comment.