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;
Utility class that invokes annotated Event Handlers on Sagas.

Author(s):
Allard Buijze
Since:
0.7
Initialize a handler invoker for the given target object that has handler method annotated with given annotationType.

Parameters:
target The target to invoke methods on
    public SagaEventHandlerInvoker(Object target) {
        super(targetSagaEventHandler.class);
    }

    
Indicates whether the handler of the target event indicates an ending event handler (i.e. is annotated with EndSaga).

Parameters:
event The event to investigate the handler for
Returns:
true if handling the given event should end the lifecycle of the Saga, false otherwise.
    public boolean isEndingEvent(Object event) {
        Handler handler = super.findHandlerMethod(event.getClass());
        return handler != null && handler.getMethod().isAnnotationPresent(EndSaga.class);
    }

    
Invoke the annotated Event Handler method for the given event on the target Saga.

Parameters:
event The event to invoke the Event Handler for
    public void invokeSagaEventHandlerMethod(Event event) {
        try {
            invokeHandlerMethod(event);
        } catch (IllegalAccessException e) {
            throw new UnsupportedOperationException(String.format(
                    "An error occurred when handling an event of type [%s]",
                    event.getClass().getSimpleName()), e);
        } catch (InvocationTargetException e) {
            if (e.getCause() instanceof RuntimeException) {
                throw (RuntimeExceptione.getCause();
            }
            throw new EventHandlerInvocationException(String.format(
                    "An error occurred when handling an event of type [%s]",
                    event.getClass().getSimpleName()), e);
        }
    }
New to GrepCode? Check out our FAQ X