@Override public Method getMethod() { return context.getMethod(); }
/** * Determine request name for an invocation context. * * @param context the invocation context (not null) * @return the request name for this invocation */ protected String getRequestName(InvocationContext context) { final Method method = context.getMethod(); return method.getDeclaringClass().getSimpleName() + '.' + method.getName(); } }
@Override protected String getRequestName(InvocationContext context) { final Method method = context.getMethod(); final Object target = context.getTarget(); return target.getClass().getSimpleName() + '.' + method.getName(); } }
/** * Returns a key for a command. Keys are specific to the pair of instance (target) * and the method being called. * * @return A command key. */ private String createCommandKey() { return method.getName() + Objects.hash(context.getTarget(), context.getMethod().hashCode()); } }
@AroundInvoke private Object aroundMethod(InvocationContext context) throws Exception { return called(context, context.getMethod()); }
@AroundInvoke public Object validateMethodInvocation(InvocationContext ctx) throws Exception { final boolean isJaxRsMethod = extension.jaxRsResourceCache.apply(ctx.getMethod().getDeclaringClass()); return isJaxRsMethod ? ctx.proceed() : interceptor.validateMethodInvocation(ctx); }
private Object doMethodInterception(InvocationContext invocationContext, InterceptionType interceptionType, InterceptorInstances interceptorInstances, InterceptorBindings interceptorBindings) throws Exception { if (interceptorBindings != null) { List<Interceptor<?>> currentInterceptors = interceptorBindings.getMethodInterceptors(interceptionType, invocationContext.getMethod()); return delegateInterception(invocationContext, interceptionType, currentInterceptors, interceptorInstances); } else { return invocationContext.proceed(); } }
/** * Intercepts a call to bean method annotated by any of the fault tolerance * annotations. * * @param context Invocation context. * @return Whatever the intercepted method returns. * @throws Throwable If a problem occurs. */ @AroundInvoke public Object interceptCommand(InvocationContext context) throws Throwable { try { LOGGER.fine("Interceptor called for '" + context.getTarget().getClass() + "::" + context.getMethod().getName() + "'"); // Create method introspector and executer retrier final MethodIntrospector introspector = new MethodIntrospector( context.getTarget().getClass(), context.getMethod()); final CommandRetrier retrier = new CommandRetrier(context, introspector); return retrier.execute(); } catch (Throwable t) { LOGGER.fine("Throwable caught by interceptor '" + t.getMessage() + "'"); throw t; } } }
/** * Constructor. * * @param context Invocation context. * @param introspector Method introspector. * @param throwable Throwable that resulted in this fallback being called. */ CommandFallback(InvocationContext context, MethodIntrospector introspector, Throwable throwable) { this.context = context; this.throwable = throwable; // Establish fallback strategy final Fallback fallback = introspector.getFallback(); if (fallback.value() != Fallback.DEFAULT.class) { handlerClass = fallback.value(); } else if (!fallback.fallbackMethod().isEmpty()) { Object instance = context.getTarget(); try { fallbackMethod = instance.getClass().getMethod(introspector.getFallback().fallbackMethod(), context.getMethod().getParameterTypes()); } catch (NoSuchMethodException e) { throw new InternalError(e); // should have been validated } } else { handlerClass = Fallback.DEFAULT.class; } }
/** * Updates fallback metrics and adjust failed invocations based on outcome of fallback. */ private void updateMetrics(Throwable throwable) { final Method method = context.getMethod(); FaultToleranceMetrics.getCounter(method, FaultToleranceMetrics.FALLBACK_CALLS_TOTAL).inc(); // If fallback was successful, it is not a failed invocation if (throwable == null) { FaultToleranceMetrics.getCounter(method, FaultToleranceMetrics.INVOCATIONS_FAILED_TOTAL).dec(); } } }
SingletonComponent lockableComponent = this.getLockableComponent(); Method method = invocationContext.getMethod(); if (method == null) { throw EjbLogger.ROOT_LOGGER.invocationNotApplicableForMethodInvocation(invocationContext);
@AroundConstruct public Object onConstruct(InvocationContext context) throws Exception { // null before the InvocationContext.proceed() returns Object target = context.getTarget(); isNull(target); // null in case of AroundConstruct Method method = context.getMethod(); isNull(method); // NOT null in case of AroundConstruct Constructor ctor = context.getConstructor(); isNotNull(ctor); // perform the constructor injection Object result = context.proceed(); isNull(result); // NOT null after the InvocationContext.proceed() completes target = context.getTarget(); isNotNull(target); // a constructor should have been called GreetingBean bean = (GreetingBean) target; isBoolean(bean.isConstructed(), true); isBoolean(bean.isInitialized(), false); // constructor injection should have been done isNotNull(bean.getParam()); return null; }
@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()); } }
@AroundInvoke public Object invoke(InvocationContext ctx) throws Exception { try { Object result = ctx.proceed(); StartProcess startProcessAnnotation = ctx.getMethod().getAnnotation(StartProcess.class); String key = startProcessAnnotation.value(); Map<String, Object> variables = extractVariables(startProcessAnnotation, ctx); businessProcess.startProcessByKey(key, variables); return result; } catch (InvocationTargetException e) { Throwable cause = e.getCause(); if(cause != null && cause instanceof Exception) { throw (Exception) cause; } else { throw e; } } catch (Exception e) { throw new ProcessEngineException("Error while starting process using @StartProcess on method '"+ctx.getMethod()+"': " + e.getMessage(), e); } }
private Map<String, Object> extractVariables(StartProcess startProcessAnnotation, InvocationContext ctx) throws Exception { VariableMap variables = new VariableMapImpl(); for (Field field : ctx.getMethod().getDeclaringClass().getDeclaredFields()) { if (!field.isAnnotationPresent(ProcessVariable.class) && !field.isAnnotationPresent(ProcessVariableTyped.class)) { continue; } field.setAccessible(true); String fieldName = null; ProcessVariable processStartVariable = field.getAnnotation(ProcessVariable.class); if (processStartVariable != null) { fieldName = processStartVariable.value(); } else { ProcessVariableTyped processStartVariableTyped = field.getAnnotation(ProcessVariableTyped.class); fieldName = processStartVariableTyped.value(); } if (fieldName == null || fieldName.length() == 0) { fieldName = field.getName(); } Object value = field.get(ctx.getTarget()); variables.put(fieldName, value); } return variables; }
this.introspector = introspector; this.isAsynchronous = introspector.isAsynchronous(); this.method = context.getMethod();
Set<ConstraintViolation<Object>> violations = executableValidator.validateParameters( ctx.getTarget(), ctx.getMethod(), ctx.getParameters() ); getMessage( ctx.getMethod(), ctx.getParameters(), violations ), violations ); ctx.getMethod(), result ); getMessage( ctx.getMethod(), ctx.getParameters(), violations ), violations );
@AroundInvoke public Object profile(InvocationContext ic) throws Exception { long initTime = System.currentTimeMillis(); try { return ic.proceed(); } finally { long diffTime = System.currentTimeMillis() - initTime; logger.severe("###" + ic.getMethod() + " took " + diffTime + " millis"); logger.fine(ic.getMethod() + " took " + diffTime + " millis"); } } }
@AroundInvoke public Object logMethod(InvocationContext ic) throws Exception { logger.entering(ic.getTarget().toString(), ic.getMethod().getName()); logger.severe("I2>>>" + ic.getTarget().toString() + " - " + ic.getMethod().getName()); try { return ic.proceed(); } finally { logger.severe("I2<<<" + ic.getTarget().toString() + " - " + ic.getMethod().getName()); logger.exiting(ic.getTarget().toString(), ic.getMethod().getName()); } } }
@AroundInvoke public Object logMethod(InvocationContext ic) throws Exception { logger.entering(ic.getTarget().toString(), ic.getMethod().getName()); logger.severe(">>>" + ic.getTarget().toString() + " - " + ic.getMethod().getName()); try { return ic.proceed(); } finally { logger.severe("<<<" + ic.getTarget().toString() + " - " + ic.getMethod().getName()); logger.exiting(ic.getTarget().toString(), ic.getMethod().getName()); } } }