Search in sources :

Example 21 with AroundInvoke

use of javax.interceptor.AroundInvoke in project Payara by payara.

the class CachePutInterceptor method cachePut.

@AroundInvoke
public Object cachePut(InvocationContext ctx) throws Throwable {
    if (!isEnabled()) {
        return ctx.proceed();
    }
    CachePut annotation = ctx.getMethod().getAnnotation(CachePut.class);
    PayaraCacheKeyInvocationContext<CachePut> pctx = new PayaraCacheKeyInvocationContext<>(ctx, annotation);
    if (!annotation.afterInvocation()) {
        doPut(pctx);
    }
    Object result = null;
    try {
        result = ctx.proceed();
    } catch (Throwable e) {
        if (annotation.afterInvocation()) {
            if (shouldICache(annotation.cacheFor(), annotation.noCacheFor(), e, false)) {
                doPut(pctx);
            }
        }
        throw e;
    }
    if (annotation.afterInvocation()) {
        doPut(pctx);
    }
    return result;
}
Also used : CachePut(javax.cache.annotation.CachePut) PayaraCacheKeyInvocationContext(fish.payara.cdi.jsr107.implementation.PayaraCacheKeyInvocationContext) AroundInvoke(javax.interceptor.AroundInvoke)

Example 22 with AroundInvoke

use of javax.interceptor.AroundInvoke in project Payara by payara.

the class CacheRemoveInterceptor method cacheRemove.

@AroundInvoke
public Object cacheRemove(InvocationContext ctx) throws Throwable {
    if (!isEnabled()) {
        return ctx.proceed();
    }
    CacheRemove annotation = ctx.getMethod().getAnnotation(CacheRemove.class);
    PayaraCacheKeyInvocationContext<CacheRemove> pctx = new PayaraCacheKeyInvocationContext<>(ctx, annotation);
    if (!annotation.afterInvocation()) {
        doRemove(pctx);
    }
    Object result = null;
    try {
        result = ctx.proceed();
    } catch (Throwable e) {
        if (annotation.afterInvocation()) {
            if (shouldIEvict(annotation.evictFor(), annotation.noEvictFor(), e)) {
                doRemove(pctx);
            }
        }
        throw e;
    }
    if (annotation.afterInvocation()) {
        doRemove(pctx);
    }
    return result;
}
Also used : CacheRemove(javax.cache.annotation.CacheRemove) PayaraCacheKeyInvocationContext(fish.payara.cdi.jsr107.implementation.PayaraCacheKeyInvocationContext) AroundInvoke(javax.interceptor.AroundInvoke)

Example 23 with AroundInvoke

use of javax.interceptor.AroundInvoke in project iobserve-analysis by research-iobserve.

the class TraceInterceptor method interceptMethodCall.

/**
 * Around advice configuration.
 *
 * @param context
 *            the invocation context of a bean call.
 * @return the return value of the next method in the chain
 * @throws Throwable
 */
@AroundInvoke
public Object interceptMethodCall(final InvocationContext context) throws Throwable {
    // (IllegalThrowsCheck)
    if (this.monitoringCtrl.isMonitoringEnabled()) {
        final String signature = context.getMethod().toString();
        if (this.monitoringCtrl.isProbeActivated(signature)) {
            // common fields
            TraceMetadata trace = TraceInterceptor.TRACEREGISTRY.getTrace();
            final boolean newTrace = trace == null;
            if (newTrace) {
                trace = TraceInterceptor.TRACEREGISTRY.registerTrace();
                this.monitoringCtrl.newMonitoringRecord(trace);
            }
            final long traceId = trace.getTraceId();
            final String clazz = context.getTarget().getClass().getCanonicalName();
            // measure before execution
            this.monitoringCtrl.newMonitoringRecord(new BeforeOperationEvent(this.timeSource.getTime(), traceId, trace.getNextOrderId(), signature, clazz));
            // execution of the called method
            try {
                final Object retval = context.proceed();
                // measure after successful execution
                this.monitoringCtrl.newMonitoringRecord(new AfterOperationEvent(this.timeSource.getTime(), traceId, trace.getNextOrderId(), signature, clazz));
                return retval;
            } catch (final Throwable th) {
                // NOPMD NOCS (catch throw might
                // ok here)
                // measure after failed execution
                this.monitoringCtrl.newMonitoringRecord(new AfterOperationFailedEvent(this.timeSource.getTime(), traceId, trace.getNextOrderId(), signature, clazz, th.toString()));
                throw th;
            } finally {
                if (newTrace) {
                    // close the trace
                    TraceInterceptor.TRACEREGISTRY.unregisterTrace();
                }
            }
        } else {
            return context.proceed();
        }
    } else {
        return context.proceed();
    }
}
Also used : AfterOperationFailedEvent(kieker.common.record.flow.trace.operation.AfterOperationFailedEvent) AfterOperationEvent(kieker.common.record.flow.trace.operation.AfterOperationEvent) TraceMetadata(kieker.common.record.flow.trace.TraceMetadata) BeforeOperationEvent(kieker.common.record.flow.trace.operation.BeforeOperationEvent) AroundInvoke(javax.interceptor.AroundInvoke)

