Search in sources :

Example 1 with ValueMap

use of com.vaadin.client.ValueMap in project flow by vaadin.

the class MessageHandler method processMessage.

/**
 * Performs the actual processing of a server message when all dependencies
 * have been loaded.
 *
 * @param valueMap
 *            the message payload
 * @param lock
 *            the lock object for this response
 * @param start
 *            the time stamp when processing started
 */
private void processMessage(ValueMap valueMap, Object lock, Date start) {
    assert getServerId(valueMap) == -1 || getServerId(valueMap) == lastSeenServerSyncId;
    try {
        double processUidlStart = Duration.currentTimeMillis();
        JsonObject json = valueMap.cast();
        if (json.hasKey("templates")) {
            TemplateRegistry templates = registry.getTemplateRegistry();
            JsonObject templatesJson = json.getObject("templates");
            templates.importFromJson(templatesJson);
        }
        if (json.hasKey("constants")) {
            ConstantPool constantPool = registry.getConstantPool();
            JsonObject constants = json.getObject("constants");
            constantPool.importFromJson(constants);
        }
        if (json.hasKey("changes")) {
            processChanges(json);
        }
        if (json.hasKey(JsonConstants.UIDL_KEY_EXECUTE)) {
            // Invoke JS only after all tree changes have been
            // propagated
            Reactive.addPostFlushListener(() -> registry.getExecuteJavaScriptProcessor().execute(json.getArray(JsonConstants.UIDL_KEY_EXECUTE)));
        }
        Console.log("handleUIDLMessage: " + (Duration.currentTimeMillis() - processUidlStart) + " ms");
        ValueMap meta = valueMap.getValueMap("meta");
        if (meta != null) {
            Profiler.enter("Error handling");
            if (meta.containsKey(JsonConstants.META_SESSION_EXPIRED)) {
                if (nextResponseSessionExpiredHandler != null) {
                    nextResponseSessionExpiredHandler.execute();
                } else {
                    registry.getSystemErrorHandler().handleSessionExpiredError(null);
                    registry.getUILifecycle().setState(UIState.TERMINATED);
                }
            } else if (meta.containsKey("appError")) {
                ValueMap error = meta.getValueMap("appError");
                registry.getSystemErrorHandler().handleUnrecoverableError(error.getString("caption"), error.getString("message"), error.getString("details"), error.getString("url"));
                registry.getUILifecycle().setState(UIState.TERMINATED);
            }
            Profiler.leave("Error handling");
        }
        nextResponseSessionExpiredHandler = null;
        Reactive.flush();
        lastProcessingTime = (int) ((new Date().getTime()) - start.getTime());
        totalProcessingTime += lastProcessingTime;
        if (!initialMessageHandled) {
            initialMessageHandled = true;
            double fetchStart = getFetchStartTime();
            if (fetchStart != 0) {
                int time = (int) (Duration.currentTimeMillis() - fetchStart);
                Console.log("First response processed " + time + " ms after fetchStart");
            }
            bootstrapTime = calculateBootstrapTime();
            if (Profiler.isEnabled() && bootstrapTime != -1) {
                Profiler.logBootstrapTimings();
            }
        }
    } finally {
        Console.log(" Processing time was " + String.valueOf(lastProcessingTime) + "ms");
        endRequestIfResponse(valueMap);
        resumeResponseHandling(lock);
        if (Profiler.isEnabled()) {
            Scheduler.get().scheduleDeferred(() -> {
                Profiler.logTimings();
                Profiler.reset();
            });
        }
    }
}
Also used : TemplateRegistry(com.vaadin.client.flow.template.TemplateRegistry) ConstantPool(com.vaadin.client.flow.ConstantPool) ValueMap(com.vaadin.client.ValueMap) JsonObject(elemental.json.JsonObject) Date(java.util.Date)

Example 2 with ValueMap

use of com.vaadin.client.ValueMap in project flow by vaadin.

the class AtmospherePushConnection method onMessage.

/**
 * Called whenever a message is received by Atmosphere.
 *
 * @param response
 *            the Atmosphere response object, which contains the message
 */
protected void onMessage(AtmosphereResponse response) {
    String message = response.getResponseBody();
    ValueMap json = MessageHandler.parseWrappedJson(message);
    if (json == null) {
        // Invalid string (not wrapped as expected)
        getConnectionStateHandler().pushInvalidContent(this, message);
        return;
    } else {
        Console.log("Received push (" + getTransportType() + ") message: " + message);
        registry.getMessageHandler().handleMessage(json);
    }
}
Also used : ValueMap(com.vaadin.client.ValueMap)

Example 3 with ValueMap

use of com.vaadin.client.ValueMap in project flow by vaadin.

the class Bootstrapper method doStartApplication.

