Search in sources :

Example 6 with ValueMap

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));
            }
        }
    };
}
Also used : Response(com.google.gwt.http.client.Response) ScreenClientProfiler(com.haulmont.cuba.web.widgets.client.profiler.ScreenClientProfiler) ValueMap(com.vaadin.client.ValueMap) Request(com.google.gwt.http.client.Request)

Example 7 with ValueMap

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");
    }
}
Also used : UIState(com.vaadin.client.UILifecycle.UIState) ValueMap(com.vaadin.client.ValueMap)

Example 8 with ValueMap

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;
    }
}
Also used : ValueMap(com.vaadin.client.ValueMap)

Aggregations

ValueMap (com.vaadin.client.ValueMap)8 Request (com.google.gwt.http.client.Request)2 Response (com.google.gwt.http.client.Response)2 UIState (com.vaadin.client.UILifecycle.UIState)2 ConstantPool (com.vaadin.client.flow.ConstantPool)2 JsonObject (elemental.json.JsonObject)2 ScreenClientProfiler (com.haulmont.cuba.web.toolkit.ui.client.profiler.ScreenClientProfiler)1 ScreenClientProfiler (com.haulmont.cuba.web.widgets.client.profiler.ScreenClientProfiler)1 ApplicationConfiguration (com.vaadin.client.ApplicationConfiguration)1 ApplicationConnection (com.vaadin.client.ApplicationConnection)1 TemplateRegistry (com.vaadin.client.flow.template.TemplateRegistry)1 Date (java.util.Date)1