From a7d41c111c1f5e33647286a90a3e280411d715d8 Mon Sep 17 00:00:00 2001 From: Heng Sin Low Date: Tue, 27 Nov 2012 22:29:02 +0800 Subject: [PATCH] IDEMPIERE-491 Caching data can generate problem. Improve startup of hazelcast service. Added fragment to allow modification of hazelcast service configuration. --- .../server.product.launch | 2 +- .../swingclient.product.launch | 4 +- .../feature.xml | 7 + .../.classpath | 7 + .../.project | 28 +++ .../.settings/org.eclipse.jdt.core.prefs | 7 + .../.settings/org.eclipse.pde.core.prefs | 3 + .../META-INF/MANIFEST.MF | 7 + .../build.properties | 4 + .../hazelcast.xml | 196 ++++++++++++++++++ .../hazelcast/service/Activator.java | 30 ++- .../hazelcast/service/CacheServiceImpl.java | 12 +- .../hazelcast/service/ClusterServiceImpl.java | 12 +- .../hazelcast/service/MessageServiceImpl.java | 2 +- 14 files changed, 298 insertions(+), 23 deletions(-) create mode 100644 org.idempiere.hazelcast.service.config/.classpath create mode 100644 org.idempiere.hazelcast.service.config/.project create mode 100644 org.idempiere.hazelcast.service.config/.settings/org.eclipse.jdt.core.prefs create mode 100644 org.idempiere.hazelcast.service.config/.settings/org.eclipse.pde.core.prefs create mode 100644 org.idempiere.hazelcast.service.config/META-INF/MANIFEST.MF create mode 100644 org.idempiere.hazelcast.service.config/build.properties create mode 100644 org.idempiere.hazelcast.service.config/hazelcast.xml diff --git a/org.adempiere.server-feature/server.product.launch b/org.adempiere.server-feature/server.product.launch index cc3f4d2d92..1a45667f84 100644 --- a/org.adempiere.server-feature/server.product.launch +++ b/org.adempiere.server-feature/server.product.launch @@ -22,7 +22,7 @@ - + diff --git a/org.adempiere.ui.swing-feature/swingclient.product.launch b/org.adempiere.ui.swing-feature/swingclient.product.launch index 8d6b499243..f496cb2c31 100644 --- a/org.adempiere.ui.swing-feature/swingclient.product.launch +++ b/org.adempiere.ui.swing-feature/swingclient.product.launch @@ -21,8 +21,8 @@ - - + + diff --git a/org.idempiere.hazelcast.service-feature/feature.xml b/org.idempiere.hazelcast.service-feature/feature.xml index 522de724ce..ef5e144f2e 100644 --- a/org.idempiere.hazelcast.service-feature/feature.xml +++ b/org.idempiere.hazelcast.service-feature/feature.xml @@ -38,4 +38,11 @@ fragment="true" unpack="false"/> + + diff --git a/org.idempiere.hazelcast.service.config/.classpath b/org.idempiere.hazelcast.service.config/.classpath new file mode 100644 index 0000000000..ad32c83a78 --- /dev/null +++ b/org.idempiere.hazelcast.service.config/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/org.idempiere.hazelcast.service.config/.project b/org.idempiere.hazelcast.service.config/.project new file mode 100644 index 0000000000..7d2440bda3 --- /dev/null +++ b/org.idempiere.hazelcast.service.config/.project @@ -0,0 +1,28 @@ + + + org.idempiere.hazelcast.service.config + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/org.idempiere.hazelcast.service.config/.settings/org.eclipse.jdt.core.prefs b/org.idempiere.hazelcast.service.config/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000000..c537b63063 --- /dev/null +++ b/org.idempiere.hazelcast.service.config/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/org.idempiere.hazelcast.service.config/.settings/org.eclipse.pde.core.prefs b/org.idempiere.hazelcast.service.config/.settings/org.eclipse.pde.core.prefs new file mode 100644 index 0000000000..f29e940a00 --- /dev/null +++ b/org.idempiere.hazelcast.service.config/.settings/org.eclipse.pde.core.prefs @@ -0,0 +1,3 @@ +eclipse.preferences.version=1 +pluginProject.extensions=false +resolve.requirebundle=false diff --git a/org.idempiere.hazelcast.service.config/META-INF/MANIFEST.MF b/org.idempiere.hazelcast.service.config/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..f4155cda17 --- /dev/null +++ b/org.idempiere.hazelcast.service.config/META-INF/MANIFEST.MF @@ -0,0 +1,7 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Hazelcast Service Configuration +Bundle-SymbolicName: org.idempiere.hazelcast.service.config +Bundle-Version: 1.0.0.qualifier +Fragment-Host: org.idempiere.hazelcast.service;bundle-version="1.0.0" +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 diff --git a/org.idempiere.hazelcast.service.config/build.properties b/org.idempiere.hazelcast.service.config/build.properties new file mode 100644 index 0000000000..34d2e4d2da --- /dev/null +++ b/org.idempiere.hazelcast.service.config/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/org.idempiere.hazelcast.service.config/hazelcast.xml b/org.idempiere.hazelcast.service.config/hazelcast.xml new file mode 100644 index 0000000000..4384476e9b --- /dev/null +++ b/org.idempiere.hazelcast.service.config/hazelcast.xml @@ -0,0 +1,196 @@ + + + + + + dev + dev-pass + + http://localhost:8080/mancenter + + 5701 + + + 0 + + + + 224.2.2.3 + 54327 + + + 127.0.0.1 + + + my-access-key + my-secret-key + + us-west-1 + + ec2.amazonaws.com + + hazelcast-sg + type + hz-nodes + + + + 10.10.1.* + + + + + + PBEWithMD5AndDES + + thesalt + + thepass + + 19 + + + + RSA/NONE/PKCS1PADDING + + thekeypass + + local + + JKS + + thestorepass + + keystore + + + + + 16 + 64 + 60 + + + + 0 + + default + + + + 1 + + 0 + + 0 + + 0 + + NONE + + 0 + + 25 + + hz.ADD_NEW_ENTRY + + + + + + \ No newline at end of file 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 780fd0f5ea..9a57f5a743 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 @@ -13,8 +13,10 @@ *****************************************************************************/ package org.idempiere.hazelcast.service; +import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import java.util.concurrent.ScheduledThreadPoolExecutor; +import java.util.concurrent.atomic.AtomicReference; import org.compiere.Adempiere; import org.compiere.model.ServerStateChangeEvent; @@ -22,7 +24,6 @@ import org.compiere.model.ServerStateChangeListener; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; -import com.hazelcast.config.*; import com.hazelcast.core.*; /** @@ -38,8 +39,8 @@ public class Activator implements BundleActivator { return context; } - protected static HazelcastInstance hazelcastInstance; - private Future future; + private static HazelcastInstance hazelcastInstance; + private static AtomicReference> futureRef = new AtomicReference>(); /* * (non-Javadoc) @@ -52,7 +53,6 @@ public class Activator implements BundleActivator { createHazelCastInstance(); else { Adempiere.addServerStateChangeListener(new ServerStateChangeListener() { - @Override public void stateChange(ServerStateChangeEvent event) { if (event.getEventType() == ServerStateChangeEvent.SERVER_START) @@ -64,26 +64,42 @@ public class Activator implements BundleActivator { private void createHazelCastInstance() { ScheduledThreadPoolExecutor executor = Adempiere.getThreadPoolExecutor(); - future = executor.submit(new Runnable() { + + Future future = executor.submit(new Runnable() { @Override public void run() { - Config config = new Config(); - hazelcastInstance = Hazelcast.newHazelcastInstance(config); + hazelcastInstance = Hazelcast.newHazelcastInstance(null); } }); + futureRef.set(future); } + public static HazelcastInstance getHazelcastInstance() { + Future future = futureRef.get(); + if (future != null && !future.isDone()) { + try { + future.get(); + } catch (InterruptedException e) { + } catch (ExecutionException e) { + } + } + + return hazelcastInstance; + } + /* * (non-Javadoc) * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext) */ public void stop(BundleContext bundleContext) throws Exception { Activator.context = null; + Future future = futureRef.get(); if (future != null && !future.isDone()) { future.cancel(true); } else if (hazelcastInstance != null) { hazelcastInstance.getLifecycleService().shutdown(); hazelcastInstance = null; } + futureRef.set(null); } } diff --git a/org.idempiere.hazelcast.service/src/org/idempiere/hazelcast/service/CacheServiceImpl.java b/org.idempiere.hazelcast.service/src/org/idempiere/hazelcast/service/CacheServiceImpl.java index f8cc75a3bf..0b82f90517 100644 --- a/org.idempiere.hazelcast.service/src/org/idempiere/hazelcast/service/CacheServiceImpl.java +++ b/org.idempiere.hazelcast.service/src/org/idempiere/hazelcast/service/CacheServiceImpl.java @@ -36,24 +36,24 @@ public class CacheServiceImpl implements ICacheService { */ @Override public Map getMap(String name) { - if (Activator.hazelcastInstance != null) - return Activator.hazelcastInstance.getMap(name); + if (Activator.getHazelcastInstance() != null) + return Activator.getHazelcastInstance().getMap(name); else return null; } @Override public List getList(String name) { - if (Activator.hazelcastInstance != null) - return Activator.hazelcastInstance.getList(name); + if (Activator.getHazelcastInstance() != null) + return Activator.getHazelcastInstance().getList(name); else return null; } @Override public Set getSet(String name) { - if (Activator.hazelcastInstance != null) - return Activator.hazelcastInstance.getSet(name); + if (Activator.getHazelcastInstance() != null) + return Activator.getHazelcastInstance().getSet(name); else return null; } 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 a99947e261..1a4ecd69d9 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 @@ -37,7 +37,7 @@ public class ClusterServiceImpl implements IClusterService { */ @Override public Collection getMembers() { - Set members = Activator.hazelcastInstance.getCluster().getMembers(); + Set members = Activator.getHazelcastInstance().getCluster().getMembers(); Set clusterMembers = new HashSet(); for(Member member : members) { clusterMembers.add(new ClusterMember(member.getUuid(), member.getInetSocketAddress().getAddress())); @@ -50,7 +50,7 @@ public class ClusterServiceImpl implements IClusterService { */ @Override public IClusterMember getLocalMember() { - Member member = Activator.hazelcastInstance.getCluster().getLocalMember(); + Member member = Activator.getHazelcastInstance().getCluster().getLocalMember(); return new ClusterMember(member.getUuid(), member.getInetSocketAddress().getAddress()); } @@ -59,11 +59,11 @@ public class ClusterServiceImpl implements IClusterService { */ @Override public Future execute(Callable task, IClusterMember clusterMember) { - Set members = Activator.hazelcastInstance.getCluster().getMembers(); + Set members = Activator.getHazelcastInstance().getCluster().getMembers(); for(Member member : members) { if (member.getUuid().equals(clusterMember.getId())) { DistributedTask distributedTask = new DistributedTask(task, member); - Activator.hazelcastInstance.getExecutorService().execute(distributedTask); + Activator.getHazelcastInstance().getExecutorService().execute(distributedTask); return distributedTask; } } @@ -81,7 +81,7 @@ public class ClusterServiceImpl implements IClusterService { for(IClusterMember clusterMember : clusterMembers) { selectedIds.add(clusterMember.getId()); } - Set members = Activator.hazelcastInstance.getCluster().getMembers(); + Set members = Activator.getHazelcastInstance().getCluster().getMembers(); Set selectedMembers = new HashSet(); for(Member member : members) { if (selectedIds.contains(member.getUuid())) { @@ -90,7 +90,7 @@ public class ClusterServiceImpl implements IClusterService { } if (selectedMembers.size() > 0) { MultiTask multiTask = new MultiTask(task, selectedMembers); - Activator.hazelcastInstance.getExecutorService().execute(multiTask); + Activator.getHazelcastInstance().getExecutorService().execute(multiTask); return multiTask; } return null; diff --git a/org.idempiere.hazelcast.service/src/org/idempiere/hazelcast/service/MessageServiceImpl.java b/org.idempiere.hazelcast.service/src/org/idempiere/hazelcast/service/MessageServiceImpl.java index 5c6e1fa70f..a42fdffbb0 100644 --- a/org.idempiere.hazelcast.service/src/org/idempiere/hazelcast/service/MessageServiceImpl.java +++ b/org.idempiere.hazelcast.service/src/org/idempiere/hazelcast/service/MessageServiceImpl.java @@ -30,7 +30,7 @@ public class MessageServiceImpl implements IMessageService { @Override public ITopic getTopic(String name) { - com.hazelcast.core.ITopic topic = Activator.hazelcastInstance.getTopic(name); + com.hazelcast.core.ITopic topic = Activator.getHazelcastInstance().getTopic(name); return new TopicImpl(topic); } }