From 14536e9848ef32ea3f13e141524476750978b045 Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Tue, 13 Mar 2018 17:40:12 -0300 Subject: [PATCH] IDEMPIERE-3653 Hazelcast improvements / make explicit DB_PostgreSQL cache as non-distributed (it was already non distributed because postgres plugin start before hazelcast instance) / add commands hazelcastStatus and hazelcastObjects to OSGi console (thanks to Eduardo Moreira eduardojm for the idea and code) --- .../src/org/compiere/db/DB_PostgreSQL.java | 2 +- .../META-INF/MANIFEST.MF | 1 + .../hazelcast/service/Activator.java | 2 + .../service/CacheConsoleProvider.java | 98 +++++++++++++++++++ 4 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 org.idempiere.hazelcast.service/src/org/idempiere/hazelcast/service/CacheConsoleProvider.java diff --git a/org.compiere.db.postgresql.provider/src/org/compiere/db/DB_PostgreSQL.java b/org.compiere.db.postgresql.provider/src/org/compiere/db/DB_PostgreSQL.java index bb0ebeea9a..f4194b8527 100755 --- a/org.compiere.db.postgresql.provider/src/org/compiere/db/DB_PostgreSQL.java +++ b/org.compiere.db.postgresql.provider/src/org/compiere/db/DB_PostgreSQL.java @@ -117,7 +117,7 @@ public class DB_PostgreSQL implements AdempiereDatabase public static final String NATIVE_MARKER = "NATIVE_"+Database.DB_POSTGRESQL+"_KEYWORK"; - private CCache convertCache = new CCache(null, "DB_PostgreSQL_Convert_Cache", 1000, 60, true); + private CCache convertCache = new CCache(null, "DB_PostgreSQL_Convert_Cache", 1000, 60, false); private Random rand = new Random(); diff --git a/org.idempiere.hazelcast.service/META-INF/MANIFEST.MF b/org.idempiere.hazelcast.service/META-INF/MANIFEST.MF index 3b015ca2fa..331272f59d 100644 --- a/org.idempiere.hazelcast.service/META-INF/MANIFEST.MF +++ b/org.idempiere.hazelcast.service/META-INF/MANIFEST.MF @@ -30,3 +30,4 @@ Bundle-ClassPath: ., hazelcast-aws-2.1.0.jar Service-Component: OSGI-INF/clusterservice.xml, OSGI-INF/cacheservice.xml, OSGI-INF/messageservice.xml Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: org.eclipse.osgi diff --git a/org.idempiere.hazelcast.service/src/org/idempiere/hazelcast/service/Activator.java b/org.idempiere.hazelcast.service/src/org/idempiere/hazelcast/service/Activator.java index 6d24d1929b..1c3c22a1f4 100644 --- a/org.idempiere.hazelcast.service/src/org/idempiere/hazelcast/service/Activator.java +++ b/org.idempiere.hazelcast.service/src/org/idempiere/hazelcast/service/Activator.java @@ -24,6 +24,7 @@ import java.util.Enumeration; import org.compiere.Adempiere; import org.compiere.model.ServerStateChangeEvent; import org.compiere.model.ServerStateChangeListener; +import org.eclipse.osgi.framework.console.CommandProvider; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; @@ -67,6 +68,7 @@ public class Activator implements BundleActivator { } }); } + bundleContext.registerService(CommandProvider.class.getName(), new CacheConsoleProvider(), null); } private static synchronized void createHazelCastInstance() { diff --git a/org.idempiere.hazelcast.service/src/org/idempiere/hazelcast/service/CacheConsoleProvider.java b/org.idempiere.hazelcast.service/src/org/idempiere/hazelcast/service/CacheConsoleProvider.java new file mode 100644 index 0000000000..e97d662678 --- /dev/null +++ b/org.idempiere.hazelcast.service/src/org/idempiere/hazelcast/service/CacheConsoleProvider.java @@ -0,0 +1,98 @@ +package org.idempiere.hazelcast.service; + +import java.util.Collection; +import java.util.Set; + +import org.eclipse.osgi.framework.console.CommandInterpreter; +import org.eclipse.osgi.framework.console.CommandProvider; + +import com.hazelcast.collection.impl.set.SetService; +import com.hazelcast.core.Cluster; +import com.hazelcast.core.DistributedObject; +import com.hazelcast.core.HazelcastInstance; +import com.hazelcast.core.IMap; +import com.hazelcast.core.ISet; +import com.hazelcast.core.Member; +import com.hazelcast.map.impl.MapService; + +public class CacheConsoleProvider implements CommandProvider { + + /* + * (non-Javadoc) + * + * @see org.eclipse.osgi.framework.console.CommandProvider#getHelp() + */ + @Override + public String getHelp() { + + final StringBuilder buffer = new StringBuilder(); + buffer.append("---- Hazelcast plugin console commands: "); + buffer.append("\n\t hazelcastStatus – print informations of current hazelcast Server"); + buffer.append("\n\t hazelcastObjects – list all distributed objects saved into hazelcast Server"); + return buffer.toString(); + + } + + public Object _hazelcastStatus(final CommandInterpreter console) { + + console.nextArgument(); + + final StringBuilder sb = new StringBuilder(); + + if (Activator.getHazelcastInstance() == null) { + sb.append("\n hazelcast not started."); + } else { + + HazelcastInstance instance = Activator.getHazelcastInstance(); + Cluster cluster = instance.getCluster(); + Set members = cluster.getMembers(); + + if (members != null) { + + for (Member member : members) { + sb.append("hazelcast "); + sb.append(member.getUuid()); + sb.append(" Node Server: "); + sb.append(member.getSocketAddress()); + sb.append("\n"); + } + } + } + + console.println(sb.toString()); + + return null; + } + + public Object _hazelcastObjects(final CommandInterpreter console) { + + final StringBuilder sb = new StringBuilder(); + + if (Activator.getHazelcastInstance() == null) { + sb.append("\n hazelcast not started."); + } else { + + HazelcastInstance instance = Activator.getHazelcastInstance(); + Collection objects = instance.getDistributedObjects(); + sb.append("\nHave "); + sb.append(objects.size()); + sb.append(" keys:"); + for (DistributedObject object : objects) { + sb.append("\n\t"); + sb.append(object.getServiceName() + "->" + object.getName()); + if (MapService.SERVICE_NAME.equals(object.getServiceName())) { + IMap map = instance.getMap(object.getName()); + sb.append(" #" + map.size()); + } else if (SetService.SERVICE_NAME.equals(object.getServiceName())) { + ISet set = instance.getSet(object.getName()); + sb.append(" #" + set.size()); + } + } + } + + console.println(sb.toString()); + + return null; + } + +}