users@jersey.java.net

Re: [Jersey] Adding new annotations to Jersey

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Thu, 12 Nov 2009 16:28:33 +0100

On Nov 12, 2009, at 3:47 PM, Casper Bang wrote:

> Interesting topic. I am currently using caching by means of a
> ServletFilter (course-grained) and a custom CacheDecorator
> (fine-grained) down around the DAO layer. It occurred to me that it
> would be really nice and flexible if methods could be annotated
> instead.
> For REST/Jersey purposes, we could see something like this:
>
> @GET
> @Produces("application/rss+xml")
> @Path("feed/")
> @Cache(ttl=60, tti=30, policy=Policy.LRU)
> public Viewable someRssContent{ ... }
>

Yes, that should be really easy to do with a ResourceFilter that looks
for the @Cache annotation and registers a ContainerResponseFilter that
uses ehcache.


> Viewable and binary resources would then be trapped by Jersey
> (implementing something like EhCache's
> SimpleCachingHeadersPageCachingFilter). That would be a super easy way
> to use caching in Jersey. However I guess it doesn't have to end
> there,
> more fine-grained methods could just as easily make use of @Cache
> except
> it would not result in HTTP cache headers etc.
>
> And why even stop there, one could even imagine using @Cache around
> vanilla Java as a shorthand for the very common lazy-initiation idiom:
>
> private static Foo foo = null;
>
> public Foo getFoo(){
> if(foo==null){
> synchronized(Foo.class){
> if(foo == null){
> foo = someExpensiveOperation();
> }
> }
> }
> }
>

> Some newer languages supports this natively as modifier (i.e. Fan).

Yes, Scala has the "lazy" operator.

Paul.

> Anyway, just an idea I felt like writing down, it feels like there's
> something here even if I'm not sure where it fits between Coin,
> Lombok,
> EhCache and Jersey.
>
> /Casper
>
>
> Paul Sandoz wrote:
>> On Nov 11, 2009, at 8:46 AM, Cemo Koc wrote:
>>
>>>
>>> Hi all,
>>>
>>> What is best way to add new annotations to Jersey. Is there any
>>> mechanism
>>> for this?
>>>
>>
>> It depends. What do you want to do?
>>
>> For example, runtime annotations are accessible and can be
>> processed by:
>>
>> 1) Resource filters;
>>
>> 2) Message body readers and writers; and
>>
>> 3) String reader providers.
>>
>> 4) Injectable providers.
>>
>> Paul.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>