• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

static and dynamic pointcut operations?  RSS feed

 
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are pointcut operations in Spring Framework? How are static and dynamic pointcut operations used and what is the need of creation of these operations?
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Naina Si:
What are pointcut operations in Spring Framework? How are static and dynamic pointcut operations used and what is the need of creation of these operations?


Pointcuts are a fundamental concept of aspect-oriented programming (AOP). In short, a pointcut is a place in your code where an aspect can be applied. E.g. a method can be a pointcut if the AOP framework in use allows you to specify that a given aspect should be applied when someone invokes that method.

For more information about AOP, take a look at these articles:
Introduction to Aspect-Oriented Programming
Improve modularity with aspect-oriented programming
I want my AOP!
 
Lasse Koskela
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, and in case those articles don't shed enough light on what's the difference between static and dynamic pointcuts, ...

With a static pointcut, the AOP framework doesn't need to consider the execution context since the pointcut is specified in terms of static structure (e.g. "all methods that start with the letters t-e-s-t").

With a dynamic pointcut, the AOP framework determines at runtime whether an aspect should be applied based on the execution context (e.g. "all methods that start with the letters t-e-s-t and one of the method call arguments is null").

I'm not too pleased with that description but I hope it's at least of some help to you.
 
author
Posts: 396
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Lasse Koskela:

With a static pointcut, the AOP framework doesn't need to consider the execution context since the pointcut is specified in terms of static structure (e.g. "all methods that start with the letters t-e-s-t").

With a dynamic pointcut, the AOP framework determines at runtime whether an aspect should be applied based on the execution context (e.g. "all methods that start with the letters t-e-s-t and one of the method call arguments is null").



That's not too bad of a description...

The key thing to take away here is that Spring AOP is able to apply aspects to static pointcuts at startup time, because it knows everything it needs to know to be able to do the weaving. This means that at runtime AOP has no significant performance hit for static pointcuts.

But dynamic pointcuts can't be applied until runtime, because the info needed isn't available until runtime. So, dynamic pointcuts have a small performance implication.
 
Naina Si
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But where do we specify that its a 'static' or 'dynamic' point cut?
Its all so confusing to me, probably i should read more on this topic.
 
Lasse Koskela
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Naina Si:
But where do we specify that its a 'static' or 'dynamic' point cut?


The static/dynamic is revealed to Spring by the way your pointcut class implements the org.springframework.aop.Pointcut interface (namely, what kind of a MethodMatcher instance it returns when Spring asks for one).

In practice, you typically don't implement the interface yourself but instead extend one of the built-in base classes for pointcuts, such as org.springframework.aop.support.DynamicMethodMatcherPointcut or org.springframework.aop.support.StaticMethodMatcherPointcut.
 
Ranch Hand
Posts: 1209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Naina Si:
But where do we specify that its a 'static' or 'dynamic' point cut?
Its all so confusing to me, probably i should read more on this topic.



Yes you will have to refer to spring aop docs

Essentially you need to implement Spring's Pointcut interface that in turn determines the Class and the methods in those classes that need to be advised. For dynamic pointcuts that rely on method arguments,
isRuntime() needs to return true. Then Spring will call method-3 and you can decide based on arguments whether you need to apply the advice or not.



Also refer to section 5.2.3.2.1 on Control flow pointcuts.
 
Ranch Hand
Posts: 451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To clarify the AOP nomenclature a bit:

"Joinpoint" is simply a point in the execution of a program.

"Advise" is action that is a taken at a particular joinpoint.

"Pointcut" is a set of joinpoints that defines where a particular advice is applied.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Static point cut:

--> The proxy for target class will be created at runtime.
--> But here the proxy will be created with the methods those supplied by taking the help of static pointcut class.
--> Due to above one performance will be optimized

Dynamic point cut :

--> The proxy for target class will be created at runtime.
--> But here the proxy will be created for all  the methods of the target class.
--> Here when we want to even consider arguments values also for conditional checking then we need to go for dynamic pointcut.
 
It will give me the powers of the gods. Not bad for a tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!