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)

This commit is contained in:
Carlos Ruiz 2018-03-13 17:40:12 -03:00
parent 81066b1498
commit 14536e9848
4 changed files with 102 additions and 1 deletions

View File

@ -117,7 +117,7 @@ public class DB_PostgreSQL implements AdempiereDatabase
public static final String NATIVE_MARKER = "NATIVE_"+Database.DB_POSTGRESQL+"_KEYWORK";
private CCache<String, String> convertCache = new CCache<String, String>(null, "DB_PostgreSQL_Convert_Cache", 1000, 60, true);
private CCache<String, String> convertCache = new CCache<String, String>(null, "DB_PostgreSQL_Convert_Cache", 1000, 60, false);
private Random rand = new Random();

View File

@ -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

View File

@ -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() {

View File

@ -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<Member> 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<DistributedObject> 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<Object, Object> map = instance.getMap(object.getName());
sb.append(" #" + map.size());
} else if (SetService.SERVICE_NAME.equals(object.getServiceName())) {
ISet<Object> set = instance.getSet(object.getName());
sb.append(" #" + set.size());
}
}
}
console.println(sb.toString());
return null;
}
}