001package io.avaje.inject.aop; 002 003import java.lang.reflect.Method; 004 005/** 006 * A fallback or recovery method used with Aspects. 007 * <p> 008 * This isn't strictly required but more a helper to make it easier for aspects 009 * that want to use a fallback or recovery method. 010 */ 011@FunctionalInterface 012public interface Fallback { 013 014 /** 015 * Find and return the fallback given the name and original method. 016 * <p> 017 * This will first try and find the method for the name that has the same parameters as 018 * the method but additionally takes a {@code Throwable} as the last parameter. If no 019 * matching method is found it then looks for the method with the name that just has the 020 * matching parameters (and not the additional throwable). 021 * 022 * @param name The name of the fallback method 023 * @param method The original method which we match to using argument types. 024 * @return The fallback 025 * @throws NoSuchMethodException When no matching fallback method is found 026 */ 027 static Fallback find(String name, Method method) throws NoSuchMethodException { 028 return FallbackFinder.find(name, method); 029 } 030 031 /** 032 * Invoke the fallback method given the invocation and exception. 033 * 034 * @param call The invocation being executed 035 * @param sourceException The exception thrown that triggers the use of the fallback method 036 */ 037 Object invoke(Invocation call, Throwable sourceException); 038}