All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.smallrye.faulttolerance.internal.InterceptionInvoker Maven / Gradle / Ivy

There is a newer version: 6.6.2
Show newest version
package io.smallrye.faulttolerance.internal;

import java.util.function.Function;

import javax.interceptor.InvocationContext;

import io.smallrye.faulttolerance.core.invocation.Invoker;

public class InterceptionInvoker implements Invoker {
    private final InvocationContext interceptionContext;

    public InterceptionInvoker(InvocationContext interceptionContext) {
        this.interceptionContext = interceptionContext;
    }

    @Override
    public int parametersCount() {
        return interceptionContext.getParameters().length;
    }

    @Override
    public  T getArgument(int index, Class parameterType) {
        return parameterType.cast(interceptionContext.getParameters()[index]);
    }

    @Override
    public  T replaceArgument(int index, Class parameterType, Function transformation) {
        Object[] arguments = interceptionContext.getParameters();
        T oldArg = parameterType.cast(arguments[index]);
        T newArg = transformation.apply(oldArg);
        arguments[index] = newArg;
        interceptionContext.setParameters(arguments);
        return oldArg;
    }

    @Override
    public V proceed() throws Exception {
        return (V) interceptionContext.proceed();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy