A spect O riented P rogramming using Spring Framework Arseni Grigorjev arsenikum[gmail.com]
Me <ul><li>Server side Java (~5y) </li></ul><ul><li>Aqris Software </li></ul><ul><li>Online gambling </li></ul>
Simple service method <ul><li>public   class  SimpleService { </li></ul><ul><li>… </li></ul><ul><li>public  List getCustom...
 
Aspect Oriented Programming <ul><li>A spect  O riented  P rogramming (AOP) enables modularization of cross-cutting concern...
Cross-Cutting Concerns Examples <ul><li>Logging and Tracing </li></ul><ul><li>Transaction Management </li></ul><ul><li>Sec...
System Evolution: Conventional
How AOP Works <ul><li>Write your mainline application logic </li></ul><ul><li>Write aspects to implement cross-cutting con...
System Evolution: AOP Based
Leading AOP Technologies <ul><li>AspectJ </li></ul><ul><ul><li>1995, original AOP technology </li></ul></ul><ul><ul><li>Of...
Leading AOP Technologies (2) <ul><li>Spring AOP </li></ul><ul><ul><li>Uses  dynamic proxies  to add aspects into your appl...
Core AOP Concepts <ul><li>Join Point </li></ul><ul><ul><li>A point of execution of a program such as method call or field ...
Spring AOP Example <ul><li>Business logic: </li></ul>public   class   SimpleService { … public  List getCustomerOrders( lo...
Spring AOP Example (2) <ul><li>Performance tracing aspect: </li></ul>
Spring AOP Example (3) <ul><li>Configure the Aspect as a Bean: </li></ul><beans> <aop:aspectj-autoproxy> <aop:include name...
Advice Types <ul><li>@Around </li></ul><ul><li>@Before </li></ul><ul><li>@After </li></ul><ul><li>@AfterReturning </li></u...
SpringSource Tool Suite AOP Support
SpringSource Tools Suite AOP Support (2)
Useful Links <ul><li>Aspect Oriented Programming with Spring </li></ul><ul><ul><li>http://static.springsource.org/spring/d...
Thank You! <ul><li>Questions? </li></ul>
Upcoming SlideShare
Loading in...5
×

Aspect-Oriented Programming by Arseni Grigorjev

2,115

Published on

AOP with SpringFramework

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,115
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
43
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide
  • -- Разделение ответсвенности ( Tangling – переплетение) -- Scattering – рассеивание, ведёт к дупликации
  • -- Tangling – переплетение -- Scattering – рассеивание, ведёт к дупликации
  • Aspect-Oriented Programming by Arseni Grigorjev

    1. 1. A spect O riented P rogramming using Spring Framework Arseni Grigorjev arsenikum[gmail.com]
    2. 2. Me <ul><li>Server side Java (~5y) </li></ul><ul><li>Aqris Software </li></ul><ul><li>Online gambling </li></ul>
    3. 3. Simple service method <ul><li>public class SimpleService { </li></ul><ul><li>… </li></ul><ul><li>public List getCustomerOrders( long operatorId, long customerId) { </li></ul><ul><li>List result; </li></ul><ul><li>long start = System. currentTimeMillis(); </li></ul><ul><li>if (!hasPermissions(operatorId)) { </li></ul><ul><li>throw new NotAuthorizedException(); </li></ul><ul><li>} </li></ul><ul><li>try { </li></ul><ul><ul><li>ordersCache.getOrders(customerId); </li></ul></ul><ul><ul><li>if (result == null ) { </li></ul></ul><ul><ul><li>logger.info( &quot;going to fetch orders for &quot; + customerId); </li></ul></ul><ul><ul><li>result = customerDao.getOrders(customerId); </li></ul></ul><ul><ul><li>logger.info( &quot;fetched orders for &quot; + customerId + &quot;: &quot; + result); </li></ul></ul><ul><ul><li>ordersCache.putOrders(customerId, result); </li></ul></ul><ul><ul><li>} </li></ul></ul><ul><li>} catch (CusstomerNotFoundException e) { </li></ul><ul><li>logger.error( &quot;Customer &quot; + customerId + &quot; not found&quot; , e); </li></ul><ul><li>result = null ; </li></ul><ul><li>} </li></ul><ul><li>long end = System. currentTimeMillis(); </li></ul><ul><li>logger.debug( &quot;method took &quot; + (end - start) + &quot; ms&quot; ); </li></ul><ul><li>return result; </li></ul><ul><li>} </li></ul><ul><li>… </li></ul><ul><li>} </li></ul>+ authorization + error handling + performance monitoring + caching + logging
    4. 5. Aspect Oriented Programming <ul><li>A spect O riented P rogramming (AOP) enables modularization of cross-cutting concerns </li></ul><ul><ul><li>Separation of Concerns principle – no code tangling </li></ul></ul><ul><ul><li>1:1 principle – no code scattering </li></ul></ul>
    5. 6. Cross-Cutting Concerns Examples <ul><li>Logging and Tracing </li></ul><ul><li>Transaction Management </li></ul><ul><li>Security </li></ul><ul><li>Caching </li></ul><ul><li>Error Handling </li></ul><ul><li>Performance Monitoring </li></ul><ul><li>Custom Business Rules </li></ul>
    6. 7. System Evolution: Conventional
    7. 8. How AOP Works <ul><li>Write your mainline application logic </li></ul><ul><li>Write aspects to implement cross-cutting concerns </li></ul><ul><li>Bind it all together </li></ul>
    8. 9. System Evolution: AOP Based
    9. 10. Leading AOP Technologies <ul><li>AspectJ </li></ul><ul><ul><li>1995, original AOP technology </li></ul></ul><ul><ul><li>Offers a full Aspect Oriented Programming language </li></ul></ul><ul><ul><li>Modifies byte code to add aspects into your application! </li></ul></ul>
    10. 11. Leading AOP Technologies (2) <ul><li>Spring AOP </li></ul><ul><ul><li>Uses dynamic proxies to add aspects into your application </li></ul></ul><ul><ul><li>Only spring beans can be advised </li></ul></ul><ul><ul><li>Uses some of AspectJ expression syntax </li></ul></ul>
    11. 12. Core AOP Concepts <ul><li>Join Point </li></ul><ul><ul><li>A point of execution of a program such as method call or field assignment </li></ul></ul><ul><li>Pointcut </li></ul><ul><ul><li>An expression that selects one or more Join Points </li></ul></ul><ul><li>Advice </li></ul><ul><ul><li>Code to be executed at a Join Point that has been selected by a Pointcut </li></ul></ul><ul><li>Aspect </li></ul><ul><ul><li>A module that encapsulates Pointcuts and Advice </li></ul></ul>
    12. 13. Spring AOP Example <ul><li>Business logic: </li></ul>public class SimpleService { … public List getCustomerOrders( long operatorId, long customerId) { return customerDao.getOrders(customerId); } … }
    13. 14. Spring AOP Example (2) <ul><li>Performance tracing aspect: </li></ul>
    14. 15. Spring AOP Example (3) <ul><li>Configure the Aspect as a Bean: </li></ul><beans> <aop:aspectj-autoproxy> <aop:include name=“performanceTracer” /> </aop:aspectj-autoproxy> <bean id=“performanceTracer” class=“ com.foo.bar. PerformanceTracer ” /> </beans>
    15. 16. Advice Types <ul><li>@Around </li></ul><ul><li>@Before </li></ul><ul><li>@After </li></ul><ul><li>@AfterReturning </li></ul><ul><li>@AfterThrowing </li></ul>
    16. 17. SpringSource Tool Suite AOP Support
    17. 18. SpringSource Tools Suite AOP Support (2)
    18. 19. Useful Links <ul><li>Aspect Oriented Programming with Spring </li></ul><ul><ul><li>http://static.springsource.org/spring/docs/2.5.x/reference/aop.html </li></ul></ul><ul><ul><li>Lots of examples </li></ul></ul><ul><ul><li>Highlights on AspectJ syntax </li></ul></ul><ul><li>SpringSource Tool Suite: </li></ul><ul><ul><li>http://www.springsource.com/products/sts </li></ul></ul><ul><ul><li>Eclipse IDE with Spring (and Spring AOP) support </li></ul></ul>
    19. 20. Thank You! <ul><li>Questions? </li></ul>
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×