Example usage for org.springframework.context ApplicationEvent ApplicationEvent

List of usage examples for org.springframework.context ApplicationEvent ApplicationEvent

Introduction

In this page you can find the example usage for org.springframework.context ApplicationEvent ApplicationEvent.

Prototype

public ApplicationEvent(Object source) 

Source Link

Document

Create a new ApplicationEvent .

Usage

From source file:org.vaadin.spring.events.internal.ApplicationContextEventBrokerTest.java

@Test
public void testOnApplicationEvent() {
    ApplicationEvent event = new ApplicationEvent(this) {
        @Override/*from   w ww  .  j a  va  2s  .  c  om*/
        public Object getSource() {
            return "mySource";
        }
    };
    EventBus eventBus = mock(EventBus.class);
    new ApplicationContextEventBroker(eventBus).onApplicationEvent(event);
    verify(eventBus).publish("mySource", event);
}

From source file:org.vaadin.spring.events.support.ApplicationContextEventBrokerTest.java

@Test
public void testOnApplicationEvent() {
    ApplicationEvent event = new ApplicationEvent(this) {

        private static final long serialVersionUID = 7475015652750718692L;

        @Override//  w  ww .  ja v a 2s  .  co m
        public Object getSource() {
            return "mySource";
        }
    };
    EventBus eventBus = mock(EventBus.class);
    new ApplicationContextEventBroker(eventBus).onApplicationEvent(event);
    verify(eventBus).publish("mySource", event);
}

From source file:org.vaadin.spring.boot.sample.events.EventsUI.java

@Override
protected void init(VaadinRequest request) {
    setPollInterval(300);//from  w ww. j  av a  2  s  .com
    eventBus.subscribe(this);

    layout = new VerticalLayout(new Button("Publish UI Event", new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            eventBus.publish(EventsUI.this, "Hello World from UI");
        }
    }), new Button("Publish Session Event", new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            eventBus.publish(EventScope.SESSION, EventsUI.this, "Hello World from Session");
        }
    }), new Button("Publish Application Event", new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            eventBus.publish(EventScope.APPLICATION, EventsUI.this, "Hello World from Application");
        }
    }), new Button("Publish Application Context Event", new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            applicationContext.publishEvent(new ApplicationEvent("Hello World from ApplicationContext") {
                @Override
                public Object getSource() {
                    return EventsUI.this;
                }
            });
        }
    }));
    layout.setSpacing(true);
    setContent(layout);
}

From source file:org.vaadin.spring.samples.eventbus.EventBusUI.java

@Override
protected void init(VaadinRequest request) {
    eventBus.subscribe(this);

    layout = new VerticalLayout(new Button("Publish UI Event", new Button.ClickListener() {

        private static final long serialVersionUID = 8689690237641128195L;

        @Override//from  w w  w . jav  a  2 s.c o m
        public void buttonClick(Button.ClickEvent event) {
            eventBus.publish(EventBusUI.this, "Hello World from UI");
        }
    }), new Button("Publish Session Event", new Button.ClickListener() {

        private static final long serialVersionUID = 8115889975902717197L;

        @Override
        public void buttonClick(Button.ClickEvent event) {
            eventBus.publish(EventScope.SESSION, EventBusUI.this, "Hello World from Session");
        }
    }), new Button("Publish Application Event", new Button.ClickListener() {

        private static final long serialVersionUID = -48717169414706329L;

        @Override
        public void buttonClick(Button.ClickEvent event) {
            eventBus.publish(EventScope.APPLICATION, EventBusUI.this, "Hello World from Application");
        }
    }), new Button("Publish Application Context Event", new Button.ClickListener() {

        private static final long serialVersionUID = 3611256983844824815L;

        @Override
        public void buttonClick(Button.ClickEvent event) {
            applicationContext.publishEvent(new ApplicationEvent("Hello World from ApplicationContext") {

                private static final long serialVersionUID = -3039286026590540225L;

                @Override
                public Object getSource() {
                    return EventBusUI.this;
                }
            });
        }
    }));
    layout.setSpacing(true);
    layout.setMargin(true);
    setContent(layout);
}

From source file:com.frank.search.solr.core.mapping.SolrMappingEventPublisher.java

@SuppressWarnings("serial")
private ApplicationEvent initGenericApplicationEvent(Object event) {

    ApplicationEvent applicationEvent = null;

    if (event instanceof ApplicationEvent) {
        applicationEvent = ((ApplicationEvent) event);
    }//  www  . ja  v a 2  s  .c  o m

    if (SPRING_42_PAYLOAD_APPLICATION_EVENT_PRESENT) {

        try {

            Constructor<?> ctor = ClassUtils.getConstructorIfAvailable(ClassUtils
                    .forName(SPRING_42_PAYLOAD_APPLICATION_EVENT_CLASS_NAME, this.getClass().getClassLoader()),
                    Object.class, Object.class);
            applicationEvent = (ApplicationEvent) BeanUtils.instantiateClass(ctor, (Object) this, event);
        } catch (Exception e) {
            // ignore and fall back to ApplicationEvent
        }
    }

    if (applicationEvent == null) {
        applicationEvent = new ApplicationEvent(event) {
        };
    }
    return applicationEvent;
}