Какво означава това предупреждение във Vaadin: Игнориране на RPC повикване за деактивиран конектор com.vaadin.ui.Window?

Опитах се да потърся в Google, за да намеря някои съвети и да разгледам уебсайта на Vaadin, но не намерих нищо свързано с този цар на проблема:

В конзолата, когато стартирам приложението, виждам това предупреждение няколко пъти:

Игнориране на RPC повикване за деактивиран конектор com.vaadin.ui.Window, caption=Надпис на прозореца

Използвам добавката Refresher, която анкетира сървъра ми на интервал от 2000 милисекунди. и добавката ICEPush, която прилага натискане към потребителския интерфейс на Vaadin.

Мисля, че това е свързано по някакъв начин с добавката Refresher, защото ако взаимодействам с компонент, който съм създал за тест (под кода), предупрежденията се добавят към конзолата.

Ето кода:

package com.example.events;

import java.util.ArrayList;
import java.util.List;

import com.github.wolfie.refresher.Refresher;
import com.vaadin.event.FieldEvents.BlurListener;
import com.vaadin.event.FieldEvents.FocusListener;
import com.vaadin.event.FieldEvents.TextChangeEvent;
import com.vaadin.event.FieldEvents.TextChangeListener;
import com.vaadin.event.LayoutEvents.LayoutClickNotifier;
import com.vaadin.ui.AbstractTextField.TextChangeEventMode;
import com.vaadin.ui.Button;

import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.Component;
import com.vaadin.ui.Label;
import com.vaadin.ui.Layout;
import com.vaadin.ui.Notification;
import com.vaadin.ui.TextArea;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window;

public class Noticeboard extends VerticalLayout {

    /**
     * 
     */
    private static final long serialVersionUID = -6023888496081433464L;

    private static List<Note> notes = new ArrayList<Note>();
    private List<Window> windows = new ArrayList<Window>();
    private static int userCount;
    private int userId;
    private static int noteId;
    private Refresher refresher = new Refresher();
    private static final int UPDATE_INTERVAL = 2000;
    private Note currentlyFocusedNote;

    public class NoticeboardUpdater extends Thread {

        @Override
        public void run() {
            while (true) {
                try {
                    Thread.sleep(UPDATE_INTERVAL);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                getUI().getSession().getLockInstance().lock();
                try {
                    updateNoticeboard();
                } finally {
                    getUI().getSession().getLockInstance().unlock();
                }
            }
        }

    }

    public Noticeboard() {
        refresher.setRefreshInterval(UPDATE_INTERVAL);
        userId = ++userCount;
        setSpacing(true);
        setMargin(true);
        addComponent(new Label("Logged in as User " + userId));
        Button addNoteButton = new Button("Add note");

        addNoteButton.addClickListener(new ClickListener() {

            /**
             * 
             */
            private static final long serialVersionUID = -4927018162887570343L;

            @Override
            public void buttonClick(ClickEvent event) {
                Note note = new Note(++noteId);
                note.setCaption("Note " + note.getId());
                notes.add(note);

                Window window = createWindow(note);
                windows.add(window);

                UI.getCurrent().addWindow(window);
            }
        });

        addComponent(addNoteButton);
        addExtension(refresher);        
        new NoticeboardUpdater().start();
    }

    private Window createWindow(final Note note) {
        final Window window = new Window(note.getCaption());
        VerticalLayout layout = new VerticalLayout();
        layout.addComponent(createContentNote(note, window));
        window.setContent(layout);
        window.setWidth(300, Unit.PIXELS);
        window.setResizable(false);
        window.setPositionX(note.getPositionX());
        window.setPositionY(note.getPositionY());
        window.setData(note);
        window.addBlurListener(createBlurListener(window));
        window.addFocusListener(createFocusListener(window));

        LayoutClickNotifier mainLayout = (LayoutClickNotifier) getUI().getContent();
        mainLayout.addLayoutClickListener(e -> {
            if (note.isNoteFocusedWindow() || note.isNoteFocusedTextArea()) {               
                if (note.getLockedByUser() > -1 && note.getLockedByUser() == userId) {                  
                    unlockNote(getWindow(currentlyFocusedNote));
                    note.setNoteFocusedWindow(false);
                    note.setNoteBlurredWindow(false);
                    note.setNoteFocusedTextArea(false);
                    note.setNoteBlurredTextArea(false);                 

                    currentlyFocusedNote = null;
                }
            }
        });

        return window;
    }

