org.zodiac.reactor.event.GenericsPayloadApplicationEvent Maven / Gradle / Ivy
The newest version!
package org.zodiac.reactor.event;
import org.springframework.context.PayloadApplicationEvent;
import org.springframework.core.ResolvableType;
/**
* Dynamic generic events, which are used to dynamically publish events that support generics.
*
* //Equivalent to a publish event: EntityModifyEvent<UserEntity>
* eventPublisher
* .publishEvent(new GenericsPayloadApplicationEvent<>(this, new EntityModifyEvent<>(oldEntity, newEntity), UserEntity.class));
*
* //Only listen to the same generic events
* @EventListener
* public handleEvent(EntityModifyEvent<UserEntity> event){
*
* }
*
*
*/
public class GenericsPayloadApplicationEvent extends PayloadApplicationEvent {
private static final long serialVersionUID = 3745888943307798710L;
/*List of generics.*/
private transient Class[] generics;
/*The type of event.*/
private transient Class eventType;
/**
* @param source The event source
* @param payload The event, it can't be anonymous inner classes.
* @param generics List of generics.
*/
public GenericsPayloadApplicationEvent(Object source, E payload, Class... generics) {
super(source, payload);
this.generics = generics;
this.eventType = payload.getClass();
}
@Override
public ResolvableType getResolvableType() {
return ResolvableType.forClassWithGenerics(PayloadApplicationEvent.class
, ResolvableType.forClassWithGenerics(eventType, generics));
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy