# HG changeset patch # User Elliott Baron # Date 1359661075 18000 # Node ID b5693fd9f6b89032429b8ea13009d2a03b7e6abf # Parent fb898142c53984fc9e8250f80c46c462ee704c08 Keep WebConnection instance I have come across this issue while working on the DAOFactory removal patch. The problem was the Reconnect dialog wasn't appearing when the GUI couldn't connect to storage. The cause is that WebStorage.getConnection returns a new instance of WebConnection each time it is called. Thus if one method calls storage.getConnection().addListener() and then another method calls storage.getConnection().connect(), the listener is no longer attached. This simple commit changes WebStorage to instantiate a WebConnection in its constructor and always return this instance in getConnection. Reviewed-by: omajid Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2013-January/005318.html diff -r fb898142c539 -r b5693fd9f6b8 storage/core/src/main/java/com/redhat/thermostat/storage/core/Storage.java --- a/storage/core/src/main/java/com/redhat/thermostat/storage/core/Storage.java Thu Jan 31 10:56:26 2013 +0100 +++ b/storage/core/src/main/java/com/redhat/thermostat/storage/core/Storage.java Thu Jan 31 14:37:55 2013 -0500 @@ -56,6 +56,12 @@ void registerCategory(Category category); + /** + * Returns the Connection object that may be used to manage connections + * to this Storage. Subsequent calls to this method should return + * the same Connection. + * @return the Connection for this Storage + */ Connection getConnection(); Add createAdd(Category category); diff -r fb898142c539 -r b5693fd9f6b8 web/client/src/main/java/com/redhat/thermostat/web/client/internal/WebStorage.java --- a/web/client/src/main/java/com/redhat/thermostat/web/client/internal/WebStorage.java Thu Jan 31 10:56:26 2013 +0100 +++ b/web/client/src/main/java/com/redhat/thermostat/web/client/internal/WebStorage.java Thu Jan 31 14:37:55 2013 -0500 @@ -329,6 +329,7 @@ private String username; private String password; private SecureRandom random; + private WebConnection conn; public WebStorage(StartupConfiguration config) throws StorageException { categoryIds = new HashMap<>(); @@ -338,6 +339,7 @@ DefaultHttpClient client = new DefaultHttpClient(connManager); httpClient = client; random = new SecureRandom(); + conn = new WebConnection(); // setup SSL if necessary if (config.getDBConnectionString().startsWith(HTTPS_PREFIX)) { @@ -482,7 +484,7 @@ @Override public Connection getConnection() { - return new WebConnection(); + return conn; } @Override