Skip to content

Commit

Permalink
feature:seata-integration-tx-api
Browse files Browse the repository at this point in the history
  • Loading branch information
lightClouds917 committed Dec 23, 2024
1 parent 16beebf commit 45c5c78
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

import org.apache.seata.common.lock.ResourceLock;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public final class TccHookManager {
private static final Logger LOGGER = LoggerFactory.getLogger(TccHookManager.class);
private static final ResourceLock LOCK = new ResourceLock();


private TccHookManager() {

Expand All @@ -40,7 +43,7 @@ private TccHookManager() {
*/
public static List<TccHook> getHooks() {
if (CACHED_UNMODIFIABLE_HOOKS == null) {
synchronized (TccHookManager.class) {
try (ResourceLock ignored = LOCK.obtain()) {
if (CACHED_UNMODIFIABLE_HOOKS == null) {
CACHED_UNMODIFIABLE_HOOKS = Collections.unmodifiableList(TCC_HOOKS);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import org.apache.seata.common.exception.FrameworkException;
import org.apache.seata.common.loader.EnhancedServiceLoader;
import org.apache.seata.common.lock.ResourceLock;
import org.apache.seata.common.util.CollectionUtils;
import org.apache.seata.integration.tx.api.remoting.RemotingDesc;
import org.apache.seata.integration.tx.api.remoting.RemotingParser;
Expand All @@ -43,6 +44,8 @@ public class DefaultRemotingParser {
*/
protected static Map<Object, RemotingDesc> remotingServiceMap = new ConcurrentHashMap<>();

private final ResourceLock resourceLock = new ResourceLock();

private static class SingletonHolder {
private static final DefaultRemotingParser INSTANCE = new DefaultRemotingParser();
}
Expand Down Expand Up @@ -79,7 +82,7 @@ protected void initRemotingParser() {
* @param remotingParser
*/
public boolean registerRemotingParser(RemotingParser remotingParser) {
synchronized (this) {
try (ResourceLock ignored = resourceLock.obtain()) {
return allRemotingParsers.add(remotingParser);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package org.apache.seata.integration.tx.api.util;

import org.apache.seata.common.lock.ResourceLock;
import org.apache.seata.integration.tx.api.interceptor.handler.DefaultInvocationHandler;
import org.apache.seata.integration.tx.api.interceptor.handler.ProxyInvocationHandler;
import org.apache.seata.integration.tx.api.interceptor.parser.DefaultInterfaceParser;
Expand All @@ -31,6 +32,7 @@
public class ProxyUtil {

private static final Map<Object, Object> PROXYED_SET = new HashMap<>();
private static final ResourceLock RESOURCE_LOCK = new ResourceLock();

public static <T> T createProxy(T target) {
return createProxy(target, target.getClass().getName());
Expand All @@ -53,7 +55,7 @@ public static <T> T createProxy(T target) {
*/
public static <T> T createProxy(T target, String beanName) {
try {
synchronized (PROXYED_SET) {
try (ResourceLock ignored = RESOURCE_LOCK.obtain()) {
if (PROXYED_SET.containsKey(target)) {
return (T) PROXYED_SET.get(target);
}
Expand Down

0 comments on commit 45c5c78

Please sign in to comment.