    private TextArea createContentNote(final Note note, final Window window) {
        TextArea contentNote = new TextArea();
        contentNote.setSizeFull();
        contentNote.setValue(note.getText());
        contentNote.setImmediate(true);
        contentNote.setTextChangeEventMode(TextChangeEventMode.EAGER);
        contentNote.addBlurListener(createBlurListener(window));
        contentNote.addFocusListener(createFocusListener(window));
        contentNote.addTextChangeListener(new TextChangeListener() {

            /**
             * 
             */
            private static final long serialVersionUID = 8552875156973567499L;

            @Override
            public void textChange(TextChangeEvent event) {
                note.setText(event.getText());
            }
        });
        return contentNote;
    }

    private BlurListener createBlurListener(Window window) {
        return e -> {
            Component blurredComponent = e.getComponent();

            if (blurredComponent == window)  {
                currentlyFocusedNote.setNoteBlurredWindow(true);
            }
            else if (blurredComponent == (((Layout) window.getContent())).iterator().next()) {
                currentlyFocusedNote.setNoteBlurredTextArea(true);
            }

        };
    }

    private FocusListener createFocusListener(Window window) {
        return e -> {
            Component focusedComponent = e.getComponent();
            Note note = (Note) window.getData();

            if (currentlyFocusedNote != null && currentlyFocusedNote != note) {
                unlockNote(getWindow(currentlyFocusedNote));        
                currentlyFocusedNote.setNoteFocusedWindow(false);
                currentlyFocusedNote.setNoteBlurredWindow(false);
                currentlyFocusedNote.setNoteFocusedTextArea(false);
                currentlyFocusedNote.setNoteBlurredTextArea(false);
            }

            currentlyFocusedNote = note;
            if (focusedComponent == window) {
                Notification.show("Focused Note Window");
                currentlyFocusedNote.setNoteFocusedWindow(true);
            }
            else if (focusedComponent == (((Layout) window.getContent())).iterator().next()) {
                Notification.show("Focused Note TextArea");
                currentlyFocusedNote.setNoteFocusedTextArea(true);
            }

            if (currentlyFocusedNote.isNoteFocusedWindow() && currentlyFocusedNote.isNoteBlurredTextArea() || 
                currentlyFocusedNote.isNoteFocusedTextArea() && currentlyFocusedNote.isNoteBlurredWindow()) {
                // Lock is already set here, skipping
                return;
            }                       
            lockNote(window);
        };
    }

    private void lockNote(Window window) {
        Note note = (Note) window.getData();
        note.setLockedByUser(userId);
        String caption = "Locked by User " + userId;
        note.setCaption(caption);
        window.setCaption(caption);
    }

    private void unlockNote(Window window) {
        Note note = (Note) window.getData();
        note.setLockedByUser(-1);
        note.setPositionX(window.getPositionX());
        note.setPositionY(window.getPositionY());
        note.setCaption("Note " + note.getId());
        window.setCaption("Note " + note.getId());
    }

    private void updateNoticeboard() {
        for (Note note : notes) {
            Window window = getWindow(note);

            if (window == null) {
                window = createWindow(note);
                windows.add(window);
                UI.getCurrent().addWindow(window);
            }

            if (note.getLockedByUser() > -1) {
                if (note.getLockedByUser() != userId) {
                    // If the note is locked by another user, then we disable this window. 
                    window.setEnabled(false);

                    updateTextArea(window, note);                   
                    updateWindowPosition(window, note);
                }
                else {                  
                    // Otherwise the window is enabled.
                    window.setEnabled(true);
                    Note focusedNote = (Note) window.getData();

                    updateFocusedNotePosition(focusedNote, window);
                }
            }           
            else {
                window.setEnabled(true);
                updateTextArea(window, note);
                updateWindowPosition(window, note);
            }           
        }
    }

