Example usage for org.springframework.context ApplicationEvent getClass

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

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:org.grails.plugin.platform.events.publisher.GormBridgePublisher.java

public void onApplicationEvent(ApplicationEvent applicationEvent) {
    //fixme horrible hack to support grails 1.3.x
    if (applicationEvent.getClass().getName().startsWith(GORM_EVENT_PACKAGE)) {
        String topic = gormTopicSupport.convertTopic(applicationEvent);
        if (topic != null) {
            log.debug("sending " + applicationEvent + " to topic " + topic);

            Map<String, Object> params = new HashMap<String, Object>();
            params.put(EventsPublisher.GORM, false);
            params.put(EventsPublisher.FORK, false);

            EventReply reply = grailsEvents.event(GormTopicSupport.GORM_SOURCE, topic,
                    gormTopicSupport.extractEntity(applicationEvent), params);
            try {
                gormTopicSupport.processCancel(applicationEvent, reply != null ? reply.getValues() : null);
            } catch (Throwable e) {
                throw new RuntimeException(e);//shouldn't happen as its sync event
            }/*w  w w. j  a v a2 s  .c o m*/
        }
    }
}

From source file:it.geosolutions.geoserver.jms.JMSApplicationListener.java

@Override
public void onApplicationEvent(ApplicationEvent event) {
    if (LOGGER.isLoggable(Level.FINE)) {
        LOGGER.fine("Incoming event of type " + event.getClass().getSimpleName());
    }/*from w ww . ja va2  s  .co  m*/

    if (event instanceof ToggleEvent) {

        // enable/disable the producer
        final ToggleEvent tEv = (ToggleEvent) event;
        if (tEv.getType().equals(this.type)) {
            setStatus(tEv.toggleTo());
        }

    } else {
        if (LOGGER.isLoggable(Level.FINE)) {
            LOGGER.fine("Incoming application event of type " + event.getClass().getSimpleName());
        }
    }
}

From source file:com.scottieknows.test.autoconfigure.PostgresAutoConfiguration.java

@Override
public void onApplicationEvent(ApplicationEvent event) {
    log.info("receieved application event " + event.getClass().getName());
    if (event instanceof ContextRefreshedEvent) {
        ContextRefreshedEvent e = (ContextRefreshedEvent) event;
        ApplicationContext ctx = e.getApplicationContext();
        restartPostgres(ctx);//from   ww  w .  j  av  a 2  s . co  m
    } else if (event instanceof ContextClosedEvent) {
        process.ifPresent(p -> p.stop());
    }
}

From source file:werecloud.api.bean.VMWareMacCache.java

@Override
public void onApplicationEvent(ApplicationEvent event) {
    try {//from ww  w  .j av a 2s. c o  m
        Method m = this.getClass().getMethod("handle", event.getClass());
        m.invoke(this, event);
        return;
    } catch (NoSuchMethodException nme) {
        logger.trace(String.format("Unhandled event: %s", event));
    } catch (Exception e) {
        logger.error("Error: ", e);
    }
    //        logger.trace(event.toString());
}

From source file:com.agileapes.couteau.context.spring.event.impl.AbstractMappedEventsTranslationScheme.java

@Override
public void fillIn(Event originalEvent, ApplicationEvent translated) throws EventTranslationException {
    for (Method method : originalEvent.getClass().getMethods()) {
        if (!method.getName().matches("set[A-Z].*") || !Modifier.isPublic(method.getModifiers())
                || !method.getReturnType().equals(void.class) || method.getParameterTypes().length != 1) {
            continue;
        }//  w w w .ja v a2 s. c o  m
        final String propertyName = StringUtils.uncapitalize(method.getName().substring(3));
        final Field field = ReflectionUtils.findField(translated.getClass(), propertyName);
        if (field == null || !method.getParameterTypes()[0].isAssignableFrom(field.getType())) {
            continue;
        }
        field.setAccessible(true);
        try {
            method.invoke(originalEvent, field.get(translated));
        } catch (Exception e) {
            throw new EventTranslationException("Failed to set property on original event: " + propertyName, e);
        }
    }
}

