• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Why should the return type of a timeout method interceptor be Object?

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there,

can someone help me with this? Returning an Object from a business method interceptor would make some sense, but since a timeout method always returns void, why?

Thanks,
Y.P.
 
Bartender
Posts: 2450
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Timer does not have any client. So, timeout method does not return any value to the client.
Timer is invoked by the container, but not by the client. It is not necessary for a timer to return any value.
Hope this helps.
 
You Peng
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Himai,

Thanks for the reply. But since it's the container, not the client, who calls the time out callback, I thought the callback should *never* return an object, which then makes "an interceptor for a timeout method returning an object" unreasonable/useless. Am I wrong with "timeout callbacks should never return an object"? Or is the return value of the interceptor meant for something else?

You
 
Himai Minh
Bartender
Posts: 2450
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Timeout method does not return anything. The container calls the timeout method when the scheduler time is up.
The client does not invoke the timeout method. So, it is not necessary for timeout method to return any value.

Interceptors (except those lifecycle callback interceptors, @PostConstruct, @PreDestroy....) can return an Object type.
Typically, an interceptor method is like this:



 
You Peng
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have no problem with these. But my question is: since timeout callbacks don't produce any result by themselves, and their interceptors are called by the container, which probably don't expect any return value from the interceptors anyway, what's the point of declaring such interceptors to return Object? The situation seems pretty much like that with life cycle interceptors, but the life cycle interceptors can only return void. Why?
 
Himai Minh
Bartender
Posts: 2450
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I see what you are talking about now.
@AroundTimeout method returns object. But those @PostConstruct ... lifecycle callback interceptors return void.
Maybe, there is some business logic inside the @AroundTimeout method and we may need the business logic to return some values.

I am not sure the exact reason neither.

 
You Peng
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks anyway!
 
Himai Minh
Bartender
Posts: 2450
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, You Peng,
I found this API spec :http://docs.oracle.com/javaee/6/api/javax/interceptor/AroundTimeout.html
It says the @AroundTimeout method may return the timer.


InvocationContext.getTimer() allows any AroundTimeout method to retrieve the timer object associated with the timeout.

 
You Peng
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Himai, but that's not what the quote was saying. The quote says only the timer object is accessible from within the method annotated with @AroundTimer.
 
Himai Minh
Bartender
Posts: 2450
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the @AroundTimeout
can return the Timer object.
I am not sure about that.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic