Package com.codebullets.sagalib

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 = null;
        try {
            saga = providers.get(sagaToContinue).get();
            saga.setState(existingSate);
        } catch (Exception ex) {
            LOG.error("Unable to create new instance of saga type {}.", sagaToContinue, ex);
        }

        return saga;
View Full Code Here


    /**
     * 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 {
            Provider<? extends Saga> sagaProvider = providers.get(sagaToStart);
            createdSaga = sagaProvider.get();
            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

    /**
     * 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

            LOG.warn("No saga found to handle message. {}", invokeParam);
        } else {
            ExecutionContext context = contextProvider.get();

            for (SagaInstanceDescription sagaDescription : sagaDescriptions) {
                Saga saga = sagaDescription.getSaga();
                setSagaExecutionContext(saga, context);

                invoker.invoke(saga, invokeParam);
                updateStateStorage(sagaDescription);
View Full Code Here

    /**
     * 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

TOP

Related Classes of com.codebullets.sagalib.Saga

Copyright © 2018 www.massapicom. 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.