private static void doStartApplication(final String applicationId) {
    Profiler.enter("Bootstrapper.startApplication");
    ApplicationConfiguration appConf = getConfigFromDOM(applicationId);
    ApplicationConnection applicationConnection = new ApplicationConnection(appConf);
    runningApplications.push(applicationConnection);
    Profiler.leave("Bootstrapper.startApplication");
    ValueMap initialUidl = getJsoConfiguration(applicationId).getUIDL();
    applicationConnection.start(initialUidl);
}
Also used : ValueMap(com.vaadin.client.ValueMap) ApplicationConfiguration(com.vaadin.client.ApplicationConfiguration) ApplicationConnection(com.vaadin.client.ApplicationConnection)

Example 4 with ValueMap

use of com.vaadin.client.ValueMap in project flow by vaadin.

the class MessageHandler method processMessage.

/**
 * Performs the actual processing of a server message when all dependencies
 * have been loaded.
 *
 * @param valueMap
 *            the message payload
 * @param lock
 *            the lock object for this response
 * @param start
 *            the time stamp when processing started
 */
private void processMessage(ValueMap valueMap, Object lock, double start) {
    assert getServerId(valueMap) == -1 || getServerId(valueMap) == lastSeenServerSyncId;
    try {
        double processUidlStart = Duration.currentTimeMillis();
        JsonObject json = valueMap.cast();
        if (json.hasKey("constants")) {
            ConstantPool constantPool = registry.getConstantPool();
            JsonObject constants = json.getObject("constants");
            constantPool.importFromJson(constants);
        }
        if (json.hasKey("changes")) {
            processChanges(json);
        }
        if (json.hasKey(JsonConstants.UIDL_KEY_EXECUTE)) {
            // Invoke JS only after all tree changes have been
            // propagated and after post flush listeners added during
            // message processing (so add one more post flush listener which
            // is called after all added post listeners).
            Reactive.addPostFlushListener(() -> Reactive.addPostFlushListener(() -> registry.getExecuteJavaScriptProcessor().execute(json.getArray(JsonConstants.UIDL_KEY_EXECUTE))));
        }
        Console.log("handleUIDLMessage: " + (Duration.currentTimeMillis() - processUidlStart) + " ms");
        Reactive.flush();
        ValueMap meta = valueMap.getValueMap("meta");
        if (meta != null) {
            Profiler.enter("Error handling");
            final UIState uiState = registry.getUILifecycle().getState();
            if (meta.containsKey(JsonConstants.META_SESSION_EXPIRED)) {
                if (nextResponseSessionExpiredHandler != null) {
                    nextResponseSessionExpiredHandler.execute();
                } else if (uiState != UIState.TERMINATED) {
                    registry.getSystemErrorHandler().handleSessionExpiredError(null);
                    registry.getUILifecycle().setState(UIState.TERMINATED);
                }
            } else if (meta.containsKey("appError") && uiState != UIState.TERMINATED) {
                ValueMap error = meta.getValueMap("appError");
                registry.getSystemErrorHandler().handleUnrecoverableError(error.getString("caption"), error.getString("message"), error.getString("details"), error.getString("url"), error.getString("querySelector"));
                registry.getUILifecycle().setState(UIState.TERMINATED);
            }
            Profiler.leave("Error handling");
        }
        nextResponseSessionExpiredHandler = null;
        lastProcessingTime = (int) (Duration.currentTimeMillis() - start);
        totalProcessingTime += lastProcessingTime;
        if (!initialMessageHandled) {
            initialMessageHandled = true;
            double fetchStart = getFetchStartTime();
            if (fetchStart != 0) {
                int time = (int) (Duration.currentTimeMillis() - fetchStart);
                Console.log("First response processed " + time + " ms after fetchStart");
            }
            bootstrapTime = calculateBootstrapTime();
            if (Profiler.isEnabled() && bootstrapTime != -1) {
                Profiler.logBootstrapTimings();
            }
        }
    } finally {
        Console.log(" Processing time was " + String.valueOf(lastProcessingTime) + "ms");
        endRequestIfResponse(valueMap);
        resumeResponseHandling(lock);
        if (Profiler.isEnabled()) {
            Scheduler.get().scheduleDeferred(() -> {
                Profiler.logTimings();
                Profiler.reset();
            });
        }
    }
}
Also used : ConstantPool(com.vaadin.client.flow.ConstantPool) UIState(com.vaadin.client.UILifecycle.UIState) ValueMap(com.vaadin.client.ValueMap) JsonObject(elemental.json.JsonObject)

Example 5 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.toolkit.ui.client.profiler.ScreenClientProfiler) ValueMap(com.vaadin.client.ValueMap) Request(com.google.gwt.http.client.Request)

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