From source file:com.ebay.pulsar.metriccalculator.processor.MCSummingProcessor.java

@Override
public void processApplicationEvent(ApplicationEvent event) {
    if (event instanceof ContextBeanChangedEvent) {
        ContextBeanChangedEvent bcInfo = (ContextBeanChangedEvent) event;
        // Apply changes
        if (bcInfo.getBeanName().equals(getConfiguration().getBeanName())) {
            LOGGER.info("Received change bean:  - " + event.getClass().getName());
            LOGGER.info("Received new configuration for  - " + bcInfo.getBeanName());
            try {
                setConfiguration(((MCSummingConfiguration) bcInfo.getChangedBean()));
            } catch (Exception e) {
                LOGGER.error("Error while applying config to MCSummingProcessor - " + e.getMessage());
            }//from   w  w w . j a va  2s .com
        }
    }
}

From source file:com.ebay.pulsar.metriccalculator.processor.MetricCassandraCollector.java

@Override
protected void processApplicationEvent(ApplicationEvent event) {
    if (event instanceof ContextBeanChangedEvent) {
        ContextBeanChangedEvent bcInfo = (ContextBeanChangedEvent) event;
        // Apply changes
        if (bcInfo.getBeanName().equals(getConfig().getBeanName())) {
            LOGGER.info("Received change bean:  - " + event.getClass().getName());
            LOGGER.info("Received new configuration for  - " + bcInfo.getBeanName());
            try {
                setConfig(((CassandraConfig) bcInfo.getChangedBean()));
            } catch (Exception e) {
                LOGGER.warn("Error while applying config to CassandraConfig - " + e.getMessage());
            }//from w w w . jav a2 s .  com
            if ((!getConfig().getKeySpace().equals(this.keySpace))
                    || (getConfig().getContactPoints() != this.contactPoints)) {
                if (config.getEnableCassandra()) {
                    disconnect();
                    connect();
                }
            }
        }
    }
}

From source file:org.trpr.platform.core.impl.event.PlatformEventMulticaster.java

/**
 * Interface method implementation. Forwards the published event to all event consumers whose subscriptions match the endpointURI
 * contained in the specified PlatformApplicationEvent.
 * Note that Spring ApplicationEvent instances that are not of type PlatformApplicationEvent are ignored and a warning message is logged.
 * @see org.springframework.context.event.ApplicationEventMulticaster#multicastEvent(org.springframework.context.ApplicationEvent)
 *//*  w  ww .  j  a v a  2 s .  co m*/
public void multicastEvent(ApplicationEvent event) {
    if (event instanceof PlatformApplicationEvent) {
        PlatformApplicationEvent platformApplicationEvent = (PlatformApplicationEvent) event;
        String eventEndpointURI = platformApplicationEvent.getEndpointURI();
        if (eventEndpointURI == null) {
            LOGGER.warn(
                    "End-point URI of PlatformApplicationEvent is null. Event will not be forwarded. Event type is : "
                            + platformApplicationEvent.getClass().getName());
            return;
        }
        if (!isSubscriptionMatch(eventEndpointURI, subscriptions)) {
            LOGGER.warn(
                    "Endpoint URI doesnot match any of the subscriptions specified on this multi-caster. Event will not be forwarded. Event URI is : "
                            + eventEndpointURI);
            return;
        }
        for (Iterator iterator = getApplicationListeners().iterator(); iterator.hasNext();) {
            ApplicationListener listener = (ApplicationListener) iterator.next();
            if (listener instanceof EndpointEventConsumer) {
                if (isSubscriptionMatch(eventEndpointURI,
                        ((EndpointEventConsumer) listener).getSubscriptions())) {
                    listener.onApplicationEvent(event);
                }
            }
        }
    } else {
        // log a warning and ignore the event
        LOGGER.warn("Spring ApplicationEvent of un-supported type received : " + event.getClass().getName()
                + ". Only PlatformApplicationEvent instances with be forwarded.");
    }
}

From source file:org.trpr.platform.servicefw.impl.event.PlatformEventMulticaster.java