    private void updateTextArea(Window window, Note note) {
        Layout layout = (Layout) window.getContent();
        TextArea area = (TextArea) layout.iterator().next();
        area.setValue(note.getText());
    }

    private Window getWindow(Note note) {
        for (Window window : windows) {
            if (window.getData().equals(note))
                return window;
        }
        return null;
    }

    private void updateWindowPosition(Window window, Note note) {
        window.setPositionX(note.getPositionX());
        window.setPositionY(note.getPositionY());
        window.setCaption(note.getCaption());
    }

    private void updateFocusedNotePosition(Note focusedNote, Window window) {       
        focusedNote.setPositionX(window.getPositionX());
        focusedNote.setPositionY(window.getPositionY());
        focusedNote.setCaption(window.getCaption());
    }
}

И вътре в метода init на потребителския интерфейс просто използвам този клас Noticeboard:

@Override
protected void init(VaadinRequest request) {
    setContent(new Noticeboard());
}

Когато преместя прозорец, създаден с бутона „Добавяне на бележка“, или променя фокуса от прозорец на друг, получавам предупреждението.

Каква може да е причината за такъв проблем?

Знам, че кодът не е от по-добрите, той е само за да видите как се държат тези добавки на Vaadin.


person tonix    schedule 17.02.2015    source източник
comment
Страничен коментар: Тъй като използвате Vaadin 7, бих ви разубедил да използвате ICEPush (тъй като това е експериментална добавка) и Refresher. И двете функционалности са вградени в рамката. Анотирайте потребителския си интерфейс с @Push, за да замените функционалността на ICEPush, и използвайте ui.setPollInterval(..) / ui.addPollListener(..), за да замените Refresher.   -  person Kim L    schedule 18.02.2015
comment
Да, знаех го. Намерих интегрирането на атмосферата на Vaadin за хубава функция, но все пак има някои проблеми, когато трябва да натиснете всички потребителски интерфейси, отворени от потребителя в браузъра. Има метод VaadinSession.getCurrent().getUIs(), който изглежда не връща колекция от потребителски интерфейси само с един потребителски интерфейс (всъщност текущият, странно, да?), вместо всички. Също така отворих тема във форума на Vaadin vaadin.com/forum#!/thread/ 8792945/8792944. Така или иначе това не е свързано с темата на въпроса. Смятате ли, че това се дължи на използването на старата добавка Refresher?   -  person tonix    schedule 18.02.2015


Отговори (1)


Когато деактивирате компонент, деактивираното състояние се обработва както от страна на клиента, така и от страна на сървъра, което означава, че компонентът не е просто визуално деактивиран, но сървърът също отказва да обработва всякакви заявки към деактивиран компонент.

Предупреждението, което виждате, означава, че има RPC заявка (HTTP заявка от страна на клиента), която е насочена към деактивиран компонент. Тъй като компонентът е деактивиран, RPC заявката ще бъде игнорирана.

Това обикновено се случва, когато имате фонова нишка, която деактивира компонент и след това също извършва анкета от страна на клиента.

person Kim L    schedule 18.02.2015
comment
Благодаря ви за пояснението! - person tonix; 18.02.2015
comment
Освен това има дискусия с Vaadin 13.0.3 относно подобно предупредително съобщение WARN com.vaadin.flow.server.communication.rpc.MapSyncRpcHandler - Заявка за актуализиране на собственост за деактивиран елемент се получава от страна на клиента. Имотът е „невалиден“. Заявката се игнорира. тук: github.com/vaadin/vaadin-text-field-flow/ проблеми/169 - person S. Doe; 22.01.2020
comment
Ето някои допълнителни дискусии за това във форума на Vaadin: vaadin.com/forum/thread/18034776 - person Jonathan Hult; 07.08.2020