Restructure use of static field m_bundle to improve the odds that multiple instances...
authorChris Jaekl <cejaekl@yahoo.com>
Fri, 1 Jan 2016 12:51:46 +0000 (21:51 +0900)
committerChris Jaekl <cejaekl@yahoo.com>
Fri, 1 Jan 2016 12:51:46 +0000 (21:51 +0900)
prod/net/jaekl/cfb/CFB.java
test/net/jaekl/cfb/CFBMock.java

index c97a1c8f7b4e74196f528b80d11bb16dfdd22884..35a08c3b178491f92e1d2c456b53a5900e64db6c 100644 (file)
@@ -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) {
index b76876f0e74a896445b5032c5ab0e5e94c73f442..87ce40df38e3241d422842d0070804cad4813666 100644 (file)
@@ -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();
+       }       
 }