Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright (c) 2011. Axon Framework
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   * http://www.apache.org/licenses/LICENSE-2.0
   *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 package org.axonframework.saga;
 
 
 import java.util.List;
 import java.util.Set;
Simple SagaManager implementation. This implementation requires the Event that should cause new Saga's to be created, to be registered using setEventsToAlwaysCreateNewSagasFor(java.util.List) and setEventsToOptionallyCreateNewSagasFor(java.util.List).

Author(s):
Allard Buijze
Since:
0.7
 
 public class SimpleSagaManager extends AbstractSagaManager {
 
 
     private List<Class<? extends Event>> eventsToAlwaysCreateNewSagasFor = Collections.emptyList();
     private List<Class<? extends Event>> eventsToOptionallyCreateNewSagasFor = Collections.emptyList();
     private Class<? extends SagasagaType;

    
Initialize a SimpleSagaManager backed by the given resources.

Parameters:
sagaType The type of Saga managed by this SagaManager
sagaRepository The repository providing access to Saga instances
associationValueResolver The instance providing AssociationValues for incoming Events
sagaFactory The factory creating new Saga instances
eventBus The event bus that the manager should register to
 
     public SimpleSagaManager(Class<? extends SagasagaTypeSagaRepository sagaRepository,
                              AssociationValueResolver associationValueResolver,
                              SagaFactory sagaFactoryEventBus eventBus) {
         super(eventBussagaRepositorysagaFactory);
         this. = sagaType;
         this. = associationValueResolver;
     }

    
Initialize a SimpleSagaManager backed by the given resources, using a GenericSagaFactory.

Parameters:
sagaType The type of Saga managed by this SagaManager
sagaRepository The repository providing access to Saga instances
associationValueResolver The instance providing AssociationValues for incoming Events
eventBus The event bus that the manager should register to
 
     public SimpleSagaManager(Class<? extends SagasagaTypeSagaRepository sagaRepository,
                              AssociationValueResolver associationValueResolver,
                              EventBus eventBus) {
         super(eventBussagaRepositorynew GenericSagaFactory());
         this. = sagaType;
         this. = associationValueResolver;
     }

    
Initialize the AnnotatedSagaManager using the given resources. Saga lookup and processing is done asynchronously using the given executor and transactionManager.

Parameters:
sagaType The type of Saga managed by this SagaManager
sagaRepository The repository providing access to the Saga instances
associationValueResolver The instance providing AssociationValues for incoming Events
sagaFactory The factory creating new instances of a Saga
eventBus The event bus publishing the events
executor The executor providing the threads to process events in
transactionManager The transaction manager that manages transactions around event processing
 
     public SimpleSagaManager(Class<? extends SagasagaTypeSagaRepository sagaRepository,
                              AssociationValueResolver associationValueResolverSagaFactory sagaFactory,
                              EventBus eventBusExecutor executorTransactionManager transactionManager) {
         super(eventBussagaRepositorysagaFactoryexecutortransactionManager);
         this. = sagaType;
         this. = associationValueResolver;
     }
 
     @Override
    protected Set<SagafindSagas(Event event) {
        Set<AssociationValueassociationValue = .extractAssociationValue(event);
        Set<Sagasagas = new HashSet<Saga>();
        sagas.addAll(getSagaRepository().find(associationValue));
        if (sagas.isEmpty() && isAssignableClassIn(event.getClass(), )
                || isAssignableClassIn(event.getClass(), )) {
            Saga saga = createSaga();
            sagas.add(saga);
            getSagaRepository().add(saga);
        }
        return sagas;
    }
    private boolean isAssignableClassIn(Class<? extends EventaClass,
                                        Collection<Class<? extends Event>> classCollection) {
        for (Class clazz : classCollection) {
            if (clazz.isAssignableFrom(aClass)) {
                return true;
            }
        }
        return false;
    }

    
Sets the types of Events that should cause the creation of a new Saga instance, even if one already exists.

Parameters:
events the types of Events that should cause the creation of a new Saga instance, even if one already exists
    public void setEventsToAlwaysCreateNewSagasFor(List<Class<? extends Event>> events) {
        this. = events;
    }

    
Sets the types of Events that should cause the creation of a new Saga instance if one does not already exist.

Parameters:
events the types of Events that should cause the creation of a new Saga instance if one does not already exist
    public void setEventsToOptionallyCreateNewSagasFor(List<Class<? extends Event>> events) {
        this. = events;
    }
New to GrepCode? Check out our FAQ X