From 1e27469b0f56feac1c23dc16bac685d18fdbbe66 Mon Sep 17 00:00:00 2001 From: Heng Sin Low Date: Tue, 30 Jul 2013 13:19:20 +0800 Subject: [PATCH] IDEMPIERE-1218 Improve discovery of hazelcast configuration file. --- .../hazelcast/service/Activator.java | 48 ++++++++++++++----- 1 file changed, 36 insertions(+), 12 deletions(-) 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 ad748f021e..d3e0f222e3 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 @@ -15,7 +15,6 @@ package org.idempiere.hazelcast.service; import java.io.File; import java.io.FileNotFoundException; -import java.net.MalformedURLException; import java.net.URL; import java.text.DateFormat; import java.util.Date; @@ -75,20 +74,45 @@ public class Activator implements BundleActivator { future = executor.submit(new Runnable() { @Override public void run() { - String dataArea = System.getProperty("osgi.install.area"); + File file = null; + //try idempiere home + String dataArea = System.getProperty("IDEMPIERE_HOME"); if (dataArea != null && dataArea.trim().length() > 0) { try { - URL url = new URL(dataArea); - File file = new File(url.getPath(), "hazelcast.xml"); - if (file.exists()) { - try { - Config config = new FileSystemXmlConfig(file); - hazelcastInstance = Hazelcast.newHazelcastInstance(config); - return; - } catch (FileNotFoundException e) {} - } - } catch (MalformedURLException e1) { + 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"); + 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) {} + } + } + if (file != null && file.exists()) { + try { + Config config = new FileSystemXmlConfig(file); + hazelcastInstance = Hazelcast.newHazelcastInstance(config); + return; + } catch (FileNotFoundException e) {} } hazelcastInstance = Hazelcast.newHazelcastInstance(null); }