diff --git a/org.adempiere.base/src/org/compiere/model/GridTab.java b/org.adempiere.base/src/org/compiere/model/GridTab.java index 2c46d271fe..a825f2f3ce 100644 --- a/org.adempiere.base/src/org/compiere/model/GridTab.java +++ b/org.adempiere.base/src/org/compiere/model/GridTab.java @@ -2352,7 +2352,7 @@ public class GridTab implements DataStatusListener, Evaluatee, Serializable return; // avoid NPE below } DataStatusListener[] listeners = m_listenerList.getListeners(DataStatusListener.class); - if (listeners.length == 0) + if (listeners.length == 0 || e == null) return; if (log.isLoggable(Level.FINE)) log.fine(e.toString()); // WHO Info diff --git a/org.adempiere.base/src/org/compiere/util/CacheMgt.java b/org.adempiere.base/src/org/compiere/util/CacheMgt.java index 0d7031b692..bb90b0c844 100644 --- a/org.adempiere.base/src/org/compiere/util/CacheMgt.java +++ b/org.adempiere.base/src/org/compiere/util/CacheMgt.java @@ -166,9 +166,9 @@ public class CacheMgt int total = 0; try { Collection> results = futureMap.values(); - for(Future future : results) { - Integer i = future.get(); - total += i.intValue(); + for(Future i : results) + { + total += i.get(); } } catch (InterruptedException e) { e.printStackTrace(); diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/desktop/DefaultDesktop.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/desktop/DefaultDesktop.java index 8858e7ad9b..61799af222 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/desktop/DefaultDesktop.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/desktop/DefaultDesktop.java @@ -191,7 +191,11 @@ public class DefaultDesktop extends TabbedDesktop implements MenuListener, Seria m_desktop.addListener(this); //subscribing to broadcast event bindEventManager(); - ZKBroadCastManager.getBroadCastMgr(); + try { + ZKBroadCastManager.getBroadCastMgr(); + } catch (Throwable e) { + e.printStackTrace(); + } EventQueue queue = EventQueues.lookup(ACTIVITIES_EVENT_QUEUE, true); queue.subscribe(this); diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/event/ZKBroadCastManager.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/event/ZKBroadCastManager.java index 21cf5347c9..a377be1a08 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/event/ZKBroadCastManager.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/event/ZKBroadCastManager.java @@ -31,7 +31,7 @@ public class ZKBroadCastManager implements ITopicSubscriber{ public static ZKBroadCastManager getBroadCastMgr() { return broadCastMgr; } - + private ZKBroadCastManager(){ BroadCastUtil.subscribe(this); } diff --git a/org.idempiere.hazelcast.service.config/hazelcast.xml b/org.idempiere.hazelcast.service.config/hazelcast.xml index 38d2f63938..cb80f192e2 100644 --- a/org.idempiere.hazelcast.service.config/hazelcast.xml +++ b/org.idempiere.hazelcast.service.config/hazelcast.xml @@ -1,6 +1,6 @@ - + + @@ -24,7 +30,7 @@ http://localhost:8080/mancenter - 5701 + 5701 us-west-1 - ec2.amazonaws.com + ec2.amazonaws.com hazelcast-sg type hz-nodes + + 10.10.1.* - - + + 19 - - - RSA/NONE/PKCS1PADDING - - thekeypass - - local - - JKS - - thestorepass - - keystore - - - 16 - 64 - 60 + + 16 + + 0 - 0 + 0 - default + 1 + + + 0 + + -1 + + BINARY + - 1000 + 1000 25 + + 100 - hz.ADD_NEW_ENTRY + com.hazelcast.map.merge.PutIfAbsentMapMergePolicy + + + INDEX-ONLY + - - + + + mapName + 10000 + 0 + - \ No newline at end of file + + cacheName + 10000 + 0 + + + + 1 + SET + + + + 1 + + + + 1 + + + + 0 + + 0 + 0 + 1000 + true + CANCEL_RUNNING_OPERATION + + + + 0 + 1 + 0 + + + + 10 + BLOCK + true + + + + 10000 + 1 + 0 + 0 + BINARY + + + + 0 + + + + + + + diff --git a/org.idempiere.hazelcast.service/.classpath b/org.idempiere.hazelcast.service/.classpath index c250c40b89..b1895c3cdf 100644 --- a/org.idempiere.hazelcast.service/.classpath +++ b/org.idempiere.hazelcast.service/.classpath @@ -3,7 +3,7 @@ - - + + diff --git a/org.idempiere.hazelcast.service/META-INF/MANIFEST.MF b/org.idempiere.hazelcast.service/META-INF/MANIFEST.MF index c2b48993f7..69d57654ef 100644 --- a/org.idempiere.hazelcast.service/META-INF/MANIFEST.MF +++ b/org.idempiere.hazelcast.service/META-INF/MANIFEST.MF @@ -26,7 +26,7 @@ Import-Package: javax.crypto, org.w3c.dom DynamicImport-Package: * Bundle-ClassPath: ., - hazelcast-3.5.3.jar, - hazelcast-cloud-3.5.3.jar + hazelcast-3.9.3.jar, + 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 diff --git a/org.idempiere.hazelcast.service/build.properties b/org.idempiere.hazelcast.service/build.properties index b7cd66310a..a3ff5a1c9a 100644 --- a/org.idempiere.hazelcast.service/build.properties +++ b/org.idempiere.hazelcast.service/build.properties @@ -5,6 +5,6 @@ bin.includes = META-INF/,\ OSGI-INF/cacheservice.xml,\ OSGI-INF/messageservice.xml,\ OSGI-INF/,\ - hazelcast-3.5.3.jar,\ - hazelcast-cloud-3.5.3.jar + hazelcast-3.9.3.jar,\ + hazelcast-aws-2.1.0.jar source.. = src/ diff --git a/org.idempiere.hazelcast.service/copyjars.xml b/org.idempiere.hazelcast.service/copyjars.xml index 7a8e1e61c2..01e8483eb0 100644 --- a/org.idempiere.hazelcast.service/copyjars.xml +++ b/org.idempiere.hazelcast.service/copyjars.xml @@ -1,6 +1,6 @@ - - + + 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 bfd2eb49fe..6d24d1929b 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 @@ -20,9 +20,6 @@ import java.net.URL; import java.text.DateFormat; import java.util.Date; import java.util.Enumeration; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.Future; -import java.util.concurrent.ScheduledThreadPoolExecutor; import org.compiere.Adempiere; import org.compiere.model.ServerStateChangeEvent; @@ -34,7 +31,8 @@ import com.hazelcast.config.Config; import com.hazelcast.config.FileSystemXmlConfig; import com.hazelcast.config.MapConfig; import com.hazelcast.config.UrlXmlConfig; -import com.hazelcast.core.*; +import com.hazelcast.core.Hazelcast; +import com.hazelcast.core.HazelcastInstance; /** * @@ -50,7 +48,6 @@ public class Activator implements BundleActivator { } private volatile static HazelcastInstance hazelcastInstance; - private static Future future; /* * (non-Javadoc) @@ -65,7 +62,7 @@ public class Activator implements BundleActivator { Adempiere.addServerStateChangeListener(new ServerStateChangeListener() { @Override public void stateChange(ServerStateChangeEvent event) { - if (event.getEventType() == ServerStateChangeEvent.SERVER_START) + if (event.getEventType() == ServerStateChangeEvent.SERVER_START) createHazelCastInstance(); } }); @@ -73,14 +70,19 @@ public class Activator implements BundleActivator { } private static synchronized void createHazelCastInstance() { - ScheduledThreadPoolExecutor executor = Adempiere.getThreadPoolExecutor(); - - future = executor.submit(new Runnable() { - @Override - public void run() { - File file = null; - //try idempiere home - String dataArea = System.getProperty("IDEMPIERE_HOME"); + File file = null; + //try idempiere home + String dataArea = System.getProperty("IDEMPIERE_HOME"); + if (dataArea != null && dataArea.trim().length() > 0) { + try { + file = new File(dataArea, "hazelcast.xml"); + if (!file.exists()) + file = null; + } catch (Exception e) {} + } + //try working directory + if (file == null) { + dataArea = System.getProperty("user.dir"); if (dataArea != null && dataArea.trim().length() > 0) { try { file = new File(dataArea, "hazelcast.xml"); @@ -88,88 +90,68 @@ public class Activator implements BundleActivator { file = null; } catch (Exception e) {} } - //try working directory - if (file == null) { - dataArea = System.getProperty("user.dir"); - if (dataArea != null && dataArea.trim().length() > 0) { - try { - file = new File(dataArea, "hazelcast.xml"); - if (!file.exists()) - file = null; - } catch (Exception e) {} - } - } - //try osgi install area - if (file == null) { - dataArea = System.getProperty("osgi.install.area"); - if (dataArea != null && dataArea.trim().length() > 0) { - try { - URL url = new URL(dataArea); - file = new File(url.getPath(), "hazelcast.xml"); - if (!file.exists()) - file = null; - } catch (Exception e) {} - } - } - //try hazelcast.config - to be consistent with hazelcast configuration documentation - if (file == null) { - dataArea = System.getProperty("hazelcast.config"); - if (dataArea != null && dataArea.trim().length() > 0) { - try { - file = new File(dataArea); - if (!file.exists()) - file = null; - } catch (Exception e) {} - } - } - if (file != null && file.exists()) { + } + //try osgi install area + if (file == null) { + dataArea = System.getProperty("osgi.install.area"); + if (dataArea != null && dataArea.trim().length() > 0) { try { - Config config = new FileSystemXmlConfig(file); - config.setClassLoader(getClass().getClassLoader()); - hazelcastInstance = Hazelcast.newHazelcastInstance(config); - MapConfig mc = config.getMapConfig("default"); - if (mc != null) { - System.out.println("Hazelcast Max Size Config: "+mc.getMaxSizeConfig().getMaxSizePolicy() + " " + mc.getMaxSizeConfig().getSize()); - } - return; - } catch (FileNotFoundException e) {} - } - - Enumeration entries = getContext().getBundle().findEntries("/", "hazelcast.xml", false); - URL url = entries.hasMoreElements() ? entries.nextElement() : null; - if (url != null) { - try { - Config config = new UrlXmlConfig(url); - config.setClassLoader(getClass().getClassLoader()); - hazelcastInstance = Hazelcast.newHazelcastInstance(config); - MapConfig mc = config.getMapConfig("default"); - if (mc != null) { - System.out.println("Hazelcast Max Size Config: "+mc.getMaxSizeConfig().getMaxSizePolicy() + " " + mc.getMaxSizeConfig().getSize()); - } - return; - } catch (IOException e) {} - } - - Config config = new Config(); - config.setClassLoader(getClass().getClassLoader()); - hazelcastInstance = Hazelcast.newHazelcastInstance(config); - MapConfig mc = config.getMapConfig("default"); - if (mc != null) { - System.out.println("Hazelcast Max Size Config: "+mc.getMaxSizeConfig().getMaxSizePolicy() + " " + mc.getMaxSizeConfig().getSize()); + URL url = new URL(dataArea); + file = new File(url.getPath(), "hazelcast.xml"); + if (!file.exists()) + file = null; + } catch (Exception e) {} } } - }); + //try hazelcast.config - to be consistent with hazelcast configuration documentation + if (file == null) { + dataArea = System.getProperty("hazelcast.config"); + if (dataArea != null && dataArea.trim().length() > 0) { + try { + file = new File(dataArea); + if (!file.exists()) + file = null; + } catch (Exception e) {} + } + } + if (file != null && file.exists()) { + try { + Config config = new FileSystemXmlConfig(file); + config.setClassLoader(Activator.class.getClassLoader()); + hazelcastInstance = Hazelcast.newHazelcastInstance(config); + MapConfig mc = config.getMapConfig("default"); + if (mc != null) { + System.out.println("Hazelcast Max Size Config: "+mc.getMaxSizeConfig().getMaxSizePolicy() + " " + mc.getMaxSizeConfig().getSize()); + } + return; + } catch (FileNotFoundException e) {} + } + + Enumeration entries = getContext().getBundle().findEntries("/", "hazelcast.xml", false); + URL url = entries.hasMoreElements() ? entries.nextElement() : null; + if (url != null) { + try { + Config config = new UrlXmlConfig(url); + config.setClassLoader(Activator.class.getClassLoader()); + hazelcastInstance = Hazelcast.newHazelcastInstance(config); + MapConfig mc = config.getMapConfig("default"); + if (mc != null) { + System.out.println("Hazelcast Max Size Config: "+mc.getMaxSizeConfig().getMaxSizePolicy() + " " + mc.getMaxSizeConfig().getSize()); + } + return; + } catch (IOException e) {} + } + + Config config = new Config(); + config.setClassLoader(Activator.class.getClassLoader()); + hazelcastInstance = Hazelcast.newHazelcastInstance(config); + MapConfig mc = config.getMapConfig("default"); + if (mc != null) { + System.out.println("Hazelcast Max Size Config: "+mc.getMaxSizeConfig().getMaxSizePolicy() + " " + mc.getMaxSizeConfig().getSize()); + } } public static synchronized HazelcastInstance getHazelcastInstance() { - if (future != null && !future.isDone()) { - try { - future.get(); - } catch (InterruptedException e) { - } catch (ExecutionException e) { - } - } - if (hazelcastInstance != null) { if (!hazelcastInstance.getLifecycleService().isRunning()) { System.err.println(DateFormat.getDateTimeInstance().format(new Date()) + " Hazelcast instance is down!"); @@ -200,9 +182,7 @@ public class Activator implements BundleActivator { public void stop(BundleContext bundleContext) throws Exception { Activator.context = null; synchronized (Activator.class) { - if (future != null && !future.isDone()) { - future.cancel(true); - } else if (hazelcastInstance != null) { + if (hazelcastInstance != null) { hazelcastInstance.getLifecycleService().shutdown(); hazelcastInstance = null; } diff --git a/org.idempiere.hazelcast.service/src/org/idempiere/hazelcast/service/ClusterMember.java b/org.idempiere.hazelcast.service/src/org/idempiere/hazelcast/service/ClusterMember.java index 73d33b389f..edd71d2f69 100644 --- a/org.idempiere.hazelcast.service/src/org/idempiere/hazelcast/service/ClusterMember.java +++ b/org.idempiere.hazelcast.service/src/org/idempiere/hazelcast/service/ClusterMember.java @@ -17,6 +17,8 @@ import java.net.InetAddress; import org.idempiere.distributed.IClusterMember; +import com.hazelcast.core.Member; + /** * @author hengsin * @@ -37,6 +39,12 @@ public class ClusterMember implements IClusterMember { this.port = port; } + public ClusterMember(Member member) { + this.id = member.getUuid(); + this.address = member.getSocketAddress().getAddress(); + this.port = member.getSocketAddress().getPort(); + } + /* (non-Javadoc) * @see org.idempiere.distributed.IClusterMember#getId() */ 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 4b7f48b1be..716312f9e3 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 @@ -14,8 +14,8 @@ package org.idempiere.hazelcast.service; import java.util.Collection; -import java.util.HashMap; import java.util.HashSet; +import java.util.LinkedHashMap; import java.util.Map; import java.util.Set; import java.util.concurrent.Callable; @@ -25,6 +25,7 @@ import org.idempiere.distributed.IClusterMember; import org.idempiere.distributed.IClusterService; import com.hazelcast.core.HazelcastInstance; +import com.hazelcast.core.IExecutorService; import com.hazelcast.core.Member; /** @@ -43,7 +44,7 @@ public class ClusterServiceImpl implements IClusterService { if (instance != null) { Set members = instance.getCluster().getMembers(); for(Member member : members) { - clusterMembers.add(new ClusterMember(member.getUuid(), member.getSocketAddress().getAddress(), member.getSocketAddress().getPort())); + clusterMembers.add(new ClusterMember(member)); } } return clusterMembers; @@ -57,7 +58,7 @@ public class ClusterServiceImpl implements IClusterService { HazelcastInstance instance = Activator.getHazelcastInstance(); if (instance != null) { Member member = instance.getCluster().getLocalMember(); - return new ClusterMember(member.getUuid(), member.getSocketAddress().getAddress(), member.getSocketAddress().getPort()); + return new ClusterMember(member); } else { return null; } @@ -73,7 +74,8 @@ public class ClusterServiceImpl implements IClusterService { Set members = instance.getCluster().getMembers(); for(Member member : members) { if (member.getUuid().equals(clusterMember.getId())) { - return Activator.getHazelcastInstance().getExecutorService("default").submitToMember(task, member); + IExecutorService service = Activator.getHazelcastInstance().getExecutorService("default"); + return service.submitToMember(task, member); } } } @@ -100,13 +102,13 @@ public class ClusterServiceImpl implements IClusterService { } } if (selectedMembers.size() > 0) { - Map> maps = Activator.getHazelcastInstance().getExecutorService("default").submitToMembers(task, selectedMembers); - Map> result = new HashMap>(); - for(Member m : maps.keySet()) { - ClusterMember cm = new ClusterMember(m.getUuid(), m.getSocketAddress().getAddress(), m.getSocketAddress().getPort()); - result.put(cm, maps.get(m)); + IExecutorService service = Activator.getHazelcastInstance().getExecutorService("default"); + Map> map = service.submitToMembers(task, selectedMembers); + Map> futureMap = new LinkedHashMap<>(); + for(Member member : map.keySet()) { + futureMap.put(new ClusterMember(member), map.get(member)); } - return result; + return futureMap; } } return null; diff --git a/org.idempiere.hazelcast.service/src/org/idempiere/hazelcast/service/TopicImpl.java b/org.idempiere.hazelcast.service/src/org/idempiere/hazelcast/service/TopicImpl.java index c0918d16f4..f2e7c81446 100644 --- a/org.idempiere.hazelcast.service/src/org/idempiere/hazelcast/service/TopicImpl.java +++ b/org.idempiere.hazelcast.service/src/org/idempiere/hazelcast/service/TopicImpl.java @@ -14,7 +14,9 @@ package org.idempiere.hazelcast.service; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.idempiere.distributed.ITopic; import org.idempiere.distributed.ITopicSubscriber; @@ -31,6 +33,7 @@ public class TopicImpl implements ITopic { private com.hazelcast.core.ITopic topic; private List> adapters; + private Map, String> registrationMap; /** * @@ -38,6 +41,7 @@ public class TopicImpl implements ITopic { public TopicImpl(com.hazelcast.core.ITopic topic) { this.topic = topic; adapters = new ArrayList>(); + registrationMap = new HashMap<>(); } @Override @@ -48,8 +52,9 @@ public class TopicImpl implements ITopic { @Override public void subscribe(final ITopicSubscriber subscriber) { TopicSubscriberAdapter adapter = new TopicSubscriberAdapter(subscriber); - adapter.setListenerId(topic.addMessageListener(adapter)); + String registrationId = topic.addMessageListener(adapter); adapters.add(adapter); + registrationMap.put(adapter, registrationId); } @Override @@ -58,7 +63,9 @@ public class TopicImpl implements ITopic { for(TopicSubscriberAdapter adapter : adapters) { if (adapter.subscriber == subscriber) { found = adapter; - topic.removeMessageListener(adapter.getListenerId()); + String registrationId = registrationMap.get(adapter); + if (topic.removeMessageListener(registrationId)) + registrationMap.remove(adapter); break; } } @@ -73,20 +80,11 @@ public class TopicImpl implements ITopic { class TopicSubscriberAdapter implements MessageListener { protected ITopicSubscriber subscriber; - private String listenerId; protected TopicSubscriberAdapter(ITopicSubscriber subscriber) { this.subscriber = subscriber; } - public void setListenerId(String listenerId) { - this.listenerId = listenerId; - } - - public String getListenerId() { - return listenerId; - } - @Override public void onMessage(Message message) { subscriber.onMessage(message.getMessageObject());