Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright (c) 2010-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.annotation;
 
 
 import java.util.UUID;

Implementation of the interface that delegates incoming events to SagaEventHandler annotated methods.

Author(s):
Allard Buijze
Since:
0.7
 
 public abstract class AbstractAnnotatedSaga implements SagaSerializable {
 
     private static final long serialVersionUID = 2385024168304711298L;
 
     private final AssociationValues associationValues;
     private final String identifier;
     private transient volatile SagaEventHandlerInvoker eventHandlerInvoker;
     private volatile boolean isActive = true;

    
Initialize the saga with a random identifier. The identifier used is a randomly generated java.util.UUID.
 
     protected AbstractAnnotatedSaga() {
         this(UUID.randomUUID().toString());
     }

    
Initialize the saga with the given identifier.

Parameters:
identifier the identifier to initialize the saga with.
 
     protected AbstractAnnotatedSaga(String identifier) {
         this. = identifier;
          = new AssociationValuesImpl();
         .add(new AssociationValue("sagaIdentifier"identifier));
          = new SagaEventHandlerInvoker(this);
     }
 
     @Override
     public String getSagaIdentifier() {
         return ;
     }
 
     @Override
         return ;
     }
 
     @Override
     public final void handle(Event event) {
         if ( == null) {
              = new SagaEventHandlerInvoker(this);
         }
         doHandle(event);
     }
 
     private void doHandle(Event event) {
         if () {
             .invokeSagaEventHandlerMethod(event);
             if (.isEndingEvent(event)) {
                 end();
             }
         }
     }
 
     @Override
     public boolean isActive() {
         return ;
     }

    
Marks the saga as ended. Ended saga's may be cleaned up by the repository when they are committed.
 
     protected void end() {
          = false;
     }

    
Registers a AssociationValue with the given saga. When the saga is committed, it can be found using the registered property.

Parameters:
property The value to associate this saga with.
    protected void associateWith(AssociationValue property) {
        .add(property);
    }

    
Registers a AssociationValue with the given saga. When the saga is committed, it can be found using the registered property.

Parameters:
key The key of the association value to associate this saga with.
value The value of the association value to associate this saga with.
    protected void associateWith(String keyObject value) {
        .add(new AssociationValue(keyvalue));
    }

    
Removes the given association from this Saga. When the saga is committed, it can no longer be found using the given association. If the given property wasn't registered with the saga, nothing happens.

Parameters:
property the association value to remove from the saga.
    protected void removeAssociationWith(AssociationValue property) {
        .remove(property);
    }

    
Removes the given association from this Saga. When the saga is committed, it can no longer be found using the given association value. If the given saga wasn't associated with given values, nothing happens.

Parameters:
key The key of the association value to remove from this saga.
value The value of the association value to remove from this saga.
    protected void removeAssociationWith(String keyObject value) {
        .remove(new AssociationValue(keyvalue));
    }
New to GrepCode? Check out our FAQ X