Pass only JSONObject around instead of multiple versions Change-Id: Ibf747df366e384df8e3cc6f5153100168514f63atags/7.6.0.alpha5
@@ -16,7 +16,6 @@ | |||
package com.vaadin.client; | |||
import java.util.Date; | |||
import java.util.HashMap; | |||
import java.util.Map; | |||
import java.util.logging.Logger; | |||
@@ -440,7 +439,7 @@ public class ApplicationConnection implements HasHandlers { | |||
// Hack to avoid logging an error in endRequest() | |||
getServerCommunicationHandler().startRequest(); | |||
getServerMessageHandler().handleJSONText(jsonText, -1); | |||
getServerMessageHandler().handleMessage(jsonText); | |||
} | |||
// Tooltip can't be created earlier because the | |||
@@ -643,12 +642,12 @@ public class ApplicationConnection implements HasHandlers { | |||
static final int MAX_CSS_WAITS = 100; | |||
public void handleWhenCSSLoaded(final String jsonText, final ValueMap json) { | |||
public void executeWhenCSSLoaded(final Command c) { | |||
if (!isCSSLoaded() && cssWaits < MAX_CSS_WAITS) { | |||
(new Timer() { | |||
@Override | |||
public void run() { | |||
handleWhenCSSLoaded(jsonText, json); | |||
executeWhenCSSLoaded(c); | |||
} | |||
}).schedule(50); | |||
@@ -665,8 +664,7 @@ public class ApplicationConnection implements HasHandlers { | |||
getLogger().severe("CSS files may have not loaded properly."); | |||
} | |||
getServerMessageHandler().handleUIDLMessage(new Date(), jsonText, | |||
json); | |||
c.execute(); | |||
} | |||
} | |||
@@ -335,7 +335,7 @@ public class AtmospherePushConnection implements PushConnection { | |||
getLogger().info("Received push message: " + message); | |||
// "for(;;);[{json}]" -> "{json}" | |||
message = message.substring(9, message.length() - 1); | |||
connection.getServerMessageHandler().handleJSONText(message, 200); | |||
connection.getServerMessageHandler().handleMessage(message); | |||
} | |||
} | |||
@@ -111,7 +111,7 @@ public class ServerCommunicationHandler { | |||
return Logger.getLogger(ServerCommunicationHandler.class.getName()); | |||
} | |||
public void doSendPendingVariableChanges() { | |||
public void sendInvocationsToServer() { | |||
if (!connection.isApplicationRunning()) { | |||
getLogger() | |||
.warning( | |||
@@ -123,7 +123,7 @@ public class ServerCommunicationHandler { | |||
// There is an active request or push is enabled but not active | |||
// -> send when current request completes or push becomes active | |||
} else { | |||
sendInvocationsToServer(); | |||
doSendInvocationsToServer(); | |||
} | |||
} | |||
@@ -132,7 +132,7 @@ public class ServerCommunicationHandler { | |||
* changes) to the server. | |||
* | |||
*/ | |||
public void sendInvocationsToServer() { | |||
private void doSendInvocationsToServer() { | |||
ServerRpcQueue serverRpcQueue = getServerRpcQueue(); | |||
if (serverRpcQueue.isEmpty()) { | |||
return; | |||
@@ -287,7 +287,7 @@ public class ServerCommunicationHandler { | |||
responseText.length() | |||
- JSON_COMMUNICATION_SUFFIX.length()); | |||
getServerMessageHandler().handleJSONText(jsonText, statusCode); | |||
getServerMessageHandler().handleMessage(jsonText); | |||
} | |||
}; | |||
if (push != null) { |
@@ -189,24 +189,12 @@ public class ServerMessageHandler { | |||
* Data structure holding information about pending UIDL messages. | |||
*/ | |||
private static class PendingUIDLMessage { | |||
private Date start; | |||
private String jsonText; | |||
private ValueMap json; | |||
public PendingUIDLMessage(Date start, String jsonText, ValueMap json) { | |||
this.start = start; | |||
this.jsonText = jsonText; | |||
public PendingUIDLMessage(ValueMap json) { | |||
this.json = json; | |||
} | |||
public Date getStart() { | |||
return start; | |||
} | |||
public String getJsonText() { | |||
return jsonText; | |||
} | |||
public ValueMap getJson() { | |||
return json; | |||
} | |||
@@ -227,13 +215,13 @@ public class ServerMessageHandler { | |||
} | |||
/** | |||
* Handles received UIDL JSON text, parsing it, and passing it on to the | |||
* Handles a received UIDL JSON text, parsing it, and passing it on to the | |||
* appropriate handlers, while logging timing information. | |||
* | |||
* @param jsonText | |||
* @param statusCode | |||
* The JSON to handle | |||
*/ | |||
public void handleJSONText(String jsonText, int statusCode) { | |||
public void handleMessage(String jsonText) { | |||
final Date start = new Date(); | |||
final ValueMap json; | |||
try { | |||
@@ -242,7 +230,7 @@ public class ServerMessageHandler { | |||
// FIXME | |||
getServerCommunicationHandler().endRequest(); | |||
connection.showCommunicationError(e.getMessage() | |||
+ " - Original JSON-text:" + jsonText, statusCode); | |||
+ " - Original JSON-text:" + jsonText, 200); | |||
return; | |||
} | |||
@@ -250,11 +238,16 @@ public class ServerMessageHandler { | |||
"JSON parsing took " + (new Date().getTime() - start.getTime()) | |||
+ "ms"); | |||
if (connection.getState() == State.RUNNING) { | |||
handleUIDLMessage(start, jsonText, json); | |||
handleJSON(json); | |||
} else if (connection.getState() == State.INITIALIZING) { | |||
// Application is starting up for the first time | |||
connection.setApplicationRunning(true); | |||
connection.handleWhenCSSLoaded(jsonText, json); | |||
connection.executeWhenCSSLoaded(new Command() { | |||
@Override | |||
public void execute() { | |||
handleJSON(json); | |||
} | |||
}); | |||
} else { | |||
getLogger() | |||
.warning( | |||
@@ -265,28 +258,23 @@ public class ServerMessageHandler { | |||
private static native ValueMap parseJSONResponse(String jsonText) | |||
/*-{ | |||
try { | |||
return JSON.parse(jsonText); | |||
} catch (ignored) { | |||
return eval('(' + jsonText + ')'); | |||
} | |||
return JSON.parse(jsonText); | |||
}-*/; | |||
public void handleUIDLMessage(final Date start, final String jsonText, | |||
final ValueMap json) { | |||
protected void handleJSON(final ValueMap json) { | |||
if (!responseHandlingLocks.isEmpty()) { | |||
// Some component is doing something that can't be interrupted | |||
// (e.g. animation that should be smooth). Enqueue the UIDL | |||
// message for later processing. | |||
getLogger().info("Postponing UIDL handling due to lock..."); | |||
pendingUIDLMessages.add(new PendingUIDLMessage(start, jsonText, | |||
json)); | |||
pendingUIDLMessages.add(new PendingUIDLMessage(json)); | |||
if (!forceHandleMessage.isRunning()) { | |||
forceHandleMessage.schedule(MAX_SUSPENDED_TIMEOUT); | |||
} | |||
return; | |||
} | |||
final Date start = new Date(); | |||
/* | |||
* Lock response handling to avoid a situation where something pushed | |||
* from the server gets processed while waiting for e.g. lazily loaded | |||
@@ -557,9 +545,7 @@ public class ServerMessageHandler { | |||
getLogger().info( | |||
" Processing time was " | |||
+ String.valueOf(lastProcessingTime) | |||
+ "ms for " + jsonText.length() | |||
+ " characters of JSON"); | |||
+ String.valueOf(lastProcessingTime) + "ms"); | |||
getLogger().info( | |||
"Referenced paintables: " + getConnectorMap().size()); | |||
@@ -1518,8 +1504,7 @@ public class ServerMessageHandler { | |||
pendingUIDLMessages = new ArrayList<PendingUIDLMessage>(); | |||
for (PendingUIDLMessage pending : pendingMessages) { | |||
handleUIDLMessage(pending.getStart(), pending.getJsonText(), | |||
pending.getJson()); | |||
handleJSON(pending.getJson()); | |||
} | |||
} | |||
} |
@@ -202,7 +202,7 @@ public class ServerRpcQueue { | |||
return; | |||
} | |||
connection.getServerCommunicationHandler() | |||
.doSendPendingVariableChanges(); | |||
.sendInvocationsToServer(); | |||
} | |||
}; | |||
@@ -15,8 +15,6 @@ | |||
*/ | |||
package com.vaadin.tests.widgetset.client; | |||
import java.util.Date; | |||
import com.vaadin.client.ValueMap; | |||
import com.vaadin.client.communication.ServerMessageHandler; | |||
import com.vaadin.shared.ApplicationConstants; | |||
@@ -27,11 +25,11 @@ public class MockServerMessageHandler extends ServerMessageHandler { | |||
protected String lastCsrfTokenReceiver; | |||
@Override | |||
public void handleUIDLMessage(Date start, String jsonText, ValueMap json) { | |||
public void handleJSON(ValueMap json) { | |||
lastCsrfTokenReceiver = json | |||
.getString(ApplicationConstants.UIDL_SECURITY_TOKEN_ID); | |||
super.handleUIDLMessage(start, jsonText, json); | |||
super.handleJSON(json); | |||
} | |||
} |