Example 24 with AroundInvoke

use of javax.interceptor.AroundInvoke in project camunda-bpm-platform by camunda.

the class CompleteTaskInterceptor method invoke.

@AroundInvoke
public Object invoke(InvocationContext ctx) throws Exception {
    try {
        Object result = ctx.proceed();
        CompleteTask completeTaskAnnotation = ctx.getMethod().getAnnotation(CompleteTask.class);
        boolean endConversation = completeTaskAnnotation.endConversation();
        businessProcess.completeTask(endConversation);
        return result;
    } catch (InvocationTargetException e) {
        throw new ProcessEngineCdiException("Error while completing task: " + e.getCause().getMessage(), e.getCause());
    }
}
Also used : ProcessEngineCdiException(org.camunda.bpm.engine.cdi.ProcessEngineCdiException) CompleteTask(org.camunda.bpm.engine.cdi.annotation.CompleteTask) InvocationTargetException(java.lang.reflect.InvocationTargetException) AroundInvoke(javax.interceptor.AroundInvoke)

Example 25 with AroundInvoke

use of javax.interceptor.AroundInvoke in project javaee7-samples by javaee-samples.

the class ReceptionSynchronizer method invoke.

@AroundInvoke
public Object invoke(final InvocationContext ctx) throws Exception {
    boolean transactional = false;
    try {
        System.out.println("Intercepting " + ctx.getMethod().toGenericString());
        transactional = txRegistry != null && txRegistry.getTransactionStatus() != Status.STATUS_NO_TRANSACTION;
        if (transactional) {
            txRegistry.registerInterposedSynchronization(new Synchronization() {

                @Override
                public void beforeCompletion() {
                }

                @Override
                public void afterCompletion(int i) {
                    registerInvocation(ctx.getMethod());
                }
            });
        }
        return ctx.proceed();
    } finally {
        if (!transactional) {
            registerInvocation(ctx.getMethod());
        }
    }
}
Also used : Synchronization(javax.transaction.Synchronization) AroundInvoke(javax.interceptor.AroundInvoke)

Aggregations

AroundInvoke (javax.interceptor.AroundInvoke)52 Method (java.lang.reflect.Method)10 InvocationManager (org.glassfish.api.invocation.InvocationManager)6 FaultToleranceService (fish.payara.microprofile.faulttolerance.FaultToleranceService)5 FallbackPolicy (fish.payara.microprofile.faulttolerance.interceptors.fallback.FallbackPolicy)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 TransactionalException (javax.transaction.TransactionalException)5 Config (org.eclipse.microprofile.config.Config)5 Fallback (org.eclipse.microprofile.faulttolerance.Fallback)5 PayaraCacheKeyInvocationContext (fish.payara.cdi.jsr107.implementation.PayaraCacheKeyInvocationContext)4 Meter (com.codahale.metrics.Meter)2 Timer (com.codahale.metrics.Timer)2 TransactionManagerHelper (com.sun.enterprise.transaction.TransactionManagerHelper)2 CallerAccessException (fish.payara.cdi.auth.roles.CallerAccessException)2 RolesPermitted (fish.payara.cdi.auth.roles.RolesPermitted)2 Parameter (java.lang.reflect.Parameter)2 Principal (java.security.Principal)2 ArrayList (java.util.ArrayList)2 NoSuchElementException (java.util.NoSuchElementException)2 Message (javax.jms.Message)2