Package com.codebullets.sagalib

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(saga);
            }
        } else {
            // create and start a new saga if message has been flagged as such
View Full Code Here


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

        String key = keyExtractor.findSagaInstanceKey(sagaToContinue, message);
        if (key != null) {
            Collection<? extends SagaState> sagaStates = stateStorage.load(sagaToContinue.getName(), key);
            for (SagaState sagaState : sagaStates) {
                Saga saga = continueSaga(sagaToContinue, sagaState);
                if (saga != null) {
                    sagas.add(saga);
                }
            }
        } else {
View Full Code Here

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

View Full Code Here

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

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

    }

    private void invokeSagas(final CurrentExecutionContext context, final Iterable<SagaInstanceDescription> sagaDescriptions, final Object invokeParam)
            throws InvocationTargetException, IllegalAccessException {
        for (SagaInstanceDescription sagaDescription : sagaDescriptions) {
            Saga saga = sagaDescription.getSaga();
            context.setSaga(saga);
            setSagaExecutionContext(saga, context);

            interceptorStart(sagaDescription, context, invokeParam);
            invoker.invoke(saga, invokeParam);
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()) {
            env.storage().delete(saga.state().getSagaId());
            env.timeoutManager().cancelTimeouts(saga.state().getSagaId());
        } else if (!saga.isFinished()) {
            env.storage().save(saga.state());
        }
    }
View Full Code Here

    public Collection<SagaInstanceDescription> create(final Object message) {
        Collection<SagaInstanceDescription> sagaInstances = new ArrayList<>();

        for (SagaType sagaType : organizer.sagaTypesForMessage(message)) {
            if (sagaType.isStartingNewSaga()) {
                Saga newSaga = startNewSaga(sagaType.getSagaClass());
                sagaInstances.add(SagaInstanceDescription.define(newSaga, true));
            } else {
                Collection<Saga> sagas = continueExistingSaga(sagaType);
                for (Saga saga : sagas) {
                    sagaInstances.add(SagaInstanceDescription.define(saga, false));
View Full Code Here

        Collection<Saga> sagas = new ArrayList<>();

        String sagaId = sagaType.getSagaId();
        if (sagaId != null) {
            // saga id is known -> we can create saga directly from know state.
            Saga saga = createSagaBasedOnId(sagaId);
            sagas.add(saga);
        } else {
            // no saga id available, search for existing state based on instance key.
            Collection<Saga> existingSagas = continueSagas(sagaType);
            sagas.addAll(existingSagas);
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.