From 4473b28a0bd65a92ca2ca5881e6173e766b6af2c Mon Sep 17 00:00:00 2001
From: Administrator <549477611@qq.com>
Date: Wed, 17 Apr 2019 12:49:11 +0800
Subject: [PATCH] 2.0.1
---
pom.xml | 11 +-
raincat-annotation/pom.xml | 30 ++++
.../raincat/annotation}/PropagationEnum.java | 2 +-
.../raincat/annotation/RaincatSPI.java | 42 +++++
.../raincat}/annotation/TxTransaction.java | 20 +--
raincat-common/pom.xml | 5 +-
.../common/bean/TxTransactionInfo.java | 2 +-
.../common/holder/CollectionUtils.java | 49 ++++++
.../common/holder/ServiceBootstrap.java | 44 ------
.../holder/extension/ExtensionLoader.java | 80 ++++++++++
.../holder/extension/ServiceBootstrap.java | 59 +++++++
.../common/serializer/HessianSerializer.java | 2 +
.../common/serializer/JavaSerializer.java | 12 +-
.../common/serializer/KryoSerializer.java | 15 +-
.../common/serializer/ObjectSerializer.java | 30 ++--
.../serializer/ProtostuffSerializer.java | 13 +-
.../holder/httpclient/OkHttpToolsTest.java | 112 -------------
.../holder/httpclient/SerializeTest.java | 92 -----------
.../holder/httpclient/ThreadLocalMapTest.java | 26 ---
raincat-core/pom.xml | 148 ++++++++++--------
.../impl/TxCompensationServiceImpl.java | 2 +-
.../AbstractTxTransactionAspect.java | 21 ++-
.../raincat/core/mediator/RpcAcquire.java | 34 ++++
.../raincat/core/mediator/RpcMediator.java | 61 ++++++++
.../raincat/core/mediator/RpcTransmit.java | 35 +++++
.../handler/NettyClientMessageHandler.java | 2 +-
.../service/AspectTransactionService.java | 12 +-
.../impl/AspectTransactionServiceImpl.java | 4 +-
.../core/service/impl/InitServiceImpl.java | 37 +----
.../core/service/impl/TxManagerLocator.java | 2 +-
.../spi/TransactionRecoverRepository.java | 10 +-
.../FileTransactionRecoverRepository.java | 10 +-
.../JdbcTransactionRecoverRepository.java | 10 +-
.../MongoTransactionRecoverRepository.java | 11 +-
.../RedisTransactionRecoverRepository.java | 8 +-
...ZookeeperTransactionRecoverRepository.java | 10 +-
.../raincat/core/AtomicReferenceTest.java | 22 ---
.../core/concurrent/task/BlockTaskTest.java | 22 ---
.../core/mongodb/MongoDbConnectDatabase.java | 61 --------
.../core/spi/ServiceBootstrapTest.java | 64 --------
...raincat.common.serializer.ObjectSerializer | 4 -
...ncat.core.spi.TransactionRecoverRepository | 5 -
raincat-dubbo/pom.xml | 23 +--
.../filter/DubboTxTransactionFilter.java | 5 +-
.../DubboTxTransactionInterceptor.java | 11 +-
raincat-motan/pom.xml | 34 ++--
.../filter/MotanTxTransactionFilter.java | 3 +-
.../MotanTxTransactionInterceptor.java | 10 +-
raincat-sample/pom.xml | 101 +++++++++++-
raincat-sample/raincat-dubbo-sample/pom.xml | 24 +++
.../raincat-dubbo-sample-consume/pom.xml | 2 +
.../raincat-springcloud-sample/pom.xml | 16 ++
.../sample/pay/client/MyConfiguration.java | 4 +-
.../pay/service/impl/PayServiceImpl.java | 5 -
raincat-springcloud/pom.xml | 40 +++--
.../RaincatFeignConfiguration.java} | 26 ++-
...ptor.java => RaincatFeignInterceptor.java} | 8 +-
.../RaincatHystrixConcurrencyStrategy.java | 107 +++++++++++++
.../SpringCloudTxTransactionAspect.java | 6 +
.../SpringCloudTxTransactionInterceptor.java | 6 +-
.../SpringCloudRpcApplicationServiceImpl.java | 14 +-
61 files changed, 942 insertions(+), 744 deletions(-)
create mode 100644 raincat-annotation/pom.xml
rename {raincat-common/src/main/java/org/dromara/raincat/common/enums => raincat-annotation/src/main/java/org/dromara/raincat/annotation}/PropagationEnum.java (97%)
create mode 100644 raincat-annotation/src/main/java/org/dromara/raincat/annotation/RaincatSPI.java
rename {raincat-core/src/main/java/org/dromara/raincat/core => raincat-annotation/src/main/java/org/dromara/raincat}/annotation/TxTransaction.java (77%)
create mode 100644 raincat-common/src/main/java/org/dromara/raincat/common/holder/CollectionUtils.java
delete mode 100644 raincat-common/src/main/java/org/dromara/raincat/common/holder/ServiceBootstrap.java
create mode 100644 raincat-common/src/main/java/org/dromara/raincat/common/holder/extension/ExtensionLoader.java
create mode 100644 raincat-common/src/main/java/org/dromara/raincat/common/holder/extension/ServiceBootstrap.java
delete mode 100644 raincat-common/src/test/java/org/dromara/raincat/common/holder/httpclient/OkHttpToolsTest.java
delete mode 100644 raincat-common/src/test/java/org/dromara/raincat/common/holder/httpclient/SerializeTest.java
delete mode 100644 raincat-common/src/test/java/org/dromara/raincat/common/holder/httpclient/ThreadLocalMapTest.java
create mode 100644 raincat-core/src/main/java/org/dromara/raincat/core/mediator/RpcAcquire.java
create mode 100644 raincat-core/src/main/java/org/dromara/raincat/core/mediator/RpcMediator.java
create mode 100644 raincat-core/src/main/java/org/dromara/raincat/core/mediator/RpcTransmit.java
delete mode 100644 raincat-core/src/test/java/org/dromara/raincat/core/AtomicReferenceTest.java
delete mode 100644 raincat-core/src/test/java/org/dromara/raincat/core/concurrent/task/BlockTaskTest.java
delete mode 100644 raincat-core/src/test/java/org/dromara/raincat/core/mongodb/MongoDbConnectDatabase.java
delete mode 100644 raincat-core/src/test/java/org/dromara/raincat/core/spi/ServiceBootstrapTest.java
delete mode 100644 raincat-core/src/test/resources/META-INF/services/com.raincat.common.serializer.ObjectSerializer
delete mode 100644 raincat-core/src/test/resources/META-INF/services/com.raincat.core.spi.TransactionRecoverRepository
rename raincat-springcloud/src/main/java/org/dromara/raincat/springcloud/{feign/RestTemplateConfiguration.java => configuration/RaincatFeignConfiguration.java} (52%)
rename raincat-springcloud/src/main/java/org/dromara/raincat/springcloud/feign/{RestTemplateInterceptor.java => RaincatFeignInterceptor.java} (75%)
create mode 100644 raincat-springcloud/src/main/java/org/dromara/raincat/springcloud/hystrix/RaincatHystrixConcurrencyStrategy.java
diff --git a/pom.xml b/pom.xml
index 2674ea2..7697cf1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,6 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
-
org.dromara
raincat
pom
@@ -45,10 +44,10 @@
raincat-dubbo
raincat-springcloud
raincat-common
- raincat-sample
raincat-admin
raincat-motan
raincat-spring-boot-starter
+ raincat-annotation
@@ -77,7 +76,7 @@
1.8
5.0.7.RELEASE
Finchley.RELEASE
- 2.5.3
+ 2.6.2
3.5.0
5.1.40
3.3.2
@@ -107,6 +106,12 @@
${project.version}
+
+ org.dromara
+ raincat-annotation
+ ${project.version}
+
+
org.dromara
raincat-common
diff --git a/raincat-annotation/pom.xml b/raincat-annotation/pom.xml
new file mode 100644
index 0000000..7dbcdeb
--- /dev/null
+++ b/raincat-annotation/pom.xml
@@ -0,0 +1,30 @@
+
+
+
+ raincat
+ org.dromara
+ 2.0.1-RELEASE
+
+ 4.0.0
+
+ raincat-annotation
+
+
+ raincat-annotation
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+
+ ${jdk.version}
+ ${project.build.sourceEncoding}
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/raincat-common/src/main/java/org/dromara/raincat/common/enums/PropagationEnum.java b/raincat-annotation/src/main/java/org/dromara/raincat/annotation/PropagationEnum.java
similarity index 97%
rename from raincat-common/src/main/java/org/dromara/raincat/common/enums/PropagationEnum.java
rename to raincat-annotation/src/main/java/org/dromara/raincat/annotation/PropagationEnum.java
index 988cb16..e8e7046 100644
--- a/raincat-common/src/main/java/org/dromara/raincat/common/enums/PropagationEnum.java
+++ b/raincat-annotation/src/main/java/org/dromara/raincat/annotation/PropagationEnum.java
@@ -16,7 +16,7 @@
*
*/
-package org.dromara.raincat.common.enums;
+package org.dromara.raincat.annotation;
/**
* PropagationEnum.
diff --git a/raincat-annotation/src/main/java/org/dromara/raincat/annotation/RaincatSPI.java b/raincat-annotation/src/main/java/org/dromara/raincat/annotation/RaincatSPI.java
new file mode 100644
index 0000000..de9304f
--- /dev/null
+++ b/raincat-annotation/src/main/java/org/dromara/raincat/annotation/RaincatSPI.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.dromara.raincat.annotation;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * The interface Hmily spi.
+ *
+ * @author xiaoyu
+ */
+@Documented
+@Retention(RetentionPolicy.RUNTIME)
+@Target({ElementType.TYPE})
+public @interface RaincatSPI {
+
+ /**
+ * Value string.
+ *
+ * @return the string
+ */
+ String value() default "";
+}
diff --git a/raincat-core/src/main/java/org/dromara/raincat/core/annotation/TxTransaction.java b/raincat-annotation/src/main/java/org/dromara/raincat/annotation/TxTransaction.java
similarity index 77%
rename from raincat-core/src/main/java/org/dromara/raincat/core/annotation/TxTransaction.java
rename to raincat-annotation/src/main/java/org/dromara/raincat/annotation/TxTransaction.java
index 6954b7f..80df0dd 100644
--- a/raincat-core/src/main/java/org/dromara/raincat/core/annotation/TxTransaction.java
+++ b/raincat-annotation/src/main/java/org/dromara/raincat/annotation/TxTransaction.java
@@ -16,9 +16,7 @@
*
*/
-package org.dromara.raincat.core.annotation;
-
-import org.dromara.raincat.common.enums.PropagationEnum;
+package org.dromara.raincat.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
@@ -26,29 +24,31 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
- * 二阶段分布式事务注解.
+ * The interface Tx transaction.
*/
@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface TxTransaction {
+
/**
- * 事务传播.
- * @return {@linkplain PropagationEnum}
+ * Propagation propagation enum.
+ *
+ * @return the propagation enum
*/
PropagationEnum propagation() default PropagationEnum.PROPAGATION_REQUIRES_NEW;
/**
- * 事务等待的最大时间 单位秒.
+ * Wait max time int.
*
- * @return 多少秒
+ * @return the int
*/
int waitMaxTime() default 60;
/**
- * 事务管理器名称
+ * Transaction manager string.
*
- * @return 如果为空,则取默认的
+ * @return the string
*/
String transactionManager() default "";
}
diff --git a/raincat-common/pom.xml b/raincat-common/pom.xml
index bf881e3..7f37517 100644
--- a/raincat-common/pom.xml
+++ b/raincat-common/pom.xml
@@ -14,9 +14,8 @@
- junit
- junit
- test
+ org.dromara
+ raincat-annotation
diff --git a/raincat-common/src/main/java/org/dromara/raincat/common/bean/TxTransactionInfo.java b/raincat-common/src/main/java/org/dromara/raincat/common/bean/TxTransactionInfo.java
index e9326e9..83bf0aa 100644
--- a/raincat-common/src/main/java/org/dromara/raincat/common/bean/TxTransactionInfo.java
+++ b/raincat-common/src/main/java/org/dromara/raincat/common/bean/TxTransactionInfo.java
@@ -20,7 +20,7 @@ package org.dromara.raincat.common.bean;
import lombok.AllArgsConstructor;
import lombok.Getter;
-import org.dromara.raincat.common.enums.PropagationEnum;
+import org.dromara.raincat.annotation.PropagationEnum;
/**
* TxTransactionInfo.
diff --git a/raincat-common/src/main/java/org/dromara/raincat/common/holder/CollectionUtils.java b/raincat-common/src/main/java/org/dromara/raincat/common/holder/CollectionUtils.java
new file mode 100644
index 0000000..44f1476
--- /dev/null
+++ b/raincat-common/src/main/java/org/dromara/raincat/common/holder/CollectionUtils.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.dromara.raincat.common.holder;
+
+import java.util.Collection;
+
+/**
+ * The type Collection utils.
+ *
+ * @author xiaoyu(Myth)
+ */
+public class CollectionUtils {
+
+ /**
+ * Is empty boolean.
+ *
+ * @param coll the coll
+ * @return the boolean
+ */
+ public static boolean isEmpty(Collection coll) {
+ return coll == null || coll.isEmpty();
+ }
+
+ /**
+ * Is not empty boolean.
+ *
+ * @param coll the coll
+ * @return the boolean
+ */
+ public static boolean isNotEmpty(Collection coll) {
+ return !isEmpty(coll);
+ }
+}
diff --git a/raincat-common/src/main/java/org/dromara/raincat/common/holder/ServiceBootstrap.java b/raincat-common/src/main/java/org/dromara/raincat/common/holder/ServiceBootstrap.java
deleted file mode 100644
index 8532c40..0000000
--- a/raincat-common/src/main/java/org/dromara/raincat/common/holder/ServiceBootstrap.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- *
- * Copyright 2017-2018 549477611@qq.com(xiaoyu)
- *
- * This copyrighted material is made available to anyone wishing to use, modify,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * Lesser General Public License, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, see .
- *
- */
-
-package org.dromara.raincat.common.holder;
-
-import java.util.Iterator;
-import java.util.ServiceLoader;
-
-/**
- * ServiceBootstrap.
- * @author xiaoyu
- */
-public class ServiceBootstrap {
-
- public static S loadFirst(final Class clazz) {
- final ServiceLoader loader = loadAll(clazz);
- final Iterator iterator = loader.iterator();
- if (!iterator.hasNext()) {
- throw new IllegalStateException(String.format(
- "No implementation defined in /META-INF/services/%s, please check whether the file exists and has the right implementation class!",
- clazz.getName()));
- }
- return iterator.next();
- }
-
- public static ServiceLoader loadAll(final Class clazz) {
- return ServiceLoader.load(clazz);
- }
-}
diff --git a/raincat-common/src/main/java/org/dromara/raincat/common/holder/extension/ExtensionLoader.java b/raincat-common/src/main/java/org/dromara/raincat/common/holder/extension/ExtensionLoader.java
new file mode 100644
index 0000000..0e57bc3
--- /dev/null
+++ b/raincat-common/src/main/java/org/dromara/raincat/common/holder/extension/ExtensionLoader.java
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.dromara.raincat.common.holder.extension;
+
+
+import org.dromara.raincat.annotation.RaincatSPI;
+import org.dromara.raincat.common.exception.TransactionRuntimeException;
+
+import java.util.Objects;
+import java.util.ServiceLoader;
+import java.util.stream.StreamSupport;
+
+
+/**
+ * The type Extension loader.
+ *
+ * @author xiaoyu
+ */
+public final class ExtensionLoader {
+
+ private Class type;
+
+ private ExtensionLoader(final Class type) {
+ this.type = type;
+ }
+
+ private static boolean withExtensionAnnotation(final Class type) {
+ return type.isAnnotationPresent(RaincatSPI.class);
+ }
+
+ /**
+ * Gets extension loader.
+ *
+ * @param the type parameter
+ * @param type the type
+ * @return the extension loader
+ */
+ public static ExtensionLoader getExtensionLoader(final Class type) {
+ if (type == null) {
+ throw new TransactionRuntimeException("type == null");
+ }
+ if (!type.isInterface()) {
+ throw new TransactionRuntimeException("Extension type(" + type + ") not interface!");
+ }
+ if (!withExtensionAnnotation(type)) {
+ throw new TransactionRuntimeException("type" + type.getName() + "not exist");
+ }
+ return new ExtensionLoader<>(type);
+ }
+
+ /**
+ * Gets activate extension.
+ *
+ * @param value the value
+ * @return the activate extension
+ */
+ public T getActivateExtension(final String value) {
+ ServiceLoader loader = ServiceBootstrap.loadAll(type);
+ return StreamSupport.stream(loader.spliterator(), false)
+ .filter(e -> Objects.equals(e.getClass()
+ .getAnnotation(RaincatSPI.class).value(), value))
+ .findFirst().orElseThrow(() -> new TransactionRuntimeException("Please check your configuration"));
+ }
+
+}
diff --git a/raincat-common/src/main/java/org/dromara/raincat/common/holder/extension/ServiceBootstrap.java b/raincat-common/src/main/java/org/dromara/raincat/common/holder/extension/ServiceBootstrap.java
new file mode 100644
index 0000000..cc386b0
--- /dev/null
+++ b/raincat-common/src/main/java/org/dromara/raincat/common/holder/extension/ServiceBootstrap.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.dromara.raincat.common.holder.extension;
+
+import java.util.Iterator;
+import java.util.ServiceLoader;
+
+/**
+ * ServiceBootstrap.
+ *
+ * @author xiaoyu
+ */
+public class ServiceBootstrap {
+
+ /**
+ * Load first s.
+ *
+ * @param the type parameter
+ * @param clazz the clazz
+ * @return the s
+ */
+ public static S loadFirst(final Class clazz) {
+ final ServiceLoader loader = loadAll(clazz);
+ final Iterator iterator = loader.iterator();
+ if (!iterator.hasNext()) {
+ throw new IllegalStateException(String.format(
+ "No implementation defined in /META-INF/services/%s, please check whether the file exists and has the right implementation class!",
+ clazz.getName()));
+ }
+ return iterator.next();
+ }
+
+ /**
+ * Load all service loader.
+ *
+ * @param the type parameter
+ * @param clazz the clazz
+ * @return the service loader
+ */
+ public static ServiceLoader loadAll(final Class clazz) {
+ return ServiceLoader.load(clazz);
+ }
+
+}
diff --git a/raincat-common/src/main/java/org/dromara/raincat/common/serializer/HessianSerializer.java b/raincat-common/src/main/java/org/dromara/raincat/common/serializer/HessianSerializer.java
index fe435ca..b3788ac 100644
--- a/raincat-common/src/main/java/org/dromara/raincat/common/serializer/HessianSerializer.java
+++ b/raincat-common/src/main/java/org/dromara/raincat/common/serializer/HessianSerializer.java
@@ -19,6 +19,7 @@ package org.dromara.raincat.common.serializer;
import com.caucho.hessian.io.Hessian2Input;
import com.caucho.hessian.io.Hessian2Output;
+import org.dromara.raincat.annotation.RaincatSPI;
import org.dromara.raincat.common.enums.SerializeProtocolEnum;
import org.dromara.raincat.common.exception.TransactionException;
@@ -31,6 +32,7 @@ import java.io.IOException;
* @author xiaoyu
*/
@SuppressWarnings("unchecked")
+@RaincatSPI("hessian")
public class HessianSerializer implements ObjectSerializer {
@Override
diff --git a/raincat-common/src/main/java/org/dromara/raincat/common/serializer/JavaSerializer.java b/raincat-common/src/main/java/org/dromara/raincat/common/serializer/JavaSerializer.java
index 2ee7516..6594dd0 100644
--- a/raincat-common/src/main/java/org/dromara/raincat/common/serializer/JavaSerializer.java
+++ b/raincat-common/src/main/java/org/dromara/raincat/common/serializer/JavaSerializer.java
@@ -17,6 +17,7 @@
package org.dromara.raincat.common.serializer;
+import org.dromara.raincat.annotation.RaincatSPI;
import org.dromara.raincat.common.enums.SerializeProtocolEnum;
import org.dromara.raincat.common.exception.TransactionException;
@@ -33,6 +34,7 @@ import java.io.ObjectOutputStream;
* @author xiaoyu
*/
@SuppressWarnings("unchecked")
+@RaincatSPI("jdk")
public class JavaSerializer implements ObjectSerializer {
@Override
@@ -54,14 +56,4 @@ public class JavaSerializer implements ObjectSerializer {
throw new TransactionException("java deSerialize error " + e.getMessage());
}
}
-
- /**
- * 设置scheme.
- *
- * @return scheme 命名
- */
- @Override
- public String getScheme() {
- return SerializeProtocolEnum.JDK.getSerializeProtocol();
- }
}
diff --git a/raincat-common/src/main/java/org/dromara/raincat/common/serializer/KryoSerializer.java b/raincat-common/src/main/java/org/dromara/raincat/common/serializer/KryoSerializer.java
index 3f0dba7..78ff463 100644
--- a/raincat-common/src/main/java/org/dromara/raincat/common/serializer/KryoSerializer.java
+++ b/raincat-common/src/main/java/org/dromara/raincat/common/serializer/KryoSerializer.java
@@ -20,7 +20,7 @@ package org.dromara.raincat.common.serializer;
import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.io.Input;
import com.esotericsoftware.kryo.io.Output;
-import org.dromara.raincat.common.enums.SerializeProtocolEnum;
+import org.dromara.raincat.annotation.RaincatSPI;
import org.dromara.raincat.common.exception.TransactionException;
import java.io.ByteArrayInputStream;
@@ -29,15 +29,16 @@ import java.io.IOException;
/**
* KryoSerializer.
+ *
* @author xiaoyu
*/
+@RaincatSPI("kryo")
public class KryoSerializer implements ObjectSerializer {
@Override
public byte[] serialize(final Object obj) throws TransactionException {
byte[] bytes;
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); Output output = new Output(outputStream)) {
- //获取kryo对象
Kryo kryo = new Kryo();
kryo.writeObject(output, obj);
bytes = output.toBytes();
@@ -61,14 +62,4 @@ public class KryoSerializer implements ObjectSerializer {
}
return object;
}
-
- /**
- * 设置scheme.
- *
- * @return scheme 命名
- */
- @Override
- public String getScheme() {
- return SerializeProtocolEnum.KRYO.getSerializeProtocol();
- }
}
diff --git a/raincat-common/src/main/java/org/dromara/raincat/common/serializer/ObjectSerializer.java b/raincat-common/src/main/java/org/dromara/raincat/common/serializer/ObjectSerializer.java
index f44286f..0f4cb4a 100644
--- a/raincat-common/src/main/java/org/dromara/raincat/common/serializer/ObjectSerializer.java
+++ b/raincat-common/src/main/java/org/dromara/raincat/common/serializer/ObjectSerializer.java
@@ -18,39 +18,35 @@
package org.dromara.raincat.common.serializer;
+import org.dromara.raincat.annotation.RaincatSPI;
import org.dromara.raincat.common.exception.TransactionException;
/**
* ObjectSerializer.
+ *
* @author xiaoyu
*/
+@RaincatSPI
public interface ObjectSerializer {
/**
- * 序列化对象.
+ * Serialize byte [ ].
*
- * @param obj 需要序更列化的对象
- * @return byte []
- * @throws TransactionException 异常信息
+ * @param obj the obj
+ * @return the byte [ ]
+ * @throws TransactionException the transaction exception
*/
byte[] serialize(Object obj) throws TransactionException;
-
/**
- * 反序列化对象.
+ * De serialize t.
*
- * @param param 需要反序列化的byte []
- * @param clazz java对象
- * @param 泛型支持
- * @return 对象
- * @throws TransactionException 异常信息
+ * @param the type parameter
+ * @param param the param
+ * @param clazz the clazz
+ * @return the t
+ * @throws TransactionException the transaction exception
*/
T deSerialize(byte[] param, Class clazz) throws TransactionException;
- /**
- * 设置scheme.
- *
- * @return scheme 命名
- */
- String getScheme();
}
diff --git a/raincat-common/src/main/java/org/dromara/raincat/common/serializer/ProtostuffSerializer.java b/raincat-common/src/main/java/org/dromara/raincat/common/serializer/ProtostuffSerializer.java
index 7f7634a..bb93ad3 100644
--- a/raincat-common/src/main/java/org/dromara/raincat/common/serializer/ProtostuffSerializer.java
+++ b/raincat-common/src/main/java/org/dromara/raincat/common/serializer/ProtostuffSerializer.java
@@ -20,7 +20,7 @@ package org.dromara.raincat.common.serializer;
import com.dyuproject.protostuff.LinkedBuffer;
import com.dyuproject.protostuff.ProtostuffIOUtil;
import com.dyuproject.protostuff.Schema;
-import org.dromara.raincat.common.enums.SerializeProtocolEnum;
+import org.dromara.raincat.annotation.RaincatSPI;
import org.dromara.raincat.common.exception.TransactionException;
import org.objenesis.Objenesis;
import org.objenesis.ObjenesisStd;
@@ -31,9 +31,11 @@ import java.io.IOException;
/**
* ProtostuffSerializer.
+ *
* @author xiaoyu
*/
@SuppressWarnings("unchecked")
+@RaincatSPI("protostuff")
public class ProtostuffSerializer implements ObjectSerializer {
private static final SchemaCache CACHED_SCHEMA = SchemaCache.getInstance();
@@ -71,14 +73,5 @@ public class ProtostuffSerializer implements ObjectSerializer {
throw new TransactionException(e.getMessage(), e);
}
}
-
- /**
- * 设置scheme.
- * @return scheme 命名
- */
- @Override
- public String getScheme() {
- return SerializeProtocolEnum.PROTOSTUFF.getSerializeProtocol();
- }
}
diff --git a/raincat-common/src/test/java/org/dromara/raincat/common/holder/httpclient/OkHttpToolsTest.java b/raincat-common/src/test/java/org/dromara/raincat/common/holder/httpclient/OkHttpToolsTest.java
deleted file mode 100644
index 4819601..0000000
--- a/raincat-common/src/test/java/org/dromara/raincat/common/holder/httpclient/OkHttpToolsTest.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- *
- * Copyright 2017-2018 549477611@qq.com(xiaoyu)
- *
- * This copyrighted material is made available to anyone wishing to use, modify,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * Lesser General Public License, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, see .
- *
- */
-package org.dromara.raincat.common.holder.httpclient;
-
-import com.google.common.collect.Lists;
-import com.google.gson.Gson;
-import org.dromara.raincat.common.holder.IdWorkerUtils;
-import org.dromara.raincat.common.netty.bean.TxTransactionItem;
-import org.junit.Test;
-
-import java.util.List;
-import java.util.concurrent.atomic.AtomicInteger;
-
-public class OkHttpToolsTest {
-
- private static final Gson GSON = new Gson();
-
- @Test
- public void post() throws Exception {
-
- List itemList = Lists.newArrayList();
- TxTransactionItem txTransactionItem = new TxTransactionItem();
- txTransactionItem.setTaskKey(IdWorkerUtils.getInstance().createTaskKey());
- itemList.add(txTransactionItem);
- OkHttpTools.getInstance().post("http://192.168.1.66:8761/tx/manager/httpExecute",GSON.toJson(itemList));
-
- }
-
-
- @Test
- public void test01(){
- MyThread myThread = null;
- for (int i=0;i<50;i++){
- MyThread m = new MyThread("name"+i,myThread);
- m.setDaemon(true);
- m.start();
- myThread = m;
- }
- System.out.println("完成");
- }
-
- @Test
- public void test02(){
- AtomicInteger atomicInteger = new AtomicInteger();
-
- for (int i=0;i<50;i++){
- SortThread m = new SortThread("name"+i,atomicInteger,i);
- m.setDaemon(true);
- m.start();
-
- }
- System.out.println("完成");
- }
-
- class SortThread extends Thread{
-
- AtomicInteger atomicInteger ;
- Integer order ;
- public SortThread(String name,AtomicInteger atomicInteger,int order){
- super(name);
- this.atomicInteger = atomicInteger;
- this.order = order;
- }
-
- @Override
- public void run() {
- while (true) {
- System.out.println(Thread.currentThread().getName() + " " +atomicInteger.get() + " "+order);
- if (atomicInteger.get() == order) {
- System.out.println(Thread.currentThread().getName() + " 执行跳槽 " + order);
- atomicInteger.incrementAndGet();
- break;
- }
-
- }
- }
- }
-
- class MyThread extends Thread{
- Thread thread ;
- public MyThread(String name,Thread thread){
- super(name);
- this.thread = thread;
- }
- @Override
- public void run() {
- if(thread != null)
- try {
- thread.join();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- System.out.println(Thread.currentThread().getName()+" 执行。。。。。。");
- }
- }
-
-}
\ No newline at end of file
diff --git a/raincat-common/src/test/java/org/dromara/raincat/common/holder/httpclient/SerializeTest.java b/raincat-common/src/test/java/org/dromara/raincat/common/holder/httpclient/SerializeTest.java
deleted file mode 100644
index a12e05e..0000000
--- a/raincat-common/src/test/java/org/dromara/raincat/common/holder/httpclient/SerializeTest.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- *
- * Copyright 2017-2018 549477611@qq.com(xiaoyu)
- *
- * This copyrighted material is made available to anyone wishing to use, modify,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * Lesser General Public License, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, see .
- *
- */
-package org.dromara.raincat.common.holder.httpclient;
-
-import org.dromara.raincat.common.enums.NettyMessageActionEnum;
-import org.dromara.raincat.common.enums.TransactionStatusEnum;
-import org.dromara.raincat.common.holder.IdWorkerUtils;
-import org.dromara.raincat.common.netty.bean.HeartBeat;
-import org.dromara.raincat.common.netty.bean.TxTransactionGroup;
-import org.dromara.raincat.common.netty.bean.TxTransactionItem;
-import org.dromara.raincat.common.netty.serizlize.kryo.KryoPoolFactory;
-import org.dromara.raincat.common.netty.serizlize.kryo.KryoSerialize;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * @author xiaoyu
- */
-public class SerializeTest {
-
- private static final int MAX=1000;
-
- public static void main(String[] args) throws IOException {
- final long start = System.currentTimeMillis();
- for (int i = 0; i items = new ArrayList<>(2);
- //tmManager 用redis hash 结构来存储 整个事务组的状态做为hash结构的第一条数据
- TxTransactionItem groupItem = new TxTransactionItem();
- //整个事务组状态为开始
- groupItem.setStatus(TransactionStatusEnum.BEGIN.getCode());
- //设置事务id为组的id 即为 hashKey
- groupItem.setTransId(groupId);
- groupItem.setTaskKey(groupId);
- items.add(groupItem);
- TxTransactionItem item = new TxTransactionItem();
- item.setTaskKey(IdWorkerUtils.getInstance().createTaskKey());
- item.setTransId(IdWorkerUtils.getInstance().createUUID());
- item.setStatus(TransactionStatusEnum.BEGIN.getCode());
- items.add(item);
- txTransactionGroup.setItemList(items);
-
-
- HeartBeat heartBeat = new HeartBeat();
- heartBeat.setAction(NettyMessageActionEnum.HEART.getCode());
- heartBeat.setTxTransactionGroup(txTransactionGroup);
-
- kryoSerialization.serialize(byteArrayOutputStream, heartBeat);
-
-
- byte[] body = byteArrayOutputStream.toByteArray();
-
-
- ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(body);
-
- final HeartBeat heartBeat1 = (HeartBeat)
- kryoSerialization.deserialize(byteArrayInputStream);
-
- }
- final long end = System.currentTimeMillis();
-
- System.out.println((end-start)/1000);
-
-
-
-
- }
-}
diff --git a/raincat-common/src/test/java/org/dromara/raincat/common/holder/httpclient/ThreadLocalMapTest.java b/raincat-common/src/test/java/org/dromara/raincat/common/holder/httpclient/ThreadLocalMapTest.java
deleted file mode 100644
index ed377f9..0000000
--- a/raincat-common/src/test/java/org/dromara/raincat/common/holder/httpclient/ThreadLocalMapTest.java
+++ /dev/null
@@ -1,26 +0,0 @@
-package org.dromara.raincat.common.holder.httpclient;
-
-/**
- * Description: .
- *
- * @author xiaoyu(Myth)
- * @version 1.0
- * @date 2018/2/5 10:53
- * @since JDK 1.8
- */
-public class ThreadLocalMapTest {
-
- public static void main(String[] args) {
-
- ThreadLocal A = new ThreadLocal();
-
- ThreadLocal B = new ThreadLocal();
-
- for(int i = 0 ;i<10 ;i++){
- A.set("3");
- B.set("4");
- }
-
- }
-
-}
diff --git a/raincat-core/pom.xml b/raincat-core/pom.xml
index d0f345c..3bf8011 100644
--- a/raincat-core/pom.xml
+++ b/raincat-core/pom.xml
@@ -6,7 +6,6 @@
raincat
org.dromara
2.0.1-RELEASE
- ../pom.xml
4.0.0
@@ -21,75 +20,12 @@
org.dromara
raincat-common
-
- junit
- junit
- 4.12
-
-
- org.springframework
- spring-test
- test
-
-
- org.springframework
- spring-jdbc
-
-
- org.mockito
- mockito-all
- 1.10.8
- test
-
-
- org.powermock
- powermock-api-mockito
- 1.6.1
- test
-
-
- org.powermock
- powermock-module-junit4
- 1.6.1
- test
-
-
- com.lmax
- disruptor
-
-
- org.mongodb
- mongo-java-driver
-
-
- org.aspectj
- aspectjweaver
-
-
- com.caucho
- hessian
-
-
- org.apache.zookeeper
- zookeeper
- 3.4.6
-
io.netty
netty-all
-
- redis.clients
- jedis
-
-
-
- org.springframework.data
- spring-data-mongodb
-
-
com.alibaba
druid
@@ -99,14 +35,90 @@
org.apache.commons
commons-lang3
+
- commons-beanutils
- commons-beanutils
+ org.springframework
+ spring-jdbc
+ provided
+
+
+
+ org.springframework
+ spring-aop
+ provided
- commons-codec
- commons-codec
+ org.springframework
+ spring-aspects
+ provided
+
+
+ org.springframework
+ spring-beans
+ provided
+
+
+ org.springframework
+ spring-context
+ provided
+
+
+ org.springframework
+ spring-context-support
+ provided
+
+
+ org.springframework
+ spring-core
+ provided
+
+
+ org.springframework
+ spring-tx
+ provided
+
+
+
+ org.springframework.data
+ spring-data-mongodb
+ provided
+
+
+
+ org.aspectj
+ aspectjweaver
+
+
+
+ org.apache.zookeeper
+ zookeeper
+
+
+ org.slf4j
+ slf4j-log4j12
+
+
+
+
+
+ com.lmax
+ disruptor
+
+
+ raincat-core
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+
+ ${jdk.version}
+ ${project.build.sourceEncoding}
+
+
+
+
\ No newline at end of file
diff --git a/raincat-core/src/main/java/org/dromara/raincat/core/compensation/impl/TxCompensationServiceImpl.java b/raincat-core/src/main/java/org/dromara/raincat/core/compensation/impl/TxCompensationServiceImpl.java
index 105affa..83e9004 100644
--- a/raincat-core/src/main/java/org/dromara/raincat/core/compensation/impl/TxCompensationServiceImpl.java
+++ b/raincat-core/src/main/java/org/dromara/raincat/core/compensation/impl/TxCompensationServiceImpl.java
@@ -18,7 +18,6 @@
package org.dromara.raincat.core.compensation.impl;
-import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.reflect.MethodUtils;
import org.dromara.raincat.common.bean.TransactionInvocation;
import org.dromara.raincat.common.bean.TransactionRecover;
@@ -26,6 +25,7 @@ import org.dromara.raincat.common.config.TxConfig;
import org.dromara.raincat.common.constant.CommonConstant;
import org.dromara.raincat.common.enums.CompensationOperationTypeEnum;
import org.dromara.raincat.common.enums.TransactionStatusEnum;
+import org.dromara.raincat.common.holder.CollectionUtils;
import org.dromara.raincat.common.holder.LogUtil;
import org.dromara.raincat.common.netty.bean.TxTransactionGroup;
import org.dromara.raincat.common.netty.bean.TxTransactionItem;
diff --git a/raincat-core/src/main/java/org/dromara/raincat/core/interceptor/AbstractTxTransactionAspect.java b/raincat-core/src/main/java/org/dromara/raincat/core/interceptor/AbstractTxTransactionAspect.java
index 5784f7e..502ed2c 100644
--- a/raincat-core/src/main/java/org/dromara/raincat/core/interceptor/AbstractTxTransactionAspect.java
+++ b/raincat-core/src/main/java/org/dromara/raincat/core/interceptor/AbstractTxTransactionAspect.java
@@ -25,6 +25,7 @@ import org.aspectj.lang.annotation.Pointcut;
/**
* AbstractTxTransactionAspect.
+ *
* @author xiaoyu
*/
@Aspect
@@ -32,15 +33,30 @@ public abstract class AbstractTxTransactionAspect {
private TxTransactionInterceptor txTransactionInterceptor;
+ /**
+ * Sets tx transaction interceptor.
+ *
+ * @param txTransactionInterceptor the tx transaction interceptor
+ */
public void setTxTransactionInterceptor(final TxTransactionInterceptor txTransactionInterceptor) {
this.txTransactionInterceptor = txTransactionInterceptor;
}
- @Pointcut("@annotation(org.dromara.raincat.core.annotation.TxTransaction)")
+ /**
+ * Tx transaction interceptor.
+ */
+ @Pointcut("@annotation(org.dromara.raincat.annotation.TxTransaction)")
public void txTransactionInterceptor() {
}
+ /**
+ * Intercept tx transaction object.
+ *
+ * @param proceedingJoinPoint the proceeding join point
+ * @return the object
+ * @throws Throwable the throwable
+ */
@Around("txTransactionInterceptor()")
public Object interceptTxTransaction(final ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
return txTransactionInterceptor.interceptor(proceedingJoinPoint);
@@ -48,7 +64,8 @@ public abstract class AbstractTxTransactionAspect {
/**
* spring bean order.
- * @return order
+ *
+ * @return order order
*/
public abstract int getOrder();
}
diff --git a/raincat-core/src/main/java/org/dromara/raincat/core/mediator/RpcAcquire.java b/raincat-core/src/main/java/org/dromara/raincat/core/mediator/RpcAcquire.java
new file mode 100644
index 0000000..a66d329
--- /dev/null
+++ b/raincat-core/src/main/java/org/dromara/raincat/core/mediator/RpcAcquire.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.dromara.raincat.core.mediator;
+
+/**
+ * The interface Rpc acquire.
+ *
+ * @author xiaoyu(Myth)
+ */
+public interface RpcAcquire {
+
+ /**
+ * Acquire string.
+ *
+ * @param key the key
+ * @return the string
+ */
+ String acquire(String key);
+}
diff --git a/raincat-core/src/main/java/org/dromara/raincat/core/mediator/RpcMediator.java b/raincat-core/src/main/java/org/dromara/raincat/core/mediator/RpcMediator.java
new file mode 100644
index 0000000..7be9ef2
--- /dev/null
+++ b/raincat-core/src/main/java/org/dromara/raincat/core/mediator/RpcMediator.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.dromara.raincat.core.mediator;
+
+import org.dromara.raincat.common.constant.CommonConstant;
+import org.dromara.raincat.core.concurrent.threadlocal.TxTransactionLocal;
+
+/**
+ * The type RpcMediator.
+ *
+ * @author xiaoyu(Myth)
+ */
+public class RpcMediator {
+
+ private static final RpcMediator RPC_MEDIATOR = new RpcMediator();
+
+ /**
+ * Gets instance.
+ *
+ * @return the instance
+ */
+ public static RpcMediator getInstance() {
+ return RPC_MEDIATOR;
+ }
+
+ /**
+ * Transmit.
+ *
+ * @param rpcTransmit the rpc mediator
+ */
+ public void transmit(final RpcTransmit rpcTransmit) {
+ rpcTransmit.transmit(CommonConstant.TX_TRANSACTION_GROUP,
+ TxTransactionLocal.getInstance().getTxGroupId());
+ }
+
+ /**
+ * Acquire hmily transaction context.
+ *
+ * @param rpcAcquire the rpc acquire
+ * @return the hmily transaction context
+ */
+ public String acquire(RpcAcquire rpcAcquire) {
+ return rpcAcquire.acquire(CommonConstant.TX_TRANSACTION_GROUP);
+
+ }
+}
diff --git a/raincat-core/src/main/java/org/dromara/raincat/core/mediator/RpcTransmit.java b/raincat-core/src/main/java/org/dromara/raincat/core/mediator/RpcTransmit.java
new file mode 100644
index 0000000..0c534bf
--- /dev/null
+++ b/raincat-core/src/main/java/org/dromara/raincat/core/mediator/RpcTransmit.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.dromara.raincat.core.mediator;
+
+/**
+ * The interface Rpc mediator.
+ *
+ * @author xiaoyu(Myth)
+ */
+public interface RpcTransmit {
+
+ /**
+ * Transmit.
+ *
+ * @param key the key
+ * @param value the value
+ */
+ void transmit(String key, String value);
+
+}
diff --git a/raincat-core/src/main/java/org/dromara/raincat/core/netty/handler/NettyClientMessageHandler.java b/raincat-core/src/main/java/org/dromara/raincat/core/netty/handler/NettyClientMessageHandler.java
index b181592..e306264 100644
--- a/raincat-core/src/main/java/org/dromara/raincat/core/netty/handler/NettyClientMessageHandler.java
+++ b/raincat-core/src/main/java/org/dromara/raincat/core/netty/handler/NettyClientMessageHandler.java
@@ -25,10 +25,10 @@ import io.netty.handler.timeout.IdleState;
import io.netty.handler.timeout.IdleStateEvent;
import io.netty.util.ReferenceCountUtil;
import io.netty.util.concurrent.ScheduledFuture;
-import org.apache.commons.collections.CollectionUtils;
import org.dromara.raincat.common.config.TxConfig;
import org.dromara.raincat.common.enums.NettyMessageActionEnum;
import org.dromara.raincat.common.enums.NettyResultEnum;
+import org.dromara.raincat.common.holder.CollectionUtils;
import org.dromara.raincat.common.holder.IdWorkerUtils;
import org.dromara.raincat.common.holder.LogUtil;
import org.dromara.raincat.common.netty.bean.HeartBeat;
diff --git a/raincat-core/src/main/java/org/dromara/raincat/core/service/AspectTransactionService.java b/raincat-core/src/main/java/org/dromara/raincat/core/service/AspectTransactionService.java
index cc42f62..0a86b7a 100644
--- a/raincat-core/src/main/java/org/dromara/raincat/core/service/AspectTransactionService.java
+++ b/raincat-core/src/main/java/org/dromara/raincat/core/service/AspectTransactionService.java
@@ -22,18 +22,20 @@ import org.aspectj.lang.ProceedingJoinPoint;
/**
* AspectTransactionService.
+ *
* @author xiaoyu
*/
@FunctionalInterface
public interface AspectTransactionService {
+
/**
- * 切面方法调用.
+ * Invoke object.
*
- * @param transactionGroupId 事务组id
- * @param point 切点
- * @return Object
- * @throws Throwable 异常信息
+ * @param transactionGroupId the transaction group id
+ * @param point the point
+ * @return the object
+ * @throws Throwable the throwable
*/
Object invoke(String transactionGroupId, ProceedingJoinPoint point) throws Throwable;
}
diff --git a/raincat-core/src/main/java/org/dromara/raincat/core/service/impl/AspectTransactionServiceImpl.java b/raincat-core/src/main/java/org/dromara/raincat/core/service/impl/AspectTransactionServiceImpl.java
index b36fee4..a417dcd 100644
--- a/raincat-core/src/main/java/org/dromara/raincat/core/service/impl/AspectTransactionServiceImpl.java
+++ b/raincat-core/src/main/java/org/dromara/raincat/core/service/impl/AspectTransactionServiceImpl.java
@@ -20,10 +20,10 @@ package org.dromara.raincat.core.service.impl;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.reflect.MethodSignature;
+import org.dromara.raincat.annotation.PropagationEnum;
+import org.dromara.raincat.annotation.TxTransaction;
import org.dromara.raincat.common.bean.TransactionInvocation;
import org.dromara.raincat.common.bean.TxTransactionInfo;
-import org.dromara.raincat.common.enums.PropagationEnum;
-import org.dromara.raincat.core.annotation.TxTransaction;
import org.dromara.raincat.core.concurrent.threadlocal.CompensationLocal;
import org.dromara.raincat.core.helper.SpringBeanUtils;
import org.dromara.raincat.core.service.AspectTransactionService;
diff --git a/raincat-core/src/main/java/org/dromara/raincat/core/service/impl/InitServiceImpl.java b/raincat-core/src/main/java/org/dromara/raincat/core/service/impl/InitServiceImpl.java
index b3463c0..ffdda7a 100644
--- a/raincat-core/src/main/java/org/dromara/raincat/core/service/impl/InitServiceImpl.java
+++ b/raincat-core/src/main/java/org/dromara/raincat/core/service/impl/InitServiceImpl.java
@@ -19,11 +19,8 @@
package org.dromara.raincat.core.service.impl;
import org.dromara.raincat.common.config.TxConfig;
-import org.dromara.raincat.common.enums.CompensationCacheTypeEnum;
-import org.dromara.raincat.common.enums.SerializeProtocolEnum;
import org.dromara.raincat.common.exception.TransactionRuntimeException;
-import org.dromara.raincat.common.holder.ServiceBootstrap;
-import org.dromara.raincat.common.serializer.KryoSerializer;
+import org.dromara.raincat.common.holder.extension.ExtensionLoader;
import org.dromara.raincat.common.serializer.ObjectSerializer;
import org.dromara.raincat.core.compensation.TxCompensationService;
import org.dromara.raincat.core.helper.SpringBeanUtils;
@@ -31,14 +28,9 @@ import org.dromara.raincat.core.logo.RaincatLogo;
import org.dromara.raincat.core.netty.NettyClientService;
import org.dromara.raincat.core.service.InitService;
import org.dromara.raincat.core.spi.TransactionRecoverRepository;
-import org.dromara.raincat.core.spi.repository.JdbcTransactionRecoverRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
-import java.util.Objects;
-import java.util.ServiceLoader;
-import java.util.stream.StreamSupport;
-
/**
* tx transaction init.
*
@@ -77,27 +69,12 @@ public class InitServiceImpl implements InitService {
* @param txConfig {@linkplain TxConfig}
*/
private void loadSpi(final TxConfig txConfig) {
- //spi serialize
- final SerializeProtocolEnum serializeProtocolEnum
- = SerializeProtocolEnum.acquireSerializeProtocol(txConfig.getSerializer());
- final ServiceLoader objectSerializers
- = ServiceBootstrap.loadAll(ObjectSerializer.class);
- final ObjectSerializer serializer =
- StreamSupport.stream(objectSerializers.spliterator(), false)
- .filter(s -> Objects.equals(s.getScheme(), serializeProtocolEnum.getSerializeProtocol()))
- .findFirst().orElse(new KryoSerializer());
-
- //spi RecoverRepository support
- final CompensationCacheTypeEnum compensationCacheTypeEnum
- = CompensationCacheTypeEnum.acquireCompensationCacheType(txConfig.getCompensationCacheType());
-
- final ServiceLoader recoverRepositories
- = ServiceBootstrap.loadAll(TransactionRecoverRepository.class);
- final TransactionRecoverRepository repository =
- StreamSupport.stream(recoverRepositories.spliterator(), false)
- .filter(r -> Objects.equals(r.getScheme(), compensationCacheTypeEnum.getCompensationCacheType()))
- .findFirst().orElse(new JdbcTransactionRecoverRepository());
- //将compensationCache实现注入到spring容器
+ //spi serialize
+ final ObjectSerializer serializer = ExtensionLoader.getExtensionLoader(ObjectSerializer.class)
+ .getActivateExtension(txConfig.getSerializer());
+ //spi repository
+ final TransactionRecoverRepository repository = ExtensionLoader.getExtensionLoader(TransactionRecoverRepository.class)
+ .getActivateExtension(txConfig.getCompensationCacheType());
repository.setSerializer(serializer);
SpringBeanUtils.getInstance().registerBean(TransactionRecoverRepository.class.getName(), repository);
}
diff --git a/raincat-core/src/main/java/org/dromara/raincat/core/service/impl/TxManagerLocator.java b/raincat-core/src/main/java/org/dromara/raincat/core/service/impl/TxManagerLocator.java
index 37d5071..fba5794 100644
--- a/raincat-core/src/main/java/org/dromara/raincat/core/service/impl/TxManagerLocator.java
+++ b/raincat-core/src/main/java/org/dromara/raincat/core/service/impl/TxManagerLocator.java
@@ -20,11 +20,11 @@ package org.dromara.raincat.core.service.impl;
import com.google.common.collect.Lists;
import com.google.gson.reflect.TypeToken;
-import org.apache.commons.collections.CollectionUtils;
import org.dromara.raincat.common.config.TxConfig;
import org.dromara.raincat.common.constant.CommonConstant;
import org.dromara.raincat.common.entity.TxManagerServer;
import org.dromara.raincat.common.entity.TxManagerServiceDTO;
+import org.dromara.raincat.common.holder.CollectionUtils;
import org.dromara.raincat.common.holder.LogUtil;
import org.dromara.raincat.common.holder.httpclient.OkHttpTools;
import org.dromara.raincat.core.concurrent.threadpool.TxTransactionThreadFactory;
diff --git a/raincat-core/src/main/java/org/dromara/raincat/core/spi/TransactionRecoverRepository.java b/raincat-core/src/main/java/org/dromara/raincat/core/spi/TransactionRecoverRepository.java
index a6503e5..52046cc 100644
--- a/raincat-core/src/main/java/org/dromara/raincat/core/spi/TransactionRecoverRepository.java
+++ b/raincat-core/src/main/java/org/dromara/raincat/core/spi/TransactionRecoverRepository.java
@@ -18,6 +18,7 @@
package org.dromara.raincat.core.spi;
+import org.dromara.raincat.annotation.RaincatSPI;
import org.dromara.raincat.common.bean.TransactionRecover;
import org.dromara.raincat.common.config.TxConfig;
import org.dromara.raincat.common.exception.TransactionRuntimeException;
@@ -30,6 +31,7 @@ import java.util.List;
* TransactionRecoverRepository.
* @author xiaoyu
*/
+@RaincatSPI
public interface TransactionRecoverRepository {
int ROWS = 1;
@@ -97,14 +99,6 @@ public interface TransactionRecoverRepository {
*/
void init(String appName, TxConfig txConfig) throws Exception;
- /**
- * get scheme.
- *
- * @return scheme
- */
- String getScheme();
-
-
/**
* set objectSerializer spi.
*
diff --git a/raincat-core/src/main/java/org/dromara/raincat/core/spi/repository/FileTransactionRecoverRepository.java b/raincat-core/src/main/java/org/dromara/raincat/core/spi/repository/FileTransactionRecoverRepository.java
index 98aa779..989eb01 100644
--- a/raincat-core/src/main/java/org/dromara/raincat/core/spi/repository/FileTransactionRecoverRepository.java
+++ b/raincat-core/src/main/java/org/dromara/raincat/core/spi/repository/FileTransactionRecoverRepository.java
@@ -19,10 +19,10 @@
package org.dromara.raincat.core.spi.repository;
import com.google.common.collect.Lists;
+import org.dromara.raincat.annotation.RaincatSPI;
import org.dromara.raincat.common.bean.TransactionRecover;
import org.dromara.raincat.common.config.TxConfig;
import org.dromara.raincat.common.constant.CommonConstant;
-import org.dromara.raincat.common.enums.CompensationCacheTypeEnum;
import org.dromara.raincat.common.enums.CompensationOperationTypeEnum;
import org.dromara.raincat.common.exception.TransactionRuntimeException;
import org.dromara.raincat.common.holder.RepositoryPathUtils;
@@ -44,7 +44,8 @@ import java.util.stream.Collectors;
*
* @author xiaoyu
*/
-@SuppressWarnings("unchecked")
+@SuppressWarnings("all")
+@RaincatSPI("file")
public class FileTransactionRecoverRepository implements TransactionRecoverRepository {
private static volatile boolean initialized;
@@ -140,11 +141,6 @@ public class FileTransactionRecoverRepository implements TransactionRecoverRepos
}
}
- @Override
- public String getScheme() {
- return CompensationCacheTypeEnum.FILE.getCompensationCacheType();
- }
-
private void writeFile(final TransactionRecover transaction) {
makeDir();
String file = getFullFileName(transaction.getId());
diff --git a/raincat-core/src/main/java/org/dromara/raincat/core/spi/repository/JdbcTransactionRecoverRepository.java b/raincat-core/src/main/java/org/dromara/raincat/core/spi/repository/JdbcTransactionRecoverRepository.java
index c0e1323..c57432a 100644
--- a/raincat-core/src/main/java/org/dromara/raincat/core/spi/repository/JdbcTransactionRecoverRepository.java
+++ b/raincat-core/src/main/java/org/dromara/raincat/core/spi/repository/JdbcTransactionRecoverRepository.java
@@ -20,16 +20,16 @@ package org.dromara.raincat.core.spi.repository;
import com.alibaba.druid.pool.DruidDataSource;
import com.google.common.collect.Maps;
-import org.apache.commons.collections.CollectionUtils;
+import org.dromara.raincat.annotation.RaincatSPI;
import org.dromara.raincat.common.bean.TransactionInvocation;
import org.dromara.raincat.common.bean.TransactionRecover;
import org.dromara.raincat.common.config.TxConfig;
import org.dromara.raincat.common.config.TxDbConfig;
import org.dromara.raincat.common.constant.CommonConstant;
-import org.dromara.raincat.common.enums.CompensationCacheTypeEnum;
import org.dromara.raincat.common.enums.CompensationOperationTypeEnum;
import org.dromara.raincat.common.exception.TransactionException;
import org.dromara.raincat.common.exception.TransactionRuntimeException;
+import org.dromara.raincat.common.holder.CollectionUtils;
import org.dromara.raincat.common.holder.RepositoryPathUtils;
import org.dromara.raincat.common.serializer.ObjectSerializer;
import org.dromara.raincat.core.helper.SqlHelper;
@@ -54,6 +54,7 @@ import java.util.stream.Collectors;
*
* @author xiaoyu
*/
+@RaincatSPI("db")
public class JdbcTransactionRecoverRepository implements TransactionRecoverRepository {
private static final Logger LOGGER = LoggerFactory.getLogger(JdbcTransactionRecoverRepository.class);
@@ -188,11 +189,6 @@ public class JdbcTransactionRecoverRepository implements TransactionRecoverRepos
executeUpdate(SqlHelper.buildCreateTableSql(tableName, txDbConfig.getDriverClassName()));
}
- @Override
- public String getScheme() {
- return CompensationCacheTypeEnum.DB.getCompensationCacheType();
- }
-
private int executeUpdate(final String sql, final Object... params) {
try {
try (Connection connection = dataSource.getConnection();
diff --git a/raincat-core/src/main/java/org/dromara/raincat/core/spi/repository/MongoTransactionRecoverRepository.java b/raincat-core/src/main/java/org/dromara/raincat/core/spi/repository/MongoTransactionRecoverRepository.java
index dc0e1c0..88a5ce2 100644
--- a/raincat-core/src/main/java/org/dromara/raincat/core/spi/repository/MongoTransactionRecoverRepository.java
+++ b/raincat-core/src/main/java/org/dromara/raincat/core/spi/repository/MongoTransactionRecoverRepository.java
@@ -22,23 +22,23 @@ import com.google.common.base.Splitter;
import com.mongodb.MongoCredential;
import com.mongodb.ServerAddress;
import com.mongodb.WriteResult;
+import org.dromara.raincat.annotation.RaincatSPI;
import org.dromara.raincat.common.bean.TransactionInvocation;
import org.dromara.raincat.common.bean.TransactionRecover;
import org.dromara.raincat.common.bean.adapter.MongoAdapter;
import org.dromara.raincat.common.config.TxConfig;
import org.dromara.raincat.common.config.TxMongoConfig;
import org.dromara.raincat.common.constant.CommonConstant;
-import org.dromara.raincat.common.enums.CompensationCacheTypeEnum;
import org.dromara.raincat.common.enums.CompensationOperationTypeEnum;
import org.dromara.raincat.common.enums.TransactionStatusEnum;
import org.dromara.raincat.common.exception.TransactionException;
import org.dromara.raincat.common.exception.TransactionRuntimeException;
import org.dromara.raincat.common.holder.Assert;
+import org.dromara.raincat.common.holder.CollectionUtils;
import org.dromara.raincat.common.holder.LogUtil;
import org.dromara.raincat.common.holder.RepositoryPathUtils;
import org.dromara.raincat.common.serializer.ObjectSerializer;
import org.dromara.raincat.core.spi.TransactionRecoverRepository;
-import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.mongodb.core.MongoClientFactoryBean;
@@ -56,6 +56,7 @@ import java.util.stream.Collectors;
* mongo db impl.
* @author xiaoyu
*/
+@RaincatSPI("mongo")
public class MongoTransactionRecoverRepository implements TransactionRecoverRepository {
private static final Logger LOGGER = LoggerFactory.getLogger(MongoTransactionRecoverRepository.class);
@@ -181,6 +182,7 @@ public class MongoTransactionRecoverRepository implements TransactionRecoverRepo
}
@Override
+ @SuppressWarnings("unchecked")
public void init(final String appName, final TxConfig txConfig) {
collectionName = RepositoryPathUtils.buildMongoTableName(appName);
final TxMongoConfig txMongoConfig = txConfig.getTxMongoConfig();
@@ -210,11 +212,6 @@ public class MongoTransactionRecoverRepository implements TransactionRecoverRepo
return clientFactoryBean;
}
- @Override
- public String getScheme() {
- return CompensationCacheTypeEnum.MONGODB.getCompensationCacheType();
- }
-
@Override
public void setSerializer(final ObjectSerializer objectSerializer) {
this.objectSerializer = objectSerializer;
diff --git a/raincat-core/src/main/java/org/dromara/raincat/core/spi/repository/RedisTransactionRecoverRepository.java b/raincat-core/src/main/java/org/dromara/raincat/core/spi/repository/RedisTransactionRecoverRepository.java
index 46d3aef..218a827 100644
--- a/raincat-core/src/main/java/org/dromara/raincat/core/spi/repository/RedisTransactionRecoverRepository.java
+++ b/raincat-core/src/main/java/org/dromara/raincat/core/spi/repository/RedisTransactionRecoverRepository.java
@@ -21,11 +21,11 @@ package org.dromara.raincat.core.spi.repository;
import com.google.common.base.Splitter;
import com.google.common.collect.Lists;
import org.apache.commons.lang3.StringUtils;
+import org.dromara.raincat.annotation.RaincatSPI;
import org.dromara.raincat.common.bean.TransactionRecover;
import org.dromara.raincat.common.config.TxConfig;
import org.dromara.raincat.common.config.TxRedisConfig;
import org.dromara.raincat.common.constant.CommonConstant;
-import org.dromara.raincat.common.enums.CompensationCacheTypeEnum;
import org.dromara.raincat.common.enums.CompensationOperationTypeEnum;
import org.dromara.raincat.common.exception.TransactionIoException;
import org.dromara.raincat.common.exception.TransactionRuntimeException;
@@ -58,6 +58,7 @@ import java.util.stream.Collectors;
*
* @author xiaoyu
*/
+@RaincatSPI("redis")
public class RedisTransactionRecoverRepository implements TransactionRecoverRepository {
private static final Logger LOGGER = LoggerFactory.getLogger(RedisTransactionRecoverRepository.class);
@@ -157,11 +158,6 @@ public class RedisTransactionRecoverRepository implements TransactionRecoverRepo
}
}
- @Override
- public String getScheme() {
- return CompensationCacheTypeEnum.REDIS.getCompensationCacheType();
- }
-
@Override
public void setSerializer(final ObjectSerializer objectSerializer) {
this.objectSerializer = objectSerializer;
diff --git a/raincat-core/src/main/java/org/dromara/raincat/core/spi/repository/ZookeeperTransactionRecoverRepository.java b/raincat-core/src/main/java/org/dromara/raincat/core/spi/repository/ZookeeperTransactionRecoverRepository.java
index 0f01ef8..cfa3d15 100644
--- a/raincat-core/src/main/java/org/dromara/raincat/core/spi/repository/ZookeeperTransactionRecoverRepository.java
+++ b/raincat-core/src/main/java/org/dromara/raincat/core/spi/repository/ZookeeperTransactionRecoverRepository.java
@@ -19,7 +19,6 @@
package org.dromara.raincat.core.spi.repository;
import com.google.common.collect.Lists;
-import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.KeeperException;
@@ -27,15 +26,16 @@ import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.ZooDefs;
import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.data.Stat;
+import org.dromara.raincat.annotation.RaincatSPI;
import org.dromara.raincat.common.bean.TransactionRecover;
import org.dromara.raincat.common.config.TxConfig;
import org.dromara.raincat.common.config.TxZookeeperConfig;
import org.dromara.raincat.common.constant.CommonConstant;
-import org.dromara.raincat.common.enums.CompensationCacheTypeEnum;
import org.dromara.raincat.common.enums.CompensationOperationTypeEnum;
import org.dromara.raincat.common.exception.TransactionException;
import org.dromara.raincat.common.exception.TransactionIoException;
import org.dromara.raincat.common.exception.TransactionRuntimeException;
+import org.dromara.raincat.common.holder.CollectionUtils;
import org.dromara.raincat.common.holder.LogUtil;
import org.dromara.raincat.common.holder.RepositoryPathUtils;
import org.dromara.raincat.common.holder.TransactionRecoverUtils;
@@ -54,6 +54,7 @@ import java.util.stream.Collectors;
*
* @author xiaoyu
*/
+@RaincatSPI("zookeeper")
public class ZookeeperTransactionRecoverRepository implements TransactionRecoverRepository {
private static final Logger LOGGER = LoggerFactory.getLogger(ZookeeperTransactionRecoverRepository.class);
@@ -189,11 +190,6 @@ public class ZookeeperTransactionRecoverRepository implements TransactionRecover
}
}
- @Override
- public String getScheme() {
- return CompensationCacheTypeEnum.ZOOKEEPER.getCompensationCacheType();
- }
-
@Override
public void setSerializer(final ObjectSerializer objectSerializer) {
this.objectSerializer = objectSerializer;
diff --git a/raincat-core/src/test/java/org/dromara/raincat/core/AtomicReferenceTest.java b/raincat-core/src/test/java/org/dromara/raincat/core/AtomicReferenceTest.java
deleted file mode 100644
index 374db98..0000000
--- a/raincat-core/src/test/java/org/dromara/raincat/core/AtomicReferenceTest.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- *
- * Copyright 2017-2018 549477611@qq.com(xiaoyu)
- *
- * This copyrighted material is made available to anyone wishing to use, modify,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * Lesser General Public License, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, see .
- *
- */
-
-package org.dromara.raincat.core;
-
-public class AtomicReferenceTest {
-}
diff --git a/raincat-core/src/test/java/org/dromara/raincat/core/concurrent/task/BlockTaskTest.java b/raincat-core/src/test/java/org/dromara/raincat/core/concurrent/task/BlockTaskTest.java
deleted file mode 100644
index d3e03a6..0000000
--- a/raincat-core/src/test/java/org/dromara/raincat/core/concurrent/task/BlockTaskTest.java
+++ /dev/null
@@ -1,22 +0,0 @@
-package org.dromara.raincat.core.concurrent.task;
-
-import org.junit.Test;
-
-import static org.junit.Assert.*;
-
-/**
- * @author xiaoyu(Myth)
- */
-public class BlockTaskTest {
-
- @Test
- public void isNotify() {
- BlockTask task1 = new BlockTask();
- task1.signal();
- System.out.println(task1.isNotify());
-
- BlockTask task2 = new BlockTask();
- System.out.println(task2.isNotify());
-
- }
-}
\ No newline at end of file
diff --git a/raincat-core/src/test/java/org/dromara/raincat/core/mongodb/MongoDbConnectDatabase.java b/raincat-core/src/test/java/org/dromara/raincat/core/mongodb/MongoDbConnectDatabase.java
deleted file mode 100644
index 47ddaa9..0000000
--- a/raincat-core/src/test/java/org/dromara/raincat/core/mongodb/MongoDbConnectDatabase.java
+++ /dev/null
@@ -1,61 +0,0 @@
-package org.dromara.raincat.core.mongodb;
-
-import com.mongodb.MongoClient;
-import com.mongodb.MongoCredential;
-import com.mongodb.ServerAddress;
-import com.mongodb.client.MongoCollection;
-import com.mongodb.client.MongoDatabase;
-import org.bson.Document;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class MongoDbConnectDatabase {
-
-
- public static void main(String[] args) {
- try {
- //连接到MongoDB服务 如果是远程连接可以替换“localhost”为服务器所在IP地址
- //ServerAddress()两个参数分别为 服务器地址 和 端口
- ServerAddress serverAddress = new ServerAddress("192.168.1.78", 27017);
- List addrs = new ArrayList<>();
- addrs.add(serverAddress);
-
- //MongoCredential.createScramSha1Credential()三个参数分别为 用户名 数据库名称 密码
- MongoCredential credential = MongoCredential.createScramSha1Credential("xiaoyu", "happylife", "123456".toCharArray());
- List credentials = new ArrayList<>();
- credentials.add(credential);
-
- //通过连接认证获取MongoDB连接
- MongoClient mongoClient = new MongoClient(addrs, credentials);
-
- //连接到数据库
- MongoDatabase mongoDatabase = mongoClient.getDatabase("happylife");
- System.out.println("Connect to database successfully");
-
- //获取集合 参数为“集合名称”
- MongoCollection mongoCollection = mongoDatabase.getCollection("collectionName");
- System.out.println("Collection mycol selected successfully");
-
- //插入文档
- /**
- * 1. 创建文档 org.bson.Document 参数为key-value的格式
- * 2. 创建文档集合List
- * 3. 将文档集合插入数据库集合中 mongoCollection.insertMany(List) 插入单个文档可以用 mongoCollection.insertOne(Document)
- * */
- Document document = new Document("title", "MongoDB").
- append("description", "database").
- append("likes", 100).
- append("by", "Fly");
- List documents = new ArrayList();
- documents.add(document);
- mongoCollection.insertMany(documents);
- System.out.println("Document inserted successfully");
-
- } catch (Exception e) {
- System.err.println(e.getClass().getName() + ": " + e.getMessage());
- }
-
-
- }
-}
diff --git a/raincat-core/src/test/java/org/dromara/raincat/core/spi/ServiceBootstrapTest.java b/raincat-core/src/test/java/org/dromara/raincat/core/spi/ServiceBootstrapTest.java
deleted file mode 100644
index 5044e51..0000000
--- a/raincat-core/src/test/java/org/dromara/raincat/core/spi/ServiceBootstrapTest.java
+++ /dev/null
@@ -1,64 +0,0 @@
-package org.dromara.raincat.core.spi;
-
-import org.dromara.raincat.common.enums.CompensationCacheTypeEnum;
-import org.dromara.raincat.common.enums.SerializeProtocolEnum;
-import org.dromara.raincat.common.holder.ServiceBootstrap;
-import org.dromara.raincat.common.serializer.ObjectSerializer;
-import org.dromara.raincat.core.helper.SpringBeanUtils;
-import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.Objects;
-import java.util.Optional;
-import java.util.ServiceLoader;
-import java.util.stream.StreamSupport;
-
-public class ServiceBootstrapTest {
-
- /**
- * logger
- */
- private static final Logger LOGGER = LoggerFactory.getLogger(ServiceBootstrapTest.class);
-
-
- @Test
- public void loadFirst() throws Exception {
- final ObjectSerializer objectSerializer = ServiceBootstrap.loadFirst(ObjectSerializer.class);
- LOGGER.info("加载的序列化名称为:{}", objectSerializer.getClass().getName());
-
- }
-
-
- @Test
- public void loadAll() {
- //spi serialize
- final SerializeProtocolEnum serializeProtocolEnum =
- SerializeProtocolEnum.HESSIAN;
- final ServiceLoader objectSerializers = ServiceBootstrap.loadAll(ObjectSerializer.class);
-
- final Optional serializer = StreamSupport.stream(objectSerializers.spliterator(), false)
- .filter(objectSerializer ->
- Objects.equals(objectSerializer.getScheme(), serializeProtocolEnum.getSerializeProtocol())).findFirst();
-
- serializer.ifPresent(objectSerializer -> LOGGER.info("加载的序列化名称为:{}", objectSerializer.getClass().getName()));
-
-
- //spi RecoverRepository support
- final CompensationCacheTypeEnum compensationCacheTypeEnum = CompensationCacheTypeEnum.DB;
- final ServiceLoader recoverRepositories = ServiceBootstrap.loadAll(TransactionRecoverRepository.class);
-
-
- final Optional repositoryOptional = StreamSupport.stream(recoverRepositories.spliterator(), false)
- .filter(recoverRepository ->
- Objects.equals(recoverRepository.getScheme(), compensationCacheTypeEnum.getCompensationCacheType())).findFirst();
- //将compensationCache实现注入到spring容器
- repositoryOptional.ifPresent(repository -> {
- serializer.ifPresent(repository::setSerializer);
- SpringBeanUtils.getInstance().registerBean(TransactionRecoverRepository.class.getName(), repository);
- });
-
-
- }
-
-}
\ No newline at end of file
diff --git a/raincat-core/src/test/resources/META-INF/services/com.raincat.common.serializer.ObjectSerializer b/raincat-core/src/test/resources/META-INF/services/com.raincat.common.serializer.ObjectSerializer
deleted file mode 100644
index 3f85f32..0000000
--- a/raincat-core/src/test/resources/META-INF/services/com.raincat.common.serializer.ObjectSerializer
+++ /dev/null
@@ -1,4 +0,0 @@
-com.raincat.common.serializer.KryoSerializer
-com.raincat.common.serializer.ProtostuffSerializer
-com.raincat.common.serializer.HessianSerializer
-com.raincat.common.serializer.JavaSerializer
\ No newline at end of file
diff --git a/raincat-core/src/test/resources/META-INF/services/com.raincat.core.spi.TransactionRecoverRepository b/raincat-core/src/test/resources/META-INF/services/com.raincat.core.spi.TransactionRecoverRepository
deleted file mode 100644
index 2eb5bf7..0000000
--- a/raincat-core/src/test/resources/META-INF/services/com.raincat.core.spi.TransactionRecoverRepository
+++ /dev/null
@@ -1,5 +0,0 @@
-com.raincat.core.spi.repository.JdbcTransactionRecoverRepository
-com.raincat.core.spi.repository.FileTransactionRecoverRepository
-com.raincat.core.spi.repository.MongoTransactionRecoverRepository
-com.raincat.core.spi.repository.RedisTransactionRecoverRepository
-com.raincat.core.spi.repository.ZookeeperTransactionRecoverRepository
\ No newline at end of file
diff --git a/raincat-dubbo/pom.xml b/raincat-dubbo/pom.xml
index 5d106c8..e654550 100644
--- a/raincat-dubbo/pom.xml
+++ b/raincat-dubbo/pom.xml
@@ -14,20 +14,25 @@
jar
-
- org.apache.commons
- commons-lang3
-
-
-
- com.alibaba
- dubbo
-
org.dromara
raincat-core
+
+
+ com.alibaba
+ dubbo
+ provided
+
+
+
+ org.springframework
+ spring-context
+ provided
+
+
+
diff --git a/raincat-dubbo/src/main/java/org/dromara/raincat/dubbo/filter/DubboTxTransactionFilter.java b/raincat-dubbo/src/main/java/org/dromara/raincat/dubbo/filter/DubboTxTransactionFilter.java
index 3ac16ed..39c6340 100644
--- a/raincat-dubbo/src/main/java/org/dromara/raincat/dubbo/filter/DubboTxTransactionFilter.java
+++ b/raincat-dubbo/src/main/java/org/dromara/raincat/dubbo/filter/DubboTxTransactionFilter.java
@@ -28,6 +28,8 @@ import com.alibaba.dubbo.rpc.RpcContext;
import com.alibaba.dubbo.rpc.RpcException;
import org.dromara.raincat.common.constant.CommonConstant;
import org.dromara.raincat.core.concurrent.threadlocal.TxTransactionLocal;
+import org.dromara.raincat.core.mediator.RpcMediator;
+import org.dromara.raincat.core.mediator.RpcTransmit;
/**
* DubboTxTransactionFilter.
@@ -39,8 +41,7 @@ public class DubboTxTransactionFilter implements Filter {
@Override
public Result invoke(final Invoker> invoker, final Invocation invocation) throws RpcException {
if (RpcContext.getContext().isConsumerSide()) {
- RpcContext.getContext().setAttachment(CommonConstant.TX_TRANSACTION_GROUP,
- TxTransactionLocal.getInstance().getTxGroupId());
+ RpcMediator.getInstance().transmit(RpcContext.getContext()::setAttachment);
}
return invoker.invoke(invocation);
}
diff --git a/raincat-dubbo/src/main/java/org/dromara/raincat/dubbo/interceptor/DubboTxTransactionInterceptor.java b/raincat-dubbo/src/main/java/org/dromara/raincat/dubbo/interceptor/DubboTxTransactionInterceptor.java
index d61919f..fb9addd 100644
--- a/raincat-dubbo/src/main/java/org/dromara/raincat/dubbo/interceptor/DubboTxTransactionInterceptor.java
+++ b/raincat-dubbo/src/main/java/org/dromara/raincat/dubbo/interceptor/DubboTxTransactionInterceptor.java
@@ -19,15 +19,17 @@
package org.dromara.raincat.dubbo.interceptor;
import com.alibaba.dubbo.rpc.RpcContext;
-import org.dromara.raincat.common.constant.CommonConstant;
-import org.dromara.raincat.core.interceptor.TxTransactionInterceptor;
-import org.dromara.raincat.core.service.AspectTransactionService;
import org.aspectj.lang.ProceedingJoinPoint;
+import org.dromara.raincat.core.interceptor.TxTransactionInterceptor;
+import org.dromara.raincat.core.mediator.RpcMediator;
+import org.dromara.raincat.core.service.AspectTransactionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
+
/**
* DubboTxTransactionInterceptor.
+ *
* @author xiaoyu
*/
@Component
@@ -42,7 +44,8 @@ public class DubboTxTransactionInterceptor implements TxTransactionInterceptor {
@Override
public Object interceptor(final ProceedingJoinPoint pjp) throws Throwable {
- String groupId = RpcContext.getContext().getAttachment(CommonConstant.TX_TRANSACTION_GROUP);
+ String groupId = RpcMediator.getInstance()
+ .acquire(RpcContext.getContext()::getAttachment);
return aspectTransactionService.invoke(groupId, pjp);
}
diff --git a/raincat-motan/pom.xml b/raincat-motan/pom.xml
index 1e521cb..c9dab6f 100644
--- a/raincat-motan/pom.xml
+++ b/raincat-motan/pom.xml
@@ -12,25 +12,31 @@
raincat-motan
-
- org.apache.commons
- commons-lang3
-
-
-
- com.weibo
- motan-core
-
-
-
- com.weibo
- motan-springsupport
-
org.dromara
raincat-core
+
+
+ org.springframework
+ spring-context
+ provided
+
+
+
+ com.weibo
+ motan-core
+ provided
+
+
+
+ com.weibo
+ motan-springsupport
+ provided
+
+
+
diff --git a/raincat-motan/src/main/java/org/dromara/raincat/motan/filter/MotanTxTransactionFilter.java b/raincat-motan/src/main/java/org/dromara/raincat/motan/filter/MotanTxTransactionFilter.java
index 7b4f4c5..f1cda72 100644
--- a/raincat-motan/src/main/java/org/dromara/raincat/motan/filter/MotanTxTransactionFilter.java
+++ b/raincat-motan/src/main/java/org/dromara/raincat/motan/filter/MotanTxTransactionFilter.java
@@ -28,6 +28,7 @@ import com.weibo.api.motan.rpc.Request;
import com.weibo.api.motan.rpc.Response;
import org.dromara.raincat.common.constant.CommonConstant;
import org.dromara.raincat.core.concurrent.threadlocal.TxTransactionLocal;
+import org.dromara.raincat.core.mediator.RpcMediator;
/**
@@ -41,7 +42,7 @@ public class MotanTxTransactionFilter implements Filter {
@Override
public Response filter(final Caller> caller, final Request request) {
- request.setAttachment(CommonConstant.TX_TRANSACTION_GROUP, TxTransactionLocal.getInstance().getTxGroupId());
+ RpcMediator.getInstance().transmit(request::setAttachment);
return caller.call(request);
}
}
diff --git a/raincat-motan/src/main/java/org/dromara/raincat/motan/interceptor/MotanTxTransactionInterceptor.java b/raincat-motan/src/main/java/org/dromara/raincat/motan/interceptor/MotanTxTransactionInterceptor.java
index ccb909d..319e56d 100644
--- a/raincat-motan/src/main/java/org/dromara/raincat/motan/interceptor/MotanTxTransactionInterceptor.java
+++ b/raincat-motan/src/main/java/org/dromara/raincat/motan/interceptor/MotanTxTransactionInterceptor.java
@@ -18,12 +18,12 @@
package org.dromara.raincat.motan.interceptor;
-import org.dromara.raincat.common.constant.CommonConstant;
-import org.dromara.raincat.core.interceptor.TxTransactionInterceptor;
-import org.dromara.raincat.core.service.AspectTransactionService;
import com.weibo.api.motan.rpc.Request;
import com.weibo.api.motan.rpc.RpcContext;
import org.aspectj.lang.ProceedingJoinPoint;
+import org.dromara.raincat.core.interceptor.TxTransactionInterceptor;
+import org.dromara.raincat.core.mediator.RpcMediator;
+import org.dromara.raincat.core.service.AspectTransactionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -32,6 +32,7 @@ import java.util.Objects;
/**
* MotanTxTransactionInterceptor.
+ *
* @author xiaoyu
*/
@Component
@@ -51,7 +52,8 @@ public class MotanTxTransactionInterceptor implements TxTransactionInterceptor {
if (Objects.nonNull(request)) {
final Map attachments = request.getAttachments();
if (attachments != null && !attachments.isEmpty()) {
- groupId = attachments.get(CommonConstant.TX_TRANSACTION_GROUP);
+ groupId = RpcMediator.getInstance().acquire(attachments::get);
+
}
}
return aspectTransactionService.invoke(groupId, pjp);
diff --git a/raincat-sample/pom.xml b/raincat-sample/pom.xml
index 6879fde..591849d 100644
--- a/raincat-sample/pom.xml
+++ b/raincat-sample/pom.xml
@@ -2,19 +2,108 @@
-
- raincat
- org.dromara
- 2.0.1-RELEASE
-
- 4.0.0
+ 4.0.0
raincat-sample
+ org.dromara
+ 2.0.1-RELEASE
pom
+
+ org.springframework.boot
+ spring-boot-starter-parent
+ 2.1.1.RELEASE
+
raincat-dubbo-sample
raincat-springcloud-sample
+
+ UTF-8
+ 1.8
+ 2.0.1-RELEASE
+ Dalston.SR1
+ 2.6.1
+
+
+
+
+
+ org.dromara
+ raincat-annotation
+ ${raincat.version}
+
+
+ org.dromara
+ raincat-core
+ ${raincat.version}
+
+
+
+ org.dromara
+ raincat-dubbo
+ ${raincat.version}
+
+
+
+ org.dromara
+ raincat-springcloud
+ ${raincat.version}
+
+
+ org.dromara
+ raincat-spring-boot-starter-dubbo
+ ${raincat.version}
+
+
+ org.dromara
+ raincat-spring-boot-starter-springcloud
+ ${raincat.version}
+
+
+
+ io.springfox
+ springfox-swagger2
+ ${springfox.version}
+
+
+ io.springfox
+ springfox-swagger-ui
+ ${springfox.version}
+
+
+ io.springfox
+ springfox-bean-validators
+ ${springfox.version}
+
+
+ org.apache.zookeeper
+ zookeeper
+ 3.4.9
+
+
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ ${maven-compiler-plugin.version}
+
+
+ 1.8
+ ${project.build.sourceEncoding}
+
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+
+
\ No newline at end of file
diff --git a/raincat-sample/raincat-dubbo-sample/pom.xml b/raincat-sample/raincat-dubbo-sample/pom.xml
index ebdc9ae..7c35a99 100644
--- a/raincat-sample/raincat-dubbo-sample/pom.xml
+++ b/raincat-sample/raincat-dubbo-sample/pom.xml
@@ -21,8 +21,32 @@
raincat-dubbo-sample-order
+
+
+ 4.0.1
+ 2.6.5
+
+
+
+
+ com.alibaba
+ dubbo
+ ${dubbo.version}
+
+
+
+ org.apache.curator
+ curator-client
+ ${curator.version}
+
+
+ org.apache.curator
+ curator-framework
+ ${curator.version}
+
+
org.dromara
raincat-dubbo-sample-consume
diff --git a/raincat-sample/raincat-dubbo-sample/raincat-dubbo-sample-consume/pom.xml b/raincat-sample/raincat-dubbo-sample/raincat-dubbo-sample-consume/pom.xml
index 017e490..5e78610 100644
--- a/raincat-sample/raincat-dubbo-sample/raincat-dubbo-sample-consume/pom.xml
+++ b/raincat-sample/raincat-dubbo-sample/raincat-dubbo-sample-consume/pom.xml
@@ -78,6 +78,7 @@
zkclient
0.4
+
org.apache.zookeeper
@@ -93,6 +94,7 @@
+
org.springframework
spring-context
diff --git a/raincat-sample/raincat-springcloud-sample/pom.xml b/raincat-sample/raincat-springcloud-sample/pom.xml
index 5cfc006..a5e7566 100644
--- a/raincat-sample/raincat-springcloud-sample/pom.xml
+++ b/raincat-sample/raincat-springcloud-sample/pom.xml
@@ -17,5 +17,21 @@
raincat-springcloud-sample-wechat
+
+ Finchley.RELEASE
+
+
+
+
+
+ org.springframework.cloud
+ spring-cloud-dependencies
+ ${spring-cloud.version}
+ pom
+ import
+
+
+
+
\ No newline at end of file
diff --git a/raincat-sample/raincat-springcloud-sample/raincat-springcloud-sample-pay/src/main/java/org/dromara/raincat/springcloud/sample/pay/client/MyConfiguration.java b/raincat-sample/raincat-springcloud-sample/raincat-springcloud-sample-pay/src/main/java/org/dromara/raincat/springcloud/sample/pay/client/MyConfiguration.java
index eac0266..b6b70c5 100644
--- a/raincat-sample/raincat-springcloud-sample/raincat-springcloud-sample-pay/src/main/java/org/dromara/raincat/springcloud/sample/pay/client/MyConfiguration.java
+++ b/raincat-sample/raincat-springcloud-sample/raincat-springcloud-sample-pay/src/main/java/org/dromara/raincat/springcloud/sample/pay/client/MyConfiguration.java
@@ -20,7 +20,7 @@ package org.dromara.raincat.springcloud.sample.pay.client;
import feign.Feign;
import feign.Request;
import feign.Retryer;
-import org.dromara.raincat.springcloud.feign.RestTemplateInterceptor;
+import org.dromara.raincat.springcloud.feign.RaincatFeignInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;
@@ -34,7 +34,7 @@ public class MyConfiguration {
@Bean
@Scope("prototype")
public Feign.Builder feignBuilder() {
- return Feign.builder().requestInterceptor(new RestTemplateInterceptor());
+ return Feign.builder().requestInterceptor(new RaincatFeignInterceptor());
}
@Bean
diff --git a/raincat-sample/raincat-springcloud-sample/raincat-springcloud-sample-pay/src/main/java/org/dromara/raincat/springcloud/sample/pay/service/impl/PayServiceImpl.java b/raincat-sample/raincat-springcloud-sample/raincat-springcloud-sample-pay/src/main/java/org/dromara/raincat/springcloud/sample/pay/service/impl/PayServiceImpl.java
index 9a302c1..403f14b 100644
--- a/raincat-sample/raincat-springcloud-sample/raincat-springcloud-sample-pay/src/main/java/org/dromara/raincat/springcloud/sample/pay/service/impl/PayServiceImpl.java
+++ b/raincat-sample/raincat-springcloud-sample/raincat-springcloud-sample-pay/src/main/java/org/dromara/raincat/springcloud/sample/pay/service/impl/PayServiceImpl.java
@@ -23,11 +23,6 @@ import org.dromara.raincat.springcloud.sample.pay.client.WechatClient;
import org.dromara.raincat.springcloud.sample.pay.entiy.Pay;
import org.dromara.raincat.springcloud.sample.pay.mapper.PayMapper;
import org.dromara.raincat.springcloud.sample.pay.service.PayService;
-import org.dromara.raincat.springcloud.sample.pay.client.AlipayClient;
-import org.dromara.raincat.springcloud.sample.pay.client.WechatClient;
-import org.dromara.raincat.springcloud.sample.pay.entiy.Pay;
-import org.dromara.raincat.springcloud.sample.pay.mapper.PayMapper;
-import org.dromara.raincat.springcloud.sample.pay.service.PayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
diff --git a/raincat-springcloud/pom.xml b/raincat-springcloud/pom.xml
index 17c5817..76ee2a1 100644
--- a/raincat-springcloud/pom.xml
+++ b/raincat-springcloud/pom.xml
@@ -12,37 +12,49 @@
raincat-springcloud
-
- org.apache.commons
- commons-lang3
-
+
org.dromara
raincat-core
- org.springframework.cloud
- spring-cloud-starter-openfeign
+ com.netflix.feign
+ feign-core
+ 8.18.0
+ provided
+
+
+
+ com.netflix.ribbon
+ ribbon-loadbalancer
+ provided
+
+
+
+ com.netflix.hystrix
+ hystrix-core
+ provided
org.springframework.boot
- spring-boot-starter-aop
+ spring-boot-starter-actuator
+ provided
-
-
- org.springframework
- spring-tx
-
-
-
org.apache.tomcat.embed
tomcat-embed-core
RELEASE
+ provided
+
+ org.springframework
+ spring-web
+ provided
+
+
diff --git a/raincat-springcloud/src/main/java/org/dromara/raincat/springcloud/feign/RestTemplateConfiguration.java b/raincat-springcloud/src/main/java/org/dromara/raincat/springcloud/configuration/RaincatFeignConfiguration.java
similarity index 52%
rename from raincat-springcloud/src/main/java/org/dromara/raincat/springcloud/feign/RestTemplateConfiguration.java
rename to raincat-springcloud/src/main/java/org/dromara/raincat/springcloud/configuration/RaincatFeignConfiguration.java
index 29c8175..b9ca621 100644
--- a/raincat-springcloud/src/main/java/org/dromara/raincat/springcloud/feign/RestTemplateConfiguration.java
+++ b/raincat-springcloud/src/main/java/org/dromara/raincat/springcloud/configuration/RaincatFeignConfiguration.java
@@ -16,9 +16,13 @@
*
*/
-package org.dromara.raincat.springcloud.feign;
+package org.dromara.raincat.springcloud.configuration;
+import com.netflix.hystrix.strategy.concurrency.HystrixConcurrencyStrategy;
import feign.RequestInterceptor;
+import org.dromara.raincat.springcloud.feign.RaincatFeignInterceptor;
+import org.dromara.raincat.springcloud.hystrix.RaincatHystrixConcurrencyStrategy;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -28,11 +32,27 @@ import org.springframework.context.annotation.Configuration;
* @author xiaoyu
*/
@Configuration
-public class RestTemplateConfiguration {
+public class RaincatFeignConfiguration {
+ /**
+ * Request interceptor request interceptor.
+ *
+ * @return the request interceptor
+ */
@Bean
public RequestInterceptor requestInterceptor() {
- return new RestTemplateInterceptor();
+ return new RaincatFeignInterceptor();
+ }
+
+ /**
+ * Hystrix concurrency strategy hystrix concurrency strategy.
+ *
+ * @return the hystrix concurrency strategy
+ */
+ @Bean
+ @ConditionalOnProperty(name = "feign.hystrix.enabled")
+ public HystrixConcurrencyStrategy hystrixConcurrencyStrategy() {
+ return new RaincatHystrixConcurrencyStrategy();
}
}
diff --git a/raincat-springcloud/src/main/java/org/dromara/raincat/springcloud/feign/RestTemplateInterceptor.java b/raincat-springcloud/src/main/java/org/dromara/raincat/springcloud/feign/RaincatFeignInterceptor.java
similarity index 75%
rename from raincat-springcloud/src/main/java/org/dromara/raincat/springcloud/feign/RestTemplateInterceptor.java
rename to raincat-springcloud/src/main/java/org/dromara/raincat/springcloud/feign/RaincatFeignInterceptor.java
index 753ddcc..c7024a5 100644
--- a/raincat-springcloud/src/main/java/org/dromara/raincat/springcloud/feign/RestTemplateInterceptor.java
+++ b/raincat-springcloud/src/main/java/org/dromara/raincat/springcloud/feign/RaincatFeignInterceptor.java
@@ -20,18 +20,18 @@ package org.dromara.raincat.springcloud.feign;
import feign.RequestInterceptor;
import feign.RequestTemplate;
-import org.dromara.raincat.common.constant.CommonConstant;
-import org.dromara.raincat.core.concurrent.threadlocal.TxTransactionLocal;
+import org.dromara.raincat.core.mediator.RpcMediator;
/**
* RestTemplateInterceptor.
+ *
* @author xiaoyu
*/
-public class RestTemplateInterceptor implements RequestInterceptor {
+public class RaincatFeignInterceptor implements RequestInterceptor {
@Override
public void apply(final RequestTemplate requestTemplate) {
- requestTemplate.header(CommonConstant.TX_TRANSACTION_GROUP, TxTransactionLocal.getInstance().getTxGroupId());
+ RpcMediator.getInstance().transmit(requestTemplate::header);
}
}
diff --git a/raincat-springcloud/src/main/java/org/dromara/raincat/springcloud/hystrix/RaincatHystrixConcurrencyStrategy.java b/raincat-springcloud/src/main/java/org/dromara/raincat/springcloud/hystrix/RaincatHystrixConcurrencyStrategy.java
new file mode 100644
index 0000000..e41e13d
--- /dev/null
+++ b/raincat-springcloud/src/main/java/org/dromara/raincat/springcloud/hystrix/RaincatHystrixConcurrencyStrategy.java
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.dromara.raincat.springcloud.hystrix;
+
+import com.netflix.hystrix.HystrixThreadPoolKey;
+import com.netflix.hystrix.HystrixThreadPoolProperties;
+import com.netflix.hystrix.strategy.HystrixPlugins;
+import com.netflix.hystrix.strategy.concurrency.HystrixConcurrencyStrategy;
+import com.netflix.hystrix.strategy.concurrency.HystrixRequestVariable;
+import com.netflix.hystrix.strategy.concurrency.HystrixRequestVariableLifecycle;
+import com.netflix.hystrix.strategy.eventnotifier.HystrixEventNotifier;
+import com.netflix.hystrix.strategy.executionhook.HystrixCommandExecutionHook;
+import com.netflix.hystrix.strategy.metrics.HystrixMetricsPublisher;
+import com.netflix.hystrix.strategy.properties.HystrixPropertiesStrategy;
+import com.netflix.hystrix.strategy.properties.HystrixProperty;
+import org.dromara.raincat.core.concurrent.threadlocal.TxTransactionLocal;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * HmilyHystrixConcurrencyStrategy.
+ *
+ * @author xiaoyu
+ */
+public class RaincatHystrixConcurrencyStrategy extends HystrixConcurrencyStrategy {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(RaincatHystrixConcurrencyStrategy.class);
+
+ private HystrixConcurrencyStrategy delegate;
+
+ public RaincatHystrixConcurrencyStrategy() {
+ try {
+ this.delegate = HystrixPlugins.getInstance().getConcurrencyStrategy();
+ if (this.delegate instanceof RaincatHystrixConcurrencyStrategy) {
+ return;
+ }
+ HystrixCommandExecutionHook commandExecutionHook = HystrixPlugins
+ .getInstance().getCommandExecutionHook();
+ HystrixEventNotifier eventNotifier = HystrixPlugins.getInstance()
+ .getEventNotifier();
+ HystrixMetricsPublisher metricsPublisher = HystrixPlugins.getInstance()
+ .getMetricsPublisher();
+ HystrixPropertiesStrategy propertiesStrategy = HystrixPlugins.getInstance()
+ .getPropertiesStrategy();
+ LOGGER.debug("HystrixEventNotifier:{}, HystrixMetricsPublisher:{}, HystrixPropertiesStrategy:{}",
+ eventNotifier, metricsPublisher, propertiesStrategy);
+ HystrixPlugins.reset();
+ HystrixPlugins.getInstance().registerConcurrencyStrategy(this);
+ HystrixPlugins.getInstance()
+ .registerCommandExecutionHook(commandExecutionHook);
+ HystrixPlugins.getInstance().registerEventNotifier(eventNotifier);
+ HystrixPlugins.getInstance().registerMetricsPublisher(metricsPublisher);
+ HystrixPlugins.getInstance().registerPropertiesStrategy(propertiesStrategy);
+ } catch (Exception e) {
+ LOGGER.error("Failed to register Tracing Hystrix Concurrency Strategy", e);
+ }
+ }
+
+ @Override
+ public Callable wrapCallable(Callable callable) {
+ final String groupId =TxTransactionLocal.getInstance().getTxGroupId();
+ return () -> {
+ TxTransactionLocal.getInstance().setTxGroupId(groupId);
+ return delegate.wrapCallable(callable).call();
+ };
+ }
+
+ @Override
+ public ThreadPoolExecutor getThreadPool(final HystrixThreadPoolKey threadPoolKey, HystrixProperty corePoolSize, HystrixProperty maximumPoolSize, HystrixProperty keepAliveTime, TimeUnit unit, BlockingQueue workQueue) {
+ return this.delegate.getThreadPool(threadPoolKey, corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue);
+ }
+
+ @Override
+ public ThreadPoolExecutor getThreadPool(HystrixThreadPoolKey threadPoolKey, HystrixThreadPoolProperties threadPoolProperties) {
+ return this.delegate.getThreadPool(threadPoolKey, threadPoolProperties);
+ }
+
+ @Override
+ public BlockingQueue getBlockingQueue(int maxQueueSize) {
+ return this.delegate.getBlockingQueue(maxQueueSize);
+ }
+
+ @Override
+ public HystrixRequestVariable getRequestVariable(HystrixRequestVariableLifecycle rv) {
+ return this.delegate.getRequestVariable(rv);
+ }
+}
diff --git a/raincat-springcloud/src/main/java/org/dromara/raincat/springcloud/interceptor/SpringCloudTxTransactionAspect.java b/raincat-springcloud/src/main/java/org/dromara/raincat/springcloud/interceptor/SpringCloudTxTransactionAspect.java
index d1021fa..674fb4a 100644
--- a/raincat-springcloud/src/main/java/org/dromara/raincat/springcloud/interceptor/SpringCloudTxTransactionAspect.java
+++ b/raincat-springcloud/src/main/java/org/dromara/raincat/springcloud/interceptor/SpringCloudTxTransactionAspect.java
@@ -26,6 +26,7 @@ import org.springframework.stereotype.Component;
/**
* SpringCloudTxTransactionAspect.
+ *
* @author xiaoyu
*/
@Aspect
@@ -33,6 +34,11 @@ import org.springframework.stereotype.Component;
public class SpringCloudTxTransactionAspect extends AbstractTxTransactionAspect implements Ordered {
+ /**
+ * Instantiates a new Spring cloud tx transaction aspect.
+ *
+ * @param springCloudTxTransactionInterceptor the spring cloud tx transaction interceptor
+ */
@Autowired
public SpringCloudTxTransactionAspect(final SpringCloudTxTransactionInterceptor springCloudTxTransactionInterceptor) {
this.setTxTransactionInterceptor(springCloudTxTransactionInterceptor);
diff --git a/raincat-springcloud/src/main/java/org/dromara/raincat/springcloud/interceptor/SpringCloudTxTransactionInterceptor.java b/raincat-springcloud/src/main/java/org/dromara/raincat/springcloud/interceptor/SpringCloudTxTransactionInterceptor.java
index 7211b9c..b6cb21a 100644
--- a/raincat-springcloud/src/main/java/org/dromara/raincat/springcloud/interceptor/SpringCloudTxTransactionInterceptor.java
+++ b/raincat-springcloud/src/main/java/org/dromara/raincat/springcloud/interceptor/SpringCloudTxTransactionInterceptor.java
@@ -20,10 +20,10 @@ package org.dromara.raincat.springcloud.interceptor;
import org.apache.commons.lang3.StringUtils;
import org.aspectj.lang.ProceedingJoinPoint;
-import org.dromara.raincat.common.constant.CommonConstant;
import org.dromara.raincat.common.holder.LogUtil;
import org.dromara.raincat.core.concurrent.threadlocal.CompensationLocal;
import org.dromara.raincat.core.interceptor.TxTransactionInterceptor;
+import org.dromara.raincat.core.mediator.RpcMediator;
import org.dromara.raincat.core.service.AspectTransactionService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -61,9 +61,9 @@ public class SpringCloudTxTransactionInterceptor implements TxTransactionInterce
try {
RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes();
HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest();
- groupId = request.getHeader(CommonConstant.TX_TRANSACTION_GROUP);
+ groupId = RpcMediator.getInstance().acquire(request::getHeader);
} catch (IllegalStateException e) {
- LogUtil.error(LOGGER,"Not Http request ,can't get RequestContextHolder!", e::getMessage);
+ LogUtil.error(LOGGER, "Not Http request ,can't get RequestContextHolder!", e::getMessage);
}
}
return aspectTransactionService.invoke(groupId, pjp);
diff --git a/raincat-springcloud/src/main/java/org/dromara/raincat/springcloud/service/SpringCloudRpcApplicationServiceImpl.java b/raincat-springcloud/src/main/java/org/dromara/raincat/springcloud/service/SpringCloudRpcApplicationServiceImpl.java
index 73574d5..48a8c7d 100644
--- a/raincat-springcloud/src/main/java/org/dromara/raincat/springcloud/service/SpringCloudRpcApplicationServiceImpl.java
+++ b/raincat-springcloud/src/main/java/org/dromara/raincat/springcloud/service/SpringCloudRpcApplicationServiceImpl.java
@@ -18,22 +18,32 @@
package org.dromara.raincat.springcloud.service;
+import org.apache.commons.lang3.RandomUtils;
import org.dromara.raincat.core.service.RpcApplicationService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
+import java.util.Optional;
+
/**
* SpringCloudRpcApplicationServiceImpl.
+ *
* @author xiaoyu
*/
@Service("rpcApplicationService")
public class SpringCloudRpcApplicationServiceImpl implements RpcApplicationService {
+ private static final String DEFAULT_APPLICATION_NAME = "raincat-springCloud";
+
@Value("${spring.application.name}")
- private String modelName;
+ private String appName;
@Override
public String findModelName() {
- return modelName;
+ return Optional.ofNullable(appName).orElse(buildDefaultApplicationName());
+ }
+
+ private String buildDefaultApplicationName() {
+ return DEFAULT_APPLICATION_NAME + RandomUtils.nextInt(1, 10);
}
}