@@ -0,0 +1,3683 @@
+/*%0A * Copyright (c) 2013 Red Rainbow IT Solutions GmbH, Germany%0A *%0A * Permission is hereby granted, free of charge, to any person obtaining a copy of%0A * this software and associated documentation files (the %22Software%22), to deal in%0A * the Software without restriction, including without limitation the rights to%0A * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of%0A * the Software, and to permit persons to whom the Software is furnished to do so,%0A * subject to the following conditions:%0A * %0A * The above copyright notice and this permission notice shall be included in all%0A * copies or substantial portions of the Software.%0A * %0A * THE SOFTWARE IS PROVIDED %22AS IS%22, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR%0A * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS%0A * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR%0A * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER%0A * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN%0A * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.%0A */%0A%0Apackage org.jeeventstore.core.notifier;%0A%0Aimport javax.annotation.Resource;%0Aimport javax.ejb.ConcurrencyManagement;%0Aimport javax.ejb.ConcurrencyManagementType;%0Aimport javax.ejb.Lock;%0Aimport javax.ejb.LockType;%0Aimport javax.ejb.Timeout;%0Aimport javax.ejb.Timer;%0Aimport javax.ejb.TimerConfig;%0Aimport javax.ejb.TimerService;%0Aimport javax.ejb.TransactionAttribute;%0Aimport javax.ejb.TransactionAttributeType;%0Aimport org.jeeventstore.core.ChangeSet;%0A%0A/**%0A * An asynchronous event store commit notifier.%0A * Notifies interested listeners asynchronously in a different thread, i.e.,%0A * the notifyListeners() method does not block.  The notifier begins to%0A * notify listeners when the transaction surrounding the call to notifyListeners()%0A * commits. If the surrounding transaction is rolled back, the listeners are %0A * not notified.  If the transaction from which notifyListeners() is called%0A * is committed, the actual notification is scheduled and will run in a new%0A * transaction.  The listeners are therefore running in a new transaction.%0A * If one of the listeners causes the notification-transaction to fail,%0A * the notification is re-tried automatically (as per EJB's TimerService semantics).%0A * %0A * The notification order is currently in the order of registration, but this is%0A * not a guarantee and might change in the future.%0A * %0A * @author Alexander Langer%0A */%0A@ConcurrencyManagement(ConcurrencyManagementType.CONTAINER)%0Apublic class AsyncEventStoreCommitNotifier%0A        extends AbstractEventStoreCommitNotifier %0A        implements EventStoreCommitNotifier %7B%0A%0A    @Resource%0A    private TimerService timerService;%0A%0A    @Override%0A    @Lock(LockType.READ)%0A    public void notifyListeners(ChangeSet changeSet) %7B%0A        scheduleListenerNotification(changeSet);%0A    %7D%0A    %0A    private void scheduleListenerNotification(ChangeSet changeSet) %7B%0A        /*%0A         * Persistent times are very expensive (requires a 2PC to the%0A         * timer storage), and we actually do not need them by the semantics%0A         * of notifyListeners()%0A         */%0A        timerService.createSingleActionTimer(0, new TimerConfig(changeSet, false));%0A    %7D%0A    %0A    /**%0A      * The timer will only fire if the transaction in which the timer was%0A      * created was committed successfully.%0A      * @param timer %0A      */%0A    @Timeout%0A    @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)%0A    public void notifyAppendListeners(Timer timer) %7B%0A        ChangeSet changeSet = (ChangeSet) timer.getInfo();%0A        this.performNotification(changeSet);%0A    %7D%0A    %0A%7D

Add an asynchronous EventStoreCommitNotifier.