Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > Java: Общие вопросы > Stateful JMX Notification Listener does not work


Автор: LeoGL 11.6.2016, 18:35
на stackoverflow.com задал вчера вечером вопрос, но до сих пор ни одного комментария. Попытаю счастье здесь. Не хочу повторяться, поэтому вопрос просто скопирую сюда.

On the localhost runs an jmx agent which I connect via rmi to. To receive notifications sent by the agent I register a listener which is a ManagedBean (JSF 2.x). The registration happens with mBeanServerConnection.addNotificationListener. Below my listener:

Код

@ManagedBean(name = "eventViewListener")
@ApplicationScoped
public class EventViewListener implements NotificationListener, Serializable {

    private static final long   serialVersionUID        = 1L;
    private static final Logger LOG                     = Logger.getLogger(EventViewListener.class.getName());
    private static final int    MAX_NUMBER_OF_EVENTS    = 5;
    private final List<Notification> events             = new LinkedList<>();

    @Override
    public void handleNotification(final Notification notification, final Object handback) {
        if (events.size() >= MAX_NUMBER_OF_EVENTS) {
            events.remove(events.size() - 1);
        }
        events.add(0, notification);
    }

    public List<Notification> getEvents() {
        return this.events;
    }
}


I set a break point in the method handleNotification and see all the notifications are correctly sent and received. I also see in events all notifications received before. Despite of this if the getEvents is called by JSF component (page refresh) it always returns an empty list.

So, why does the getEvents always returns an empty list? For me it seems like there are two different instances in deal because of the serialization.

Автор: LSD 16.6.2016, 16:33
Дык в чем проблема, проверь свою гипотезу.
Код

private final UUID id = UUID.randomUUID();

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)