users@jersey.java.net

Re: [Jersey] restart a resource

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Mon, 06 Oct 2008 10:42:10 +0200

On Oct 3, 2008, at 2:23 PM, Guilhem wrote:

> hi,
>
> i follow the tutorial i 've found at http://blogs.sun.com/sandoz/entry/javarebel_and_jersey_take_2
> this works well, but I don't see how to use this with tomcat instead
> of a lightWebContainer.
>

You can extend the ServletContainer to register a container notifier.
You need to add an instance of ContainerNotifier to to the resource
config properties (ResourceConfig.PROPERTY_CONTAINER_NOTIFIER).

Override the configure methods to do something like this:

       protected void configure(final ServletConfig sc, ResourceConfig
rc, WebApplication wa) {
           super.configure(sc, rc, wa);

           ContainerNotifier cn = ....
            
rc.getProperties().put(esourceConfig.PROPERTY_CONTAINER_NOTIFIER, cn);
       }


> more, the resource are reloaded only when the classes are changed.
>
> For my application I want to make a JSF interface with a button
> "reload" which restart all the resources (i had prefer only selected
> resource but it seems to be unpossible).
>

Yes, currently it is not possible reload a single resource. Do you
want to log an issue?

It sounds like you want to have a another resource that triggers a
reload.

You could have a singleton resource instance you add to the singletons
of ResourceConfig at configuration time that has the instance of the
ContainerNotifier, then when a POST method is sent to that resource it
can perform a reload.

       protected void configure(final ServletConfig sc, ResourceConfig
rc, WebApplication wa) {
           super.configure(sc, rc, wa);

           ReloadResource rr = new ReloadResource(cn);
           rc.getSingletons().add(rr);
            
rc.getProperties().put(esourceConfig.PROPERTY_CONTAINER_NOTIFIER, rr);
       }

       ....

       @Path("reload")
       public class ReloadResource implements ContainerNotifier {
           List<ContainerListener> cls;
           ...

           @POST void reload() {
                for (ContainerListener cl : cls) cl.onReload();
            }
       }


Alternatively you could create an injectable provider to inject the
registered container notifier.


> is there any tutorial which help me to do this?
>

Unfortunately not :-(

Paul.


> Guilhem Legal
>
>
> Paul Sandoz a écrit :
>>
>> On Sep 24, 2008, at 4:42 PM, Guilhem wrote:
>>
>>> hi,
>>>
>>> I would know if its possible to dynamically restart a resource
>>> without having to undeploy/deploy or restart the container?
>>>
>>
>> It is currently only possible to reload all resources. What happens
>> is a new web application is created, configured and initiated.
>>
>> See the JavaDoc of the class:
>>
>> com.sun.jersey.spi.container.ContainerNotifier
>>
>> to register a notifier that may reload the container.
>>
>> I have used this in conjunction with JavaRebel. When JavaRebel
>> detects changes to class files i have a hook in that to dynamically
>> reload things using a ContainerNotifier without having to undeploy/
>> deploy the web application.
>>
>> Does that work for you?
>>
>> 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
>