use of com.vaadin.client.ValueMap in project cuba by cuba-platform.
the class CubaXhrConnection method createResponseHandler.
@Override
protected XhrResponseHandler createResponseHandler() {
return new XhrResponseHandler() {
protected int serverTimeOnClient;
@Override
public void onResponseReceived(Request request, Response response) {
int statusCode = response.getStatusCode();
if (statusCode == 200) {
serverTimeOnClient = (int) Util.round(Profiler.getRelativeTimeMillis() - requestStartTime, 0);
}
super.onResponseReceived(request, response);
}
@Override
protected void beforeHandlingMessage(ValueMap json) {
super.beforeHandlingMessage(json);
ScreenClientProfiler profiler = ScreenClientProfiler.getInstance();
String profilerMarker = ScreenClientProfiler.getProfilerMarkerFromJson(json);
if (profilerMarker != null) {
int serverTimeOnServer = ScreenClientProfiler.getServerTimeFromJson(json);
if (serverTimeOnServer > 0) {
profiler.registerServerTime(profilerMarker, serverTimeOnServer);
profiler.registerNetworkTime(profilerMarker, serverTimeOnClient - serverTimeOnServer);
} else {
profiler.registerServerTime(profilerMarker, serverTimeOnClient);
}
profiler.registerEventTs(profilerMarker, ScreenClientProfiler.getEventTsFromJson(json));
}
}
};
}
use of com.vaadin.client.ValueMap in project flow by vaadin.
the class MessageHandler method handleMessage.
/**
* Handles a received UIDL JSON text, parsing it, and passing it on to the
* appropriate handlers, while logging timing information.
*
* @param json
* The JSON to handle
*/
public void handleMessage(final ValueMap json) {
if (json == null) {
throw new IllegalArgumentException("The json to handle cannot be null");
}
if (getServerId(json) == -1) {
ValueMap meta = json.getValueMap("meta");
// Log the error only if session didn't expire.
if (meta == null || !meta.containsKey(JsonConstants.META_SESSION_EXPIRED)) {
Console.error("Response didn't contain a server id. " + "Please verify that the server is up-to-date and that the response data has not been modified in transmission.");
}
}
UIState state = registry.getUILifecycle().getState();
if (state == UIState.INITIALIZING) {
// Application is starting up for the first time
state = UIState.RUNNING;
registry.getUILifecycle().setState(state);
}
if (state == UIState.RUNNING) {
handleJSON(json);
} else {
Console.warn("Ignored received message because application has already been stopped");
}
}
use of com.vaadin.client.ValueMap in project flow by vaadin.
the class MessageHandler method parseJson.
/**
* Unwraps and parses the given JSON, originating from the server.
*
* @param jsonText
* the json from the server
* @return A parsed ValueMap or null if the input could not be parsed (or
* was null)
*/
public static ValueMap parseJson(String jsonText) {
if (jsonText == null) {
return null;
}
final double start = Profiler.getRelativeTimeMillis();
try {
ValueMap json = parseJSONResponse(jsonText);
Console.log("JSON parsing took " + Profiler.getRelativeTimeString(start) + "ms");
return json;
} catch (final Exception e) {
Console.error("Unable to parse JSON: " + jsonText);
return null;
}
}
Aggregations