@Override public void addTransactionCommitAdvice(MethodAdviceReceiver receiver) { for (Method m : receiver.getInterface().getMethods()) { if (m.getAnnotation(CommitAfter.class) != null) { receiver.adviseMethod(m, advice); } } } }
private static void advise(Class<? extends Annotation> annotationClass, ObjectLocator objectLocator, Class<? extends CacheMethodAdvice> adviceClass, MethodAdviceReceiver methodAdviceReceiver) { // TAP5-2466: create the advice on-demand to avoid recursion issues MethodAdvice advice = null; if (methodAdviceReceiver.getClassAnnotationProvider().getAnnotation(annotationClass) != null) { advice = build(objectLocator, adviceClass); methodAdviceReceiver.adviseAllMethods(advice); } else { for (Method method : methodAdviceReceiver.getInterface().getMethods()) { if (methodAdviceReceiver.getMethodAnnotation(method, annotationClass) != null) { if(advice== null) { advice = build(objectLocator, adviceClass); } methodAdviceReceiver.adviseMethod(method, advice); } } } }
@Override public void addTransactionCommitAdvice(MethodAdviceReceiver receiver) { for (final Method m : receiver.getInterface().getMethods()) { if (m.getAnnotation(CommitAfter.class) != null) { PersistenceContext annotation = receiver.getMethodAnnotation(m, PersistenceContext.class); receiver.adviseMethod(m, methodAdvices.get(annotation == null ? null : annotation.unitName())); } } }
private void addAdvice(Method method, MethodAdviceReceiver receiver) { final Class thunkType = method.getReturnType(); final String description = String.format("<%s Thunk for %s>", thunkType.getName(), InternalUtils.asString(method)); MethodAdvice advice = new MethodAdvice() { /** * When the method is invoked, we don't immediately proceed. Instead, we return a thunk instance * that defers its behavior to the lazily invoked invocation. */ @Override public void advise(final MethodInvocation invocation) { ObjectCreator deferred = new ObjectCreator() { @Override public Object createObject() { invocation.proceed(); return invocation.getReturnValue(); } }; ObjectCreator cachingObjectCreator = new CachingObjectCreator(deferred); Object thunk = thunkCreator.createThunk(thunkType, cachingObjectCreator, description); invocation.setReturnValue(thunk); } }; receiver.adviseMethod(method, advice); }
@Override public void addLoggingAdvice(Logger logger, MethodAdviceReceiver receiver) { MethodAdvice advice = new LoggingAdvice(logger, exceptionTracker); receiver.adviseAllMethods(advice); } }
@Override public void addLazyMethodInvocationAdvice(MethodAdviceReceiver methodAdviceReceiver) { for (Method m : methodAdviceReceiver.getInterface().getMethods()) { if (filter(m)) addAdvice(m, methodAdviceReceiver); } }
@Override public void addOperationAdvice(MethodAdviceReceiver receiver) { for (Method m : receiver.getInterface().getMethods()) { Operation annotation = receiver.getMethodAnnotation(m, Operation.class); if (annotation != null) { String value = annotation.value(); receiver.adviseMethod(m, createAdvice(value)); } } }
private void addAdvice(Method method, MethodAdviceReceiver receiver) { final Class thunkType = method.getReturnType(); final String description = String.format("<%s Thunk for %s>", thunkType.getName(), InternalUtils.asString(method)); MethodAdvice advice = new MethodAdvice() { /** * When the method is invoked, we don't immediately proceed. Instead, we return a thunk instance * that defers its behavior to the lazily invoked invocation. */ @Override public void advise(final MethodInvocation invocation) { ObjectCreator deferred = new ObjectCreator() { @Override public Object createObject() { invocation.proceed(); return invocation.getReturnValue(); } }; ObjectCreator cachingObjectCreator = new CachingObjectCreator(deferred); Object thunk = thunkCreator.createThunk(thunkType, cachingObjectCreator, description); invocation.setReturnValue(thunk); } }; receiver.adviseMethod(method, advice); }
@Override public void addTransactionCommitAdvice(final MethodAdviceReceiver receiver) { receiver.adviseAllMethods(new CommitAfterMethodAdvice(manager)); }
@Override public void addLazyMethodInvocationAdvice(MethodAdviceReceiver methodAdviceReceiver) { for (Method m : methodAdviceReceiver.getInterface().getMethods()) { if (filter(m)) addAdvice(m, methodAdviceReceiver); } }
@Override public void addTransactionCommitAdvice(MethodAdviceReceiver receiver) { for (Method m : receiver.getInterface().getMethods()) { if (m.getAnnotation(CommitAfter.class) != null) { receiver.adviseMethod(m, advice); } } } }
@Override public void addOperationAdvice(MethodAdviceReceiver receiver) { for (Method m : receiver.getInterface().getMethods()) { Operation annotation = receiver.getMethodAnnotation(m, Operation.class); if (annotation != null) { String value = annotation.value(); receiver.adviseMethod(m, createAdvice(value)); } } }
@Advise(serviceInterface = ComponentInstantiatorSource.class) public static void componentReplacer(MethodAdviceReceiver methodAdviceReceiver, final ComponentOverride componentReplacer) throws NoSuchMethodException, SecurityException { if (componentReplacer.hasReplacements()) { MethodAdvice advice = new MethodAdvice() { @Override public void advise(MethodInvocation invocation) { String className = (String) invocation.getParameter(0); final Class<?> replacement = componentReplacer.getReplacement(className); if (replacement != null) { invocation.setParameter(0, replacement.getName()); } invocation.proceed(); } }; methodAdviceReceiver.adviseMethod( ComponentInstantiatorSource.class.getMethod("getInstantiator", String.class), advice); } }
@Override public void addLoggingAdvice(Logger logger, MethodAdviceReceiver receiver) { MethodAdvice advice = new LoggingAdvice(logger, exceptionTracker); receiver.adviseAllMethods(advice); } }
@SuppressWarnings("unchecked") public void addTransactionCommitAdvice(MethodAdviceReceiver receiver) { if (receiver.getInterface().getAnnotation(Transactional.class) != null) { Transactional annotation = (Transactional) receiver.getInterface().getAnnotation(Transactional.class); if (isIntercepted(annotation)) { for (Method m : receiver.getInterface().getMethods()) { if (m.getAnnotation(NotTransactional.class) == null) { receiver.adviseMethod(m, advice); } } } } else { for (Method m : receiver.getInterface().getMethods()) { if (m.getAnnotation(Transactional.class) != null) { Transactional annotation = m.getAnnotation(Transactional.class); if (isIntercepted(annotation)) { receiver.adviseMethod(m, advice); } } } } }
private static void doAdvise(MethodAdviceReceiver receiver, final String id) { receiver.adviseAllMethods(new MethodAdvice() { @Override public void advise(MethodInvocation invocation) { invocation.proceed(); Object result = invocation.getReturnValue(); invocation.setReturnValue(String.format("%s[%s]", id, result)); } }); }
@Match("ScriptingServices") public static void adviseSafe(final Logger log, final ApplicationStateManager appStateManager, final Indexer indexer, final PortalSecurityManager securityManager, MethodAdviceReceiver receiver) { MethodAdvice advice = new MethodAdvice() { @Override public void advise(MethodInvocation invocation) { invocation.proceed(); Storage storage = (Storage) invocation.getReturnValue(); invocation.setReturnValue(new SecureStorage(storage, indexer, securityManager, appStateManager.getIfExists(JsonSessionState.class))); } }; try { Method method = receiver.getInterface().getMethod("getStorage", new Class[]{}); receiver.adviseMethod(method, advice); } catch (Exception e) { log.error("Failed to advise: {}", e.getMessage()); } }
private static void doAdvise(MethodAdviceReceiver receiver, final String id) { receiver.adviseAllMethods(new MethodAdvice() { @Override public void advise(MethodInvocation invocation) { invocation.proceed(); Object result = invocation.getReturnValue(); invocation.setReturnValue(String.format("%s[%s]", id, result)); } }); }
Method method = receiver.getInterface().getMethod("search", new Class[]{SearchRequest.class, OutputStream.class}); receiver.adviseMethod(method, advice); } catch (Exception e) { log.error("Failed to advise: {}", e.getMessage());
@Advise(serviceInterface = NonAnnotatedServiceInterface.class) public static void adviseNonAnnotatedServiceInterface(MethodAdviceReceiver methodAdviceReceiver) { methodAdviceReceiver.adviseAllMethods(new TestAdvice()); }