From: Chris Jaekl Date: Fri, 1 Jan 2016 12:51:46 +0000 (+0900) Subject: Restructure use of static field m_bundle to improve the odds that multiple instances... X-Git-Url: https://jaekl.net/gitweb/?a=commitdiff_plain;h=a4a577abc3f9b2b1147caafd1cb39fa8c2622cd4;p=cfb.git Restructure use of static field m_bundle to improve the odds that multiple instances will function as expected. --- diff --git a/prod/net/jaekl/cfb/CFB.java b/prod/net/jaekl/cfb/CFB.java index c97a1c8..35a08c3 100644 --- a/prod/net/jaekl/cfb/CFB.java +++ b/prod/net/jaekl/cfb/CFB.java @@ -60,7 +60,6 @@ public class CFB { m_driver = new PostgresqlDriver(); m_schema = new CfbSchema(m_driver); m_locale = locale; - m_bundle = null; m_config = new Config(); m_configFile = new File("config.properties"); @@ -72,12 +71,12 @@ public class CFB { m_output = null; } - CfbBundle getBundle() { + static CfbBundle getBundle(Locale locale) { CfbBundle bundle = m_bundle; if (null == bundle) { synchronized(CFB.class) { if (null == m_bundle) { - m_bundle = bundle = CfbBundle.getInst(m_locale); + m_bundle = bundle = CfbBundle.getInst(locale); } } } @@ -153,7 +152,7 @@ public class CFB { } String trans(String key) { - return getBundle().get(key); + return getBundle(m_locale).get(key); } String getenv(String varName) { @@ -256,12 +255,12 @@ public class CFB { Analysis prior = store.getPrior(analysis); Delta delta = new Delta(prior, analysis); - HtmlReport report = new HtmlReport(getBundle(), messageMap.getColl(), delta); + HtmlReport report = new HtmlReport(getBundle(m_locale), messageMap.getColl(), delta); if (null != m_output) { report.write(m_output); } - Notifier notifier = new Notifier(getBundle(), m_config); + Notifier notifier = new Notifier(getBundle(m_locale), m_config); notifier.sendEmailIfNeeded(pw, report); } catch (StoreException exc) { diff --git a/test/net/jaekl/cfb/CFBMock.java b/test/net/jaekl/cfb/CFBMock.java index b76876f..87ce40d 100644 --- a/test/net/jaekl/cfb/CFBMock.java +++ b/test/net/jaekl/cfb/CFBMock.java @@ -6,19 +6,11 @@ import net.jaekl.cfb.db.CfbSchema; import net.jaekl.cfb.db.driver.DbDriver; public class CFBMock extends CFB { - private CfbBundleMock mock_bundle; - CFBMock(Locale locale, DbDriver driver) { super(locale); m_driver = driver; m_schema = new CfbSchema(m_driver); - mock_bundle = new CfbBundleMock(); - } - - @Override - CfbBundle getBundle() - { - return mock_bundle; - } + m_bundle = new CfbBundleMock(); + } }