geronimo-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jeremy Boynes" <>
Subject RE: InvocationResult
Date Sun, 24 Aug 2003 17:50:38 GMT
> From: David Blevins [] 

> You only need to catch a specific exception type when you 
> need to do something unique.  The above block could be written as:
> try {
>     InvocationResult r = getNext().invoke(invocation);
>     pool.release(ctx);
>     return r;
> } catch (Throwable t) {
>     pool.remove(ctx);
>     throw t;
> } finally {
>     EJBInvocationUtil.putEnterpriseContext(invocation, null);
> }

Couple of things :-) :
* this changes the order of release/remove and putEnterpriseContext
  not important in this segment, but could be elsewhere - aw, who cares

* this would require changing invoke from throwing Exception to
  this might be a good idea anyway

* you also need to catch ApplicationException so it releases rather than
  unless perhaps we return an InvocationResult for all 'normal'
  (so it contains the return value or a checked Exception from the user
  and then throw any system exception from user-land or any exception
  by the container

Hmmm - thinking about it, that last bit seems to make more sense. It
mirrors the distinction between 'normal' completion and a system
exceptions as defined for EJBs; it makes the code for the interceptors
simpler; it allows us to add meta-values to any normal completion and
although we can't add them to system exceptions I don't think that's a
big downside.

So the CallbackInterceptor would then be

  try {
    Object result = callbackMethod.invoke(instance, callbackArgs);
    return new SimpleInvocationResult(result);
  } catch (InvocationTargetException e) {
    Throwable cause = e.getCause();
    if (cause instanceof Exception && !(cause instanceof
RuntimeException)) {
      return new SimpleInvocationResult((Exception)cause));
    } else {
      throw cause;

and the code David had above would work nicely.

Any objections?


View raw message