From 2706026b8568cf931902dafbe43738b6a59368dd Mon Sep 17 00:00:00 2001 From: hengsin Date: Sat, 13 Jun 2020 22:00:04 +0800 Subject: [PATCH] IDEMPIERE-4331 Do not use Hazelcast Cache Service if it is standalone (#113) Use normal map if hazelcast is stand alone --- .../src/org/compiere/util/CacheMgt.java | 6 +++++- .../distributed/IClusterService.java | 8 +++++++ .../hazelcast/service/ClusterServiceImpl.java | 21 +++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/org.adempiere.base/src/org/compiere/util/CacheMgt.java b/org.adempiere.base/src/org/compiere/util/CacheMgt.java index 8574d4198f..c2671ce25b 100644 --- a/org.adempiere.base/src/org/compiere/util/CacheMgt.java +++ b/org.adempiere.base/src/org/compiere/util/CacheMgt.java @@ -109,7 +109,11 @@ public class CacheMgt { ICacheService provider = Service.locator().locate(ICacheService.class).getService(); if (provider != null) - map = provider.getMap(name); + { + IClusterService clusterService = Service.locator().locate(IClusterService.class).getService(); + if (clusterService != null && !clusterService.isStandAlone()) + map = provider.getMap(name); + } } if (map == null) diff --git a/org.adempiere.base/src/org/idempiere/distributed/IClusterService.java b/org.adempiere.base/src/org/idempiere/distributed/IClusterService.java index b38a9aa357..f58c09adb0 100644 --- a/org.adempiere.base/src/org/idempiere/distributed/IClusterService.java +++ b/org.adempiere.base/src/org/idempiere/distributed/IClusterService.java @@ -38,4 +38,12 @@ public interface IClusterService { * @return Map of IClusterMember and Future */ public Map> execute(Callable task, Collection members); + + /** + * + * @return true if instance is stand alone + */ + public default boolean isStandAlone() { + return false; + } } diff --git a/org.idempiere.hazelcast.service/src/org/idempiere/hazelcast/service/ClusterServiceImpl.java b/org.idempiere.hazelcast.service/src/org/idempiere/hazelcast/service/ClusterServiceImpl.java index 716312f9e3..68384d3f7c 100644 --- a/org.idempiere.hazelcast.service/src/org/idempiere/hazelcast/service/ClusterServiceImpl.java +++ b/org.idempiere.hazelcast.service/src/org/idempiere/hazelcast/service/ClusterServiceImpl.java @@ -27,6 +27,8 @@ import org.idempiere.distributed.IClusterService; import com.hazelcast.core.HazelcastInstance; import com.hazelcast.core.IExecutorService; import com.hazelcast.core.Member; +import com.hazelcast.instance.HazelcastInstanceImpl; +import com.hazelcast.instance.HazelcastInstanceProxy; /** * @author hengsin @@ -114,4 +116,23 @@ public class ClusterServiceImpl implements IClusterService { return null; } + @Override + public boolean isStandAlone() { + HazelcastInstance instance = Activator.getHazelcastInstance(); + if (instance != null) { + if (instance instanceof HazelcastInstanceImpl) { + HazelcastInstanceImpl impl = (HazelcastInstanceImpl) instance; + return impl.node.getJoiner() == null; + } else if (instance instanceof HazelcastInstanceProxy) { + HazelcastInstanceProxy proxy = (HazelcastInstanceProxy) instance; + HazelcastInstanceImpl impl = proxy.getOriginal(); + return impl.node.getJoiner() == null; + } else { + return false; + } + } else { + return true; + } + } + }