users@ejb-spec.java.net

[ejb-spec users] Re: [jsr345-experts] [interceptors] _at_PostActivate, etc interceptor signature?

From: David Blevins <david.blevins_at_gmail.com>
Date: Wed, 9 Jan 2013 10:08:22 -0800

Posted this yesterday, but not sure if it came through:

This is something I've been meaning to bring up. Currently the rules are interceptor signatures for callbacks are not allowed to return Object or throw Exception. Blogged about it here: http://blog.dblevins.com/2010/09/ejbnext-interceptor-improvements-method.html

We chose that altered method signature because it effectively matched the method signature of the callback itself, but it has some terrible consequences. The worst is that InvocationContext.proceed() method signature is always the same:

  public Object proceed() throws Exception

When the Interceptor isn't allowed to have the same method signature it creates awkward and unfortunately unavoidable boiler plate:

   @PostConstruct
   @PreDestroy
   @PrePassivate
   @PostActivate
   @AroundTimeout
   public void callback(InvocationContext context) {
       try {
           intercept(context);
       } catch (Exception e) {
           if (e instanceof RuntimeException) {
               throw (RuntimeException) e;
           } else{
               throw new RuntimeException(e);
           }
       }
   }


We should update the spec rules so that interceptor method signatures for callbacks are allowed to be the same and let the container handle the possible undeclared exception issues rather than force that upon the application code in every single callback interceptor they create.


-David

On Jan 8, 2013, at 1:45 PM, Marina Vatkina <marina.vatkina_at_oracle.com> wrote:

> Good question. Looks like when Interceptors spec was created from the EJB spec, the PrePassivate/PostActivate callbacks were left in the EJB spec, while the rest was moved out.
>
> We have (obviously) two choices:
>
> 1) add the method signatures (back) to the EJB spec section "7.5 Interceptors for LifeCycle Event Callbacks"
> 2) change the Interceptors spec to distinguish between the LC interceptors in general and the ones that are supported (i.e. PostConstruct/PreDestroy).
>
> WDYT?
>
> thanks,
> -marina
>
> On 1/8/13 6:36 AM, Mark Struberg wrote:
>> Hi folks!
>>
>> The method signatures for @AroundInvoke and @PostConstruct _interceptors_ (not the postconstruct lifecycle methods, but the interceptors for them!) are well defined in the interceptors spec.
>>
>>
>>
>> But what about the method signatures for an interceptor for @PostActivate and the others which are defined in InterceptionType [1]?
>> I didn't find anything about them in the interceptors spec. Where can I find this info?
>>
>>
>> txs and LieGrue,
>> strub
>>
>> [1] http://docs.oracle.com/javaee/6/api/javax/enterprise/inject/spi/InterceptionType.html
>>
>