package org.jeecqrs.startup;

import javax.annotation.PostConstruct;

/**
 * Orchestrates the initialization of the various infrastructure services.
 * Deploy as @Startup @Singleton EJB.
 */
public abstract class AbstractApplicationStartup {

    @PostConstruct
    public void startup() {
        wireUpEventListeners();
        wireUpCommandHandlers();
        wireUpDispatchScheduler();
        wireUpSagaTracker();
        replayEvents();
        startDispatchScheduler();
        startSagaTracker();
    }

    /**
     * Registers event handlers at the {@link EventDispatcher}.
     */
    protected abstract void wireUpEventListeners();

    /**
     * Registers command handlers at the {@link CommandBus}.
     */
    protected abstract void wireUpCommandHandlers();

    /**
     * Sets up the bridge between the {@link EventDispatcher} and the
     * persistence layer, such that newly persisted events are published
     * to the dispatcher.
     * Implementations might use polling or use an asynchronous listener
     * if the persistence implementations supports this.
     */
    protected abstract void wireUpDispatchScheduler();

    /**
     * Sets up the {@link SagaTracker} to handle timed events in sagas.
     */
    protected abstract void wireUpSagaTracker();

    /**
     * Replay persisted events on application startup.
     * Implementations should be aware of long transactions and timeouts.
     */
    protected abstract void replayEvents();

    /**
     * Starts the {@link DispatchScheduler}, if required (asynchronous
     * implementations may not need this).
     */
    protected abstract void startDispatchScheduler();

    /**
     * Starts the {@link SagaTracker}, if required (asynchronous
     * implementations may not need this).
     */
    protected abstract void startSagaTracker();

}

@@ -180,16 +180,209 @@
 on EJB.%0A
+ * %3Cp%3E%0A * Contrary to the other services, the interface of %7B@link AbstractApplicationStartup%7D%0A * does not contain the notion of a %22bucket%22, since it is meant as a per-module%0A * initialization.%0A
  */%0Apubl
@@ -1102,16 +1102,36 @@
 ents are
+ continuously%0A     *
  publish
@@ -1132,23 +1132,16 @@
 ublished
-%0A     *
  to the 
@@ -1163,83 +1163,233 @@
   * 
-Implementations might use polling or use an asynchronous listener%0A     * if
+The preferred way is to hook into the event persistence receive%0A     * notifications about persisted events asynchronously once the events%0A     * have been persisted to the durable storage. %0A     * If this is not supported by
  the
@@ -1400,16 +1400,28 @@
 sistence
+ technology,
  impleme
@@ -1432,21 +1432,137 @@
 ions
- supports thi
+%0A     * may also use other techniques, such as polling in fixed intervals to%0A     * query a database for recently published event
 s.%0A 

Improve Javadoc of AbstractApplicationStartup