/**
 * Interface method implementation. Forwards the published event to all event consumers whose subscriptions match the endpointURI
 * contained in the specified PlatformApplicationEvent.
 * Note that Spring ApplicationEvent instances that are not of type PlatformApplicationEvent are ignored and a warning message is logged.
 * @see org.springframework.context.event.ApplicationEventMulticaster#multicastEvent(org.springframework.context.ApplicationEvent)
 *///from w  w w.  java2 s .  com
@SuppressWarnings({ "rawtypes", "unchecked" })
public void multicastEvent(ApplicationEvent event) {
    if (event instanceof PlatformApplicationEvent) {
        PlatformApplicationEvent platformApplicationEvent = (PlatformApplicationEvent) event;
        String eventEndpointURI = platformApplicationEvent.getEndpointURI();
        if (eventEndpointURI == null) {
            LOGGER.warn(
                    "End-point URI of PlatformApplicationEvent is null. Event will not be forwarded. Event type is : "
                            + platformApplicationEvent.getClass().getName());
            return;
        }
        if (!isSubscriptionMatch(eventEndpointURI, subscriptions)) {
            LOGGER.warn(
                    "Endpoint URI doesnot match any of the subscriptions specified on this multi-caster. Event will not be forwarded. Event URI is : "
                            + eventEndpointURI);
            return;
        }
        for (Iterator<ApplicationListener> iterator = getApplicationListeners().iterator(); iterator
                .hasNext();) {
            ApplicationListener listener = (ApplicationListener) iterator.next();
            if (listener instanceof ServiceEventConsumer) {
                if (isSubscriptionMatch(eventEndpointURI,
                        ((ServiceEventConsumer) listener).getSubscriptions())) {
                    listener.onApplicationEvent(event);
                }
            }
        }
    } else {
        // log a warning and ignore the event
        LOGGER.warn("Spring ApplicationEvent of un-supported type received : " + event.getClass().getName()
                + ". Only PlatformApplicationEvent instances with be forwarded.");
    }
}

From source file:org.alfresco.repo.management.SafeApplicationEventMulticaster.java

/**
 * Return a Collection of ApplicationListeners matching the given event
 * type. Non-matching listeners get excluded early.
 * //  w  ww .  j av a2 s .co m
 * @param event
 *            the event to be propagated. Allows for excluding non-matching
 *            listeners early, based on cached matching information.
 * @return a Collection of ApplicationListeners
 * @see org.springframework.context.ApplicationListener
 */
protected Collection<ApplicationListener> getApplicationListeners(ApplicationEvent event) {
    Class<? extends ApplicationEvent> eventType = event.getClass();
    Class sourceType = event.getSource().getClass();
    ListenerCacheKey cacheKey = new ListenerCacheKey(eventType, sourceType);
    ListenerRetriever retriever = this.retrieverCache.get(cacheKey);
    if (retriever != null) {
        return retriever.getApplicationListeners();
    } else {
        retriever = new ListenerRetriever(true);
        LinkedList<ApplicationListener> allListeners = new LinkedList<ApplicationListener>();
        synchronized (this.defaultRetriever) {
            if (!this.defaultRetriever.applicationListenerBeans.isEmpty()) {
                BeanFactory beanFactory = getBeanFactory();
                for (String listenerBeanName : this.defaultRetriever.applicationListenerBeans) {
                    ApplicationListener listener = beanFactory.getBean(listenerBeanName,
                            ApplicationListener.class);
                    if (supportsEvent(listener, eventType, sourceType)) {
                        retriever.applicationListenerBeans.add(listenerBeanName);
                        allListeners.add(listener);
                    }
                }
            }
            for (ApplicationListener listener : this.defaultRetriever.applicationListeners) {
                if (!allListeners.contains(listener) && supportsEvent(listener, eventType, sourceType)) {
                    retriever.applicationListeners.add(listener);
                    allListeners.add(listener);
                }
            }
            OrderComparator.sort(allListeners);
            this.retrieverCache.put(cacheKey, retriever);
        }
        if (log.isDebugEnabled()) {
            log.debug(allListeners.toString());
        }
        return allListeners;
    }
}