IDEMPIERE-4331 Do not use Hazelcast Cache Service if it is standalone (#113)

Use normal map if hazelcast is stand alone
This commit is contained in:
hengsin 2020-06-13 22:00:04 +08:00 committed by GitHub
parent aac7d81077
commit 2706026b85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 1 deletions

View File

@ -109,8 +109,12 @@ public class CacheMgt
{ {
ICacheService provider = Service.locator().locate(ICacheService.class).getService(); ICacheService provider = Service.locator().locate(ICacheService.class).getService();
if (provider != null) if (provider != null)
{
IClusterService clusterService = Service.locator().locate(IClusterService.class).getService();
if (clusterService != null && !clusterService.isStandAlone())
map = provider.getMap(name); map = provider.getMap(name);
} }
}
if (map == null) if (map == null)
{ {

View File

@ -38,4 +38,12 @@ public interface IClusterService {
* @return Map of IClusterMember and Future * @return Map of IClusterMember and Future
*/ */
public <V> Map<IClusterMember, Future<V>> execute(Callable<V> task, Collection<IClusterMember> members); public <V> Map<IClusterMember, Future<V>> execute(Callable<V> task, Collection<IClusterMember> members);
/**
*
* @return true if instance is stand alone
*/
public default boolean isStandAlone() {
return false;
}
} }

View File

@ -27,6 +27,8 @@ import org.idempiere.distributed.IClusterService;
import com.hazelcast.core.HazelcastInstance; import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.IExecutorService; import com.hazelcast.core.IExecutorService;
import com.hazelcast.core.Member; import com.hazelcast.core.Member;
import com.hazelcast.instance.HazelcastInstanceImpl;
import com.hazelcast.instance.HazelcastInstanceProxy;
/** /**
* @author hengsin * @author hengsin
@ -114,4 +116,23 @@ public class ClusterServiceImpl implements IClusterService {
return null; 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;
}
}
} }