Examples of Saga


Examples of com.codebullets.sagalib.Saga

        return sagas;
    }

    private Saga createSagaBasedOnId(final String sagaId) {
        Saga sagaToContinue = null;

        // saga id is know -> we can create saga directly from know state.
        SagaState state = stateStorage.load(sagaId);
        if (state != null) {
            sagaToContinue = continueSaga(state.getType(), state);
View Full Code Here

Examples of com.codebullets.sagalib.Saga

    private Collection<Saga> continueSagas(final SagaType sagaType) {
        Collection<Saga> sagas = new ArrayList<>();

        Collection<? extends SagaState> sagaStates = stateStorage.load(sagaType.getSagaClass().getName(), sagaType.getInstanceKey());
        for (SagaState sagaState : sagaStates) {
            Saga saga = continueSaga(sagaType.getSagaClass(), sagaState);
            if (saga != null) {
                sagas.add(saga);
            }
        }
View Full Code Here

Examples of com.codebullets.sagalib.Saga

    /**
     * Creates a new saga instance and attaches the existing saga state.
     */
    private Saga continueSaga(final Class<? extends Saga> sagaToContinue, final SagaState existingSate) {
        Saga saga;

        try {
            saga = createNewSagaInstance(sagaToContinue);
            saga.setState(existingSate);
        } catch (Exception ex) {
            saga = null;
            LOG.error("Unable to create new instance of saga type {}.", sagaToContinue, ex);
        }

View Full Code Here

Examples of com.codebullets.sagalib.Saga

    /**
     * Create a new saga instance based on fully qualified name and the existing saga state.
     */
    private Saga continueSaga(final String sagaToContinue, final SagaState existingState) {
        Saga saga = null;

        try {
            Class clazz = Class.forName(sagaToContinue);
            saga = continueSaga(clazz, existingState);
        } catch (Exception ex) {
View Full Code Here

Examples of com.codebullets.sagalib.Saga

    /**
     * Starts a new saga by creating an instance and attaching a new saga state.
     */
    private Saga startNewSaga(final Class<? extends Saga> sagaToStart) {
        Saga createdSaga = null;

        try {
            createdSaga = createNewSagaInstance(sagaToStart);
            createdSaga.createNewState();

            SagaState newState = createdSaga.state();
            newState.setSagaId(UUID.randomUUID().toString());
            newState.setType(sagaToStart.getName());
        } catch (Exception ex) {
            LOG.error("Unable to create new instance of saga type {}.", sagaToStart, ex);
        }
View Full Code Here

Examples of com.codebullets.sagalib.Saga

     * Creates a new saga instances with the requested type.
     * @throws Exception Forwards possible exceptions from the provider get method.
     */
    private Saga createNewSagaInstance(final Class<? extends Saga> sagaType) throws Exception {
        Provider<? extends Saga> sagaProvider = providers.get(sagaType);
        Saga createdSaga = sagaProvider.get();
        if (createdSaga instanceof NeedTimeouts) {
            ((NeedTimeouts) createdSaga).setTimeoutManager(timeoutManager);
        }

        return createdSaga;
View Full Code Here

Examples of com.codebullets.sagalib.Saga

    /**
     * Search for a reader based on saga type.
     */
    private Collection<KeyReader> findReader(final Class<? extends Saga> sagaClazz, final Class<?> messageClazz) {
        Saga saga = sagaProviderFactory.createProvider(sagaClazz).get();
        Collection<KeyReader> readers = saga.keyReaders();
        if (readers == null) {
            // return empty list in case saga returns null for any reason
            readers = new ArrayList<>();
        }

View Full Code Here

Examples of com.codebullets.sagalib.Saga

    /**
     * Updates the state storage depending on whether the saga is completed or keeps on running.
     */
    private void updateStateStorage(final SagaInstanceDescription description) {
        Saga saga = description.getSaga();

        // if saga has finished delete existing state and possible timeouts
        // if saga has just been created state has never been save and there
        // is no need to delete it.
        if (saga.isFinished() && !description.isStarting()) {
            storage.delete(saga.state().getSagaId());
            timeoutManager.cancelTimeouts(saga.state().getSagaId());
        } else if (!saga.isFinished()) {
            storage.save(saga.state());
        }
    }
View Full Code Here

Examples of com.codebullets.sagalib.Saga

        if (message instanceof Timeout) {
            // timeout is special. Has only one specific saga state and
            // saga id is already known
            Timeout timeout = (Timeout) message;
            Saga saga = createSagaForTimeoutHandling(timeout);
            if (saga != null) {
                sagaInstances.add(SagaInstanceDescription.define(saga, false));
            }
        } else {
            // create and start a new saga if message has been flagged as such
            Collection<Class<? extends Saga>> startingSagaTypes = messagesStartingSagas.get(message.getClass());
            for (Class<? extends Saga> sagaType : startingSagaTypes) {
                Saga newSaga = startNewSaga(sagaType);
                sagaInstances.add(SagaInstanceDescription.define(newSaga, true));
            }

            // Search for existing saga states and attach them to created instances.
            Collection <Class<? extends Saga>> existingSagaTypes = messagesToContinueSaga.get(message.getClass());
View Full Code Here

Examples of com.codebullets.sagalib.Saga

    /**
     * Search for saga state based on id directly and create instance with attached state.
     */
    private Saga createSagaForTimeoutHandling(final Timeout timeout) {
        Saga saga = null;

        // timeout does not need key extraction
        SagaState state = stateStorage.load(timeout.getSagaId());
        if (state != null) {
            saga = continueSaga(state.getType(), state);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.