• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

multiple AroundInvoke

 
Ranch Hand
Posts: 757
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What if there are two or many @AroundInvoke methods in single interceptor class (I mean the same class)? Which will be the first one that invoked?
 
Ranch Hand
Posts: 1277
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

It’s important to realize that an interceptor must always have only one method that is designated as the around invoke (AroundInvoke) method.
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'd say multiple AroundInvoke methods in the same class are not legal. But you may have seperate AroundInvoke methods on each level of the interceptor's class hierarchie.

That's what I found in the Java EE Specification 5.0:

12.3 Business Method Interceptors
"... However, only one AroundInvoke method may be present on a given class."

12.3.1 Multiple Business Method Interceptor Methods
"... If an interceptor class itself has superclasses, the interceptor methods defined by the interceptor class’s superclasses are invoked before the interceptor method defined by the interceptor class, most general superclass first."
 
Treimin Clark
Ranch Hand
Posts: 757
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks to Niranjan, and Dirk.

 
Niranjan Deshpande
Ranch Hand
Posts: 1277
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Dirk,

Thanks for adding the relevant information for 12.3.1.

Section 12.3.1 is talking of methods in the interceptor class heirarchy.

How would be the invocation if -
1. the invoked method is 'overloaded'
2. the invoced methos is 'overridden'.

in the heirarchy.
 
Treimin Clark
Ranch Hand
Posts: 757
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Niranjan Deshpande wrote:
How would be the invocation if -
1. the invoked method is 'overloaded'
2. the invoced methos is 'overridden'.



I don't understand that how it is possible to overload a method, which is annotated with @AroundInvoke annotation. Since the signature of the @ArounInvoke method must be consist with one InvocationContext parameter, how can it be overloaded?
 
Niranjan Deshpande
Ranch Hand
Posts: 1277
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good Catch!

so we have two scenarios, assuming interceptor class2 extends interceptor class1 :

1. class 1 has @AroundInvoke method1, class 2 has @AroundInvoke method2- here method1 will be executed and then methd2. Correct?

1. class 1 has @AroundInvoke method1, class 2 has @AroundInvoke method1- here method1 in class2 overrides the one in class1. What will happen here?
 
Treimin Clark
Ranch Hand
Posts: 757
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As I know, both scenarios above will provide the same result. Am I correct?
 
Dirk Dühr
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess Treimin hits the mark:
The expected around-invoke method signature including return type and throws clause is fixed.

That means, any method overloading a specified around-invoke method (e.g. by specifiying different parameter types in the method signature) shoud be ignored by the EJB container, at least.

While overloaded around-invoke methods seem to be legal concering the specs, the ejb-jar_3_0.xsd scheme comments they are not:

ejb-jar_3_0.xsd:

...
<xsd:complexType name="around-invokeType">
<xsd:annotation>
<xsd:documentation>

The around-invoke type specifies a method on a
class to be called during the around invoke portion of an
ejb invocation. Note that each class may have only one
around invoke method and that the method may not be
overloaded.
...


So the EJB container might complain about overloaded around-invoke methods.

But overriding is funny enough. I just wonder about this scenario:



Now, I inject MySpecialInterceptor into an arbitrary busines method. Which around-invoke method body is executed?

Due to "base class first" + "override overrides" ;-) ... I'd assume:

So I actually defined two around-invoke methods in one interceptor class?!
 
Dirk Dühr
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Niranjan Deshpande wrote:
....
so we have two scenarios, assuming interceptor class2 extends interceptor class1 :

1. class 1 has @AroundInvoke method1, class 2 has @AroundInvoke method2- here method1 will be executed and then methd2. Correct?


I think so, too. Base class first.

Niranjan Deshpande wrote:
...
1. class 1 has @AroundInvoke method1, class 2 has @AroundInvoke method1- here method1 in class2 overrides the one in class1. What will happen here?


Just realized I replicated your question with my preceeding post. Sorry, did not read your second scenario carefully enough.
I think in this case the invocation sequence is: class2.method1 since the invocation is triggered by the base class override, then class2.method2.
 
Niranjan Deshpande
Ranch Hand
Posts: 1277
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Dirk,

Thanks for the xsd

Did you actually try running the interceptors? What was the result?

I think you did not define two methods in the same class, but you inherited them!

 
Dirk Dühr
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Niranjan,

Did not find the time yet. I'll give it a try the next days on Glassfish and JBoss.
I'll post my results soon.
reply
    Bookmark Topic Watch Topic
  • New Topic