IDEMPIERE-1218 Improve discovery of hazelcast configuration file.

This commit is contained in:
Heng Sin Low 2013-07-30 13:19:20 +08:00
parent fa5ba42381
commit 1e27469b0f
1 changed files with 36 additions and 12 deletions

View File

@ -15,7 +15,6 @@ package org.idempiere.hazelcast.service;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.text.DateFormat; import java.text.DateFormat;
import java.util.Date; import java.util.Date;
@ -75,20 +74,45 @@ public class Activator implements BundleActivator {
future = executor.submit(new Runnable() { future = executor.submit(new Runnable() {
@Override @Override
public void run() { 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) { if (dataArea != null && dataArea.trim().length() > 0) {
try { try {
URL url = new URL(dataArea); file = new File(dataArea, "hazelcast.xml");
File file = new File(url.getPath(), "hazelcast.xml"); if (!file.exists())
if (file.exists()) { file = null;
try { } catch (Exception e) {}
Config config = new FileSystemXmlConfig(file); }
hazelcastInstance = Hazelcast.newHazelcastInstance(config); //try working directory
return; if (file == null) {
} catch (FileNotFoundException e) {} dataArea = System.getProperty("user.dir");
} if (dataArea != null && dataArea.trim().length() > 0) {
} catch (MalformedURLException e1) { 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); hazelcastInstance = Hazelcast.newHazelcastInstance(null);
} }