Hi,
sorry for the late answer. We cannot easily update to CDI 2.0 and I don't think that the priority annoation will help us because we have no predictable order for fireing events. But we expect that when we fire a specific event for one object and then fire another event for another object the listeners are executed in the same order.
In fact it is not easy for us to provide some code because in the software this is a little bit more complex, but I will provide some sample code to present what we did and what we expect.
{code:java} /** * * Only a dummy object to present the object operations */ public class EventObject { }
/** * Stateless Bean class that produces the events */ @Stateless public class EventProducerClass {
@Inject @Created Event<EventObject> createEvent;
@Inject @Locked Event<EventObject> lockEvent;
public void testEventing() { EventObject eo1 = new EventObject(); EventObject eo2 = new EventObject();
// first fire lock event for first object (we expect that this event is being handled by the observers below at first) lockEvent.fire(eo1); // second fire create event for second object (we expect that this event is being handled by the observers below at second) createEvent.fire(eo2); } }
/** * Sample Event consumer that reacts on the events after trasaction success. * In the above case the lock event on the first object is fired before the create event of the second object. * So we expect that the event of the lock event is being fired before the create event. * But in the case of after TX Success the create event of the second object is being fired before the lock event of the first object and that may be not the correct / expected behaviour. */ public class EventConsumerAfterTXSuccess {
public void onCreate(@Observes(during = TransactionPhase.AFTER_SUCCESS) @Created EventObject object) { // do some action after creating an object } public void onLock(@Observes(during = TransactionPhase.AFTER_SUCCESS) @Locked EventObject object) { // do some action on locking first object that must be done before the create event of the second object received } }
/** * Sample Event consumer that reacts on the events before the transaction was finished. * In the above case the lock event on the first object is fired before the create event of the second object. * So we expect that the event of the lock event is being fired before the create event. * And in this case of before TX Success the lock event of the first object is being fired before the create event of the second object and that is the correct behaviour. */ public class EventConsumerBeforeTXSuccess {
public void onCreate(@Observes(during = TransactionPhase.BEFORE_COMPLETION) @Created EventObject object) { // do some action after creating an object } public void onLock(@Observes(during = TransactionPhase.BEFORE_COMPLETION) @Locked EventObject object) { // do some action on locking first object that must be done before the create event of the second object received } } {code}
|
|