Revision: 3314
Author: ferguson.sebastian
Date: Fri Feb 19 11:29:28 2010
Log: Some threading issues solved in the updater thread and in the Sender.
http://code.google.com/p/power-architect/source/detail?r=3314
Modified:
/trunk/src/ca/sqlpower/architect/enterprise/ArchitectClientSideSession.java
=======================================
---
/trunk/src/ca/sqlpower/architect/enterprise/ArchitectClientSideSession.java
Thu Feb 18 14:32:41 2010
+++
/trunk/src/ca/sqlpower/architect/enterprise/ArchitectClientSideSession.java
Fri Feb 19 11:29:28 2010
@@ -510,11 +510,13 @@
flushAgain = true;
return;
}
- persistingToServer = true;
- flushAgain = false;
+
+ persistingToServer = true;
+ flushAgain = false;
URI serverURI = getServerURI();
HttpPost postRequest = new HttpPost(serverURI);
+
postRequest.setEntity(new
StringEntity(message.toString()));
postRequest.setHeader("Content-Type", "application/json");
HttpUriRequest request = postRequest;
@@ -537,11 +539,11 @@
throw new RuntimeException(e);
} finally {
persistingToServer = false;
- try {
- if (flushAgain) flush();
- } catch (SPPersistenceException e) {
- throw new RuntimeException(e);
- }
+ try {
+ if (flushAgain) flush();
+ } catch (SPPersistenceException e) {
+ throw new RuntimeException(e);
+ }
}
}
});
@@ -588,6 +590,8 @@
* Used by the Updater to handle inbound HTTP updates
*/
private final HttpClient inboundHttpClient;
+
+ final String contextRelativePath = "/project/" +
projectLocation.getUUID();
private volatile boolean cancelled;
@@ -609,14 +613,19 @@
cancelled = true;
}
+ boolean updating = false;
+
@Override
public void run() {
logger.info("Updater thread starting");
- final String contextRelativePath = "/project/" +
projectLocation.getUUID();
-
try {
while (!this.isInterrupted() && !cancelled) {
try {
+ while (updating) {
+ synchronized (this) {
+ wait();
+ }
+ }
URI uri = getServerURI(projectLocation.getServiceInfo(),
contextRelativePath,
"oldRevisionNo=" +
currentRevision);
@@ -625,28 +634,36 @@
JSONMessage message =
inboundHttpClient.execute(request, new JSONResponseHandler());
final JSONObject json = new
JSONObject(message.getBody());
final String jsonArray = json.getString("data");
-
+
+ updating = true;
runInForeground(new Runnable() {
public void run() {
try {
if (!persistingToServer) {
int newRevision =
json.getInt("currentRevision");
if (currentRevision < newRevision)
{
+ logger.debug("CurrentRevision
= " + currentRevision + " JSON:");
+ logger.debug(jsonArray);
currentRevision = newRevision;
- logger.debug("Updater:
Starting run ...");
jsonDecoder.decode(jsonArray);
- logger.debug("... Updater:
completing run");
}
}
} catch (SPPersistenceException e) {
logger.error("Update from server
failed!", e);
+ //logger.warn(jsonArray);
+ throw new RuntimeException("Please hit
the refresh button that does not exist", e);
// TODO discard session and reload
} catch (JSONException e) {
logger.error("Update from server
failed!", e);
+ } finally {
+ updating = false;
+ synchronized (updater) {
+ updater.notify();
+ }
}
}
});
-
+
} catch (Exception ex) {
logger.error("Failed to contact server. Will retry in " + retryDelay
+ " ms.", ex);
Thread.sleep(retryDelay);