Revision: 3302
Author: ferguson.sebastian
Date: Wed Feb 17 13:45:03 2010
Log: New client side sessions are properly added to the context's list of
sessions, and receive a life cycle listener so that the application shuts
down properly when the session's window is closed.
http://code.google.com/p/power-architect/source/detail?r=3302
Modified:
/trunk/src/ca/sqlpower/architect/enterprise/ArchitectClientSideSession.java
/trunk/src/ca/sqlpower/architect/swingui/ArchitectSwingSessionContextImpl.java
=======================================
---
/trunk/src/ca/sqlpower/architect/enterprise/ArchitectClientSideSession.java
Wed Feb 17 08:55:16 2010
+++
/trunk/src/ca/sqlpower/architect/enterprise/ArchitectClientSideSession.java
Wed Feb 17 13:45:03 2010
@@ -456,6 +456,8 @@
// Contained classes
--------------------------------------------------------------------
+ boolean persistingToServer = false;
+
/**
* Sends outgoing JSON
*/
@@ -474,9 +476,8 @@
public void flush() throws SPPersistenceException {
try {
-
- currentRevision++;
- System.out.println(message.toString());
+ persistingToServer = true;
+ logger.debug("starting send ... (v" + currentRevision +
")");
URI serverURI = getServerURI();
HttpPost postRequest = new HttpPost(serverURI);
@@ -484,18 +485,21 @@
postRequest.setHeader("Content-Type",
"application/json");
HttpUriRequest request = postRequest;
- getHttpClient().execute(request, new
JSONResponseHandler());
+ String response = getHttpClient().execute(request, new
JSONResponseHandler());
+ currentRevision = (new
JSONObject(response)).getInt("currentRevision");
+
} catch (ClientProtocolException e) {
- currentRevision--;
throw new SPPersistenceException(null, e);
} catch (IOException e) {
- currentRevision--;
throw new SPPersistenceException(null, e);
} catch (URISyntaxException e) {
- currentRevision--;
throw new SPPersistenceException(null, e);
- } finally {
+ } catch (Exception e) {
+ throw new RuntimeException(null, e);
+ } finally {
clear();
+ persistingToServer = false;
+ logger.debug("... ending send");
}
}
@@ -554,42 +558,34 @@
@Override
public void run() {
logger.info("Updater thread starting");
-
- // the path to contact on the server for update events
final String contextRelativePath = "/project/" +
projectLocation.getUUID();
try {
while (!this.isInterrupted() && !cancelled) {
try {
-
URI uri = new URI("http", null,
projectLocation.getServiceInfo().getServerAddress(),
projectLocation.getServiceInfo().getPort(),
- projectLocation.getServiceInfo().getPath() +
contextRelativePath, "oldRevisionNo=" + currentRevision, null);
+ projectLocation.getServiceInfo().getPath() +
contextRelativePath, "oldRevisionNo=" + currentRevision, null);
HttpUriRequest request = new
HttpGet(uri);
-
- String message = inboundHttpClient.execute(request, new
JSONResponseHandler());
- JSONObject json = new
JSONObject(message);
- final String jsonArray =
json.getString("data");
-
- currentRevision =
json.getInt("currentRevision");
-
- runInForeground(new Runnable() {
- public void run() {
- try {
-
-
jsonDecoder.decode(jsonArray);
-
- } catch
(SPPersistenceException e) {
-
logger.error("Update from server failed!", e);
-
createUserPrompter(
- "Architect failed to apply an update that was just received
from the Enterprise Server.\n"
- +
"The error was:"
- +
"\n" + e.getMessage(),
-
UserPromptType.MESSAGE, UserPromptOptions.OK,
-
UserPromptResponse.OK, UserPromptResponse.OK, "OK");
- // TODO
discard session and reload
- }
- }
- });
+
+ String message =
inboundHttpClient.execute(request, new JSONResponseHandler());
+ final JSONObject json = new JSONObject(message);
+ final String jsonArray = json.getString("data");
+ currentRevision = json.getInt("currentRevision");
+ if (!persistingToServer) {
+ runInForeground(new Runnable() {
+ public void run() {
+ try {
+ logger.debug("Start update ... (v" +
json.getInt("currentRevision") + ")");
+ jsonDecoder.decode(jsonArray);
+ logger.debug("... end update");
+ } catch (SPPersistenceException e) {
+ logger.error("Update from server
failed!", e);
+ // TODO discard session and reload
+ } catch (JSONException je) {
+ }
+ }
+ });
+ }
} catch (Exception ex) {
logger.error("Failed to contact server. Will retry in " + retryDelay
+ " ms.", ex);
Thread.sleep(retryDelay);
=======================================
---
/trunk/src/ca/sqlpower/architect/swingui/ArchitectSwingSessionContextImpl.java
Wed Feb 17 08:55:16 2010
+++
/trunk/src/ca/sqlpower/architect/swingui/ArchitectSwingSessionContextImpl.java
Wed Feb 17 13:45:03 2010
@@ -268,24 +268,25 @@
}
public ArchitectSwingSession createNewServerSession(SPServerInfo
serverInfo, boolean initGUI) throws SQLObjectException,
ClientProtocolException, URISyntaxException, IOException, JSONException {
-
ProjectLocation projectLocation =
ArchitectClientSideSession.createNewServerSession(serverInfo);
ArchitectSession clientSession = new
ArchitectClientSideSession(this, projectLocation.getName(),
projectLocation);
-
ArchitectSwingSession swingSession = new
ArchitectSwingSessionImpl(this, clientSession);
-
+ getSessions().add(swingSession);
+ swingSession.addSessionLifecycleListener(sessionLifecycleListener);
+
if (initGUI) {
swingSession.initGUI();
}
- getSessions().add(swingSession);
+
return swingSession;
}
public ArchitectSwingSession createServerSession(ProjectLocation
projectLocation, boolean initGUI) throws SQLObjectException {
-
ArchitectClientSideSession clientSession = new
ArchitectClientSideSession(this, projectLocation.getName(),
projectLocation);
ArchitectSwingSession swingSession = new
ArchitectSwingSessionImpl(this, clientSession);
clientSession.startUpdaterThread();
+ getSessions().add(swingSession);
+ swingSession.addSessionLifecycleListener(sessionLifecycleListener);
if (initGUI) {
swingSession.initGUI();