Mercurial > hg > release > thermostat-0.5
changeset 946:b5693fd9f6b8
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
author | Elliott Baron <ebaron@redhat.com> |
---|---|
date | Thu, 31 Jan 2013 14:37:55 -0500 |
parents | fb898142c539 |
children | 228ad727f418 |
files | storage/core/src/main/java/com/redhat/thermostat/storage/core/Storage.java web/client/src/main/java/com/redhat/thermostat/web/client/internal/WebStorage.java |
diffstat | 2 files changed, 9 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- 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);
--- 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