SPRING_ Surround Notification

Source: Internet
Author: User
Tags closure throwable

Diligence neglect, journeys by chance ruin in the following.

Create a surround notification

  Surround notification is the most powerful type of notification that allows you to write logic that wraps the target method that is being notified, and it is like writing both a pre-notification and a post-notification in a notification method.

Spring uses @around annotations to declare surround notifications.

 PackageChapter4.practice1;ImportOrg.aspectj.lang.ProceedingJoinPoint;Importorg.aspectj.lang.annotation.AfterReturning;Importorg.aspectj.lang.annotation.AfterThrowing;ImportOrg.aspectj.lang.annotation.Around;ImportOrg.aspectj.lang.annotation.Aspect;ImportOrg.aspectj.lang.annotation.Before;ImportOrg.aspectj.lang.annotation.Pointcut;/*** POJO * Use @aspect to annotate the POJO is also a facet*/@Aspect Public classAudience {/*** Use @pointcut to set pointcut expressions*/@Pointcut ("Execution (* * chapter4.practice1.Performance.perform (..))")     Public voidperformance () {} @Around ("Performance ()")     Public voidwatchperformance (proceedingjoinpoint JP) {Try{System.out.println ("Siliencing Cell Phones ..."); System.out.println ("Taking seats ...");
The target method executes before jp.proceed ();
After the target method executes System.out.println ("Clap clap ..."); } Catch(Throwable e) {System.out.println ("Demanding a refund ..."); } }}

Proceedingjoinpoint's Proceed () method

/******************************************************************************* * Copyright (c) 2005 Contributors . * All rights reserved. * This program and the accompanying materials is made available * under the terms of the Eclipse public License v1.0 * WH Ich accompanies this distribution and was available at *http://eclipse.org/legal/epl-v10.html* * Contributors: * Initial implementation Alexandre Vasseur ******************************************* ************************************/ PackageOrg.aspectj.lang;Importorg.aspectj.runtime.internal.AroundClosure;/*** Proceedingjoinpoint exposes the proceed (..) method in order to support around advice in @AJ aspects * *@author<a href= "Mailto:alex at Gnilux DOT com" >alexandre vasseur</a>*/ Public InterfaceProceedingjoinpointextendsJoinpoint {/*** The joinpoint needs to know on its closure so, proceed can delegate to Closure.run () * <p/> * This internal method should not being called directly, and won ' t is visible to the end-user when * packed in a jar (s Ynthetic method) * *@paramArc*/    voidset$aroundclosure (aroundclosure arc); /*** Proceed with the next advice or target method invocation * *@return     * @throwsThrowable*/     PublicObject Proceed ()throwsThrowable; /**     * Proceed with the next advice or target method invocation * <p/> * <p>unlike code style, Proceed (..)  In annotation style places different requirements on the * parameters passed to it. The proceed (..) call takes, in this order: * <ul> * <li> If ' This () ' is used in the pointcut for bind     ING, it must is passed first in proceed (..).  * <li> If ' target () ' is used in the pointcut for binding, it must is passed next in proceed (..)-* It'll be     The first argument to proceed (..) if this () is not a used for binding. * <li> Finally Come all the arguments expected on the join point, in the order they is supplied * at the join Point.  Effectively the advice signature is ignored-it doesn ' t matter * if a subset of arguments were bound or the ordering was changed in the advice signature, * The proceed (..) calls takes all of them in the right order for the join point      . * </ul> * <p>sinceProceed (..) in the takes an Object array, AspectJ cannot does as much * compile time checking as it can for code Style.      If the rules above aren ' t obeyed * then it'll unfortunately manifest as a runtime error.  * </p> * *@paramargs *@return     * @throwsThrowable*/     PublicObject Proceed (object[] args)throwsThrowable;}

  The proceed () method blocks the call to the method being notified.

  

SPRING_ Surround Notification

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.