Describe an event's fields once -- get the AbstractEvent class, its AbstractEventListener subclass, the Spring bean wiring it up, and an example of publishing it.
🔒 Your code never leaves your browser — everything is generated locally from templates, no AI, no server round-trip.
trainingcore/src/com/prospect2p/core/events/OrderStatusChangedEvent.javapackage com.prospect2p.core.events;
import de.hybris.platform.servicelayer.event.events.AbstractEvent;
public class OrderStatusChangedEvent extends AbstractEvent
{
private final java.lang.String orderCode;
public OrderStatusChangedEvent(final java.lang.String orderCode)
{
this.orderCode = orderCode;
}
public java.lang.String getOrderCode()
{
return orderCode;
}
}
SAP Commerce (Hybris) has a lightweight, in-process publish/subscribe mechanism built on EventService: application code publishes a POJO event (extending AbstractEvent), and any Spring bean registered as an AbstractEventListener<T> for that event type gets its onEvent() called synchronously by the publishing thread.
It's intentionally simple -- no message broker, no persistence, no retry -- which makes it the right tool for same-process notifications (kick off a process, invalidate a cache, write an audit log) and the wrong tool for anything that needs guaranteed delivery or to survive a restart.
Use an event + listener to decouple "something happened" from "here's what to do about it" -- e.g. publish an OrderPlacedEvent from checkout code, and let one or more listeners react (send a confirmation email, update analytics, trigger a warehouse process) without checkout code knowing about any of them.
If the reaction needs to run on a schedule rather than in response to something happening, use a CronJob instead. If it needs to pause and resume over a long period, start a Business Process from the listener rather than doing the work directly in onEvent().
Synchronous by default -- publishEvent() calls every matching listener's onEvent() on the calling thread before returning. Some projects configure an asynchronous event multicaster for specific event types, but that's an explicit Spring configuration choice, not the default.
It handles the type filtering -- onEvent(AbstractEvent) from the Spring event system checks whether the incoming event is an instance of T before delegating to your typed, protected onEvent(T event) method, so you never need an instanceof check yourself.
When the event needs to be handled on every node of a cluster, not just the node that published it (e.g. invalidating a local cache everywhere). This generator adds the implements clause when requested but leaves the required method as a verify-and-implement TODO, since its exact signature has shifted across SAP Commerce versions.
Yes -- register as many AbstractEventListener<T> beans for the same event type as needed; EventService calls all of them. There's no guaranteed ordering between listeners unless you add your own coordination.
An event should represent an immutable fact about something that already happened. If a listener needs to react differently based on some field, it should read it via a getter -- not mutate the event, which other listeners may still be reading.