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;
}
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;
}
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();
}
}
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());
}
}
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());
}
}
}
